Jump to:

10845 Posts in 2513 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » CustomSearchForm snippet

Discuss all other Modules here.

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

Page: 1 2 3 4 5 6
Go to End
Author Topic: 9152 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: CustomSearchForm snippet Link to this post

    Try:

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

    Or..

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

  • Shawn Parr
    Avatar
    Community Member
    60 Posts

    Re: CustomSearchForm snippet Link to this post

    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!

  • wmk
    Avatar
    Community Member
    44 Posts

    Re: CustomSearchForm snippet Link to this post

    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.

  • Xurk
    Avatar
    Community Member
    50 Posts

    Re: CustomSearchForm snippet Link to this post

    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

  • Xurk
    Avatar
    Community Member
    50 Posts

    Re: CustomSearchForm snippet Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: CustomSearchForm snippet Link to this post

    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.

  • Xurk
    Avatar
    Community Member
    50 Posts

    Re: CustomSearchForm snippet Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: CustomSearchForm snippet Link to this post

    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.

    9152 Views
Page: 1 2 3 4 5 6
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.