Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

CustomSearchForm snippet


Go to End


46 Posts   17730 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 July 2009 at 1:53am

Try:

return $p->AbsoluteLink('article/'.$this->ID);

Or..

return Director::absoluteURL($p->Link('article/'.$this->ID));

Avatar
Shawn Parr

Community Member, 60 Posts

8 July 2009 at 2:26am

Edited: 08/07/2009 2:44am

Hmm, neither of those seem to work.

return $p->AbsoluteLink('article/'.$this->ID); gives a link to just the page, but isn't concatenating the article/ID part.

Director::absoluteURL($p->Link('article/'.$this->ID)); seems to give the correct URL as an output but:

Both still have an errant slash is front of the url. i.e. /http://server/shawn/news/search-test/article/22.

I think there may be a bug in here somewhere, as I also just noticed that pages found in the search also seem to have extra slashes in them. I'm going to comb through my code in Page.php and my dataobject to see if I've accidentally put it in there somewhere.

EDIT: the 'bad' links are only in the read more links. The 'Title' links appear to be fine.

Turns out I did something stupid in my template file for the results while experimenting. Changing it back to how it was fixed it. So no bugs, and my original method actually worked!

Avatar
wmk

Community Member, 87 Posts

28 January 2010 at 1:21am

Uncle Cheese, you're the man!

Thank you a lot for this great solution! It works great on SS 2.3.4

Anyone made tests with translatable enabled?

I made a little change to the Class, as i have used advanced filter for modelAdmin like:

    static $searchable_fields = array(
        'Title' => array('title'=>'Name', 'filter' => 'PartialMatchFilter'),
        'Categories.Title'=> array(
            'title' => 'Category',
            'filter' => 'PartialMatchFilter'),
        'otherField',
        'yetAnotherField'
    );

Therefore i changed about line 80:

foreach($arr['Fields'] as $key => $val) {
    if ($key && !is_int($key)) {
        if (!strpos($key,'.') && array_key_exists('filter',$val) && $val['filter'] == 'PartialMatchFilter') {
            $fields[] = $key;
        }
    }
}
$match[$class] = "MATCH (".implode(',',$fields).") AGAINST ('$keywords' $boolean)";
$relevanceKeywords = str_replace(array('*','+','-'),'',$keywords);
$relevance[$class] = "MATCH (".implode(',',$fields).") AGAINST ('$relevanceKeywords')";

Hope this helps someone.

Avatar
Xurk

Community Member, 50 Posts

15 June 2010 at 8:39pm

First of all, this is a great thread UncleCheese :) Thanks for the inspiration, it all seems so logical, especially after spending a day or two looking for a way to add DataObjects to the standard search functionality but not really getting anywhere.

However, I haven't been able to get this customization of the SearchForm to function on my website. I've followed the instructions in the opening post meticulously and have double-checked everything to see if I hadn't made a slight mistake somewhere. But everything looks good. The "/dev/build/?flush=1" also indicates that the full-text indici have been added to the database tables of the DataObjects I want to add to the site search.

Is it a possibility that running SS 2.4 has anything to do with this? It doesn't seem likely and I'm not receiving errors, but if anyone else running 2.4 could confirm that this not working should be traced back to my code or to SS 2.4, I'd be grateful.

Could it also be possible that the DataObjects aren't included due to them not having their own physical PHP files, but existing within another PHP file (I have a MyObjectHolder.php file which extends the Page class with a MyObjectHolder class, and the MyObject (extending DataObject) is placed beneath that class)?

Anyone willing to help me out, thanks a lot in advance :)

Avatar
Xurk

Community Member, 50 Posts

17 June 2010 at 7:09pm

Edited: 17/06/2010 7:10pm

Sorry for the bump, but I just received an e-mail from the client asking why the parts of the website which are DataObjects aren't showing up in the search results (and the client this done by the weekend)... busted ;-)

Anyone have any ideas or suggestions?

Avatar
Willr

Forum Moderator, 5523 Posts

17 June 2010 at 9:16pm

I recommend looking at the sphinx search module. It requires a bit of an effort to setup (esp on shared machines) but the high quality of search (incl dataobjects) makes it very very useful http://silverstripe.org/sphinx-module.

Avatar
Xurk

Community Member, 50 Posts

17 June 2010 at 9:19pm

Reading the features list, Sphinx does seem like it is worth investing some time into, so I think I'll give it a shot. Thanks for the tip, Willr :)

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 June 2010 at 2:01am

Our firm deals with this problem on a daily basis. We have a lot of angry clients, and can certainly relate to your frustration. I'm shocked that this isn't a higher priority issue for SS NZ.

The feedback I have received from them has pointed me to the "sphinx" module (should show up in the docs).. It's a Zend-based binary search that updates its index with a cron script as I remember. I got pretty far with it before moving on.

At this point, we use Google search for all of our clients. I've written a GoogleSearch module that is build on the GoogleSiteMap module to place custom classes (e.g. DataObject subclasses) in your site map. From there, the search is extremely easy to implement.. And for $100 a year, you can get rid of the Google branding and style it any way you like. You can also manually flush your site's index at any time.

See an example here: http://www.yestermorrow.org

It's not ideal, but it got us to where we needed to be to get this client to stop complaining that their courses (dataobjects in ModelAdmin) weren't showing up in search. Since that's their core offering, it was kind of a big deal. Not to mention, you won't find anyone with a better search algorithm than Google, so overall, it's a higher quality product. You just have to be willing to work within certain presentational limitations.