Jump to:

22993 Posts in 11829 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Search results returning javascript file in assets

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1682 Views
  • HilaryB
    Avatar
    Community Member
    11 Posts

    Search results returning javascript file in assets Link to this post

    If you enter the search term 'cms' into the search form on our site it returns cmsmain.js in the assets folder as a result. My understanding of the search is that it only searches the database sitetree table, so I am very surprised to see an item from the assets folder there.

    The site uses Silverstripe 2.3.3

    How do I stop these javascript files showing (which Silverstripe puts in the assets folder)?

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: Search results returning javascript file in assets Link to this post

    I don't get this in the 2.4 beta version (the only site I have an inline search one, so all I can test).

    Have you tried updating to the latest 2.3.x release?

    Mo

  • purplespider
    Avatar
    Community Member
    80 Posts

    Re: Search results returning javascript file in assets Link to this post

    I have this problem too, and I'm using 2.4.

    It is displaying other files from the assets folder too, .flv .html etc. It appears to already ignore images though.

    How can we control what the search engine looks in?

  • HilaryB
    Avatar
    Community Member
    11 Posts

    Re: Search results returning javascript file in assets Link to this post

    I've been doing some more digging since posting this request. I found that there is a static set in /sapphire/search/SearchForm.php

    protected $classesToSearch = array("SiteTree", "File"); So it looks like it searches the Files table as well as the SiteTree.

    In the same file there is also the following method:

    /**
        * Set the classes to search.
        * Currently you can only choose from "SiteTree" and "File", but a future version might improve this.
        */
       function classesToSearch(array $classes)

    So it looks like having created a new SearchForm object you could call this method in your search method (probably in Page.php) and remove Files - by just passing in SiteTree..

    In this method there are also arrays set up of which columns to search. However there doesn't seem to be a way to change this other than hacking it.

    I cannot find any useful documentation on how the search works, the tutorial is a start, but more is needed.

    Searching the File table is not very useful as it only holds the file names/paths. What would be useful is to be able to search the assets if they are something like pdf files.

    I have come to the conclusion that SilverStripe's search is not one of it's strengths and I would really like to see it improved considerably.

  • Yellow7 Jon
    Avatar
    Community Member
    39 Posts

    Re: Search results returning javascript file in assets Link to this post

    Was searching on how to stop the searching of the assets, seems you can just add this in your Page.php -> function results()

    $form->classesToSearch(array('SiteTree'));

    before

       $data = array(
           'Results' => $form->getResults(),
           'Query' => $form->getSearchQuery(),
           'Title' => 'Search Results'
           );

    just for future reference for others

    1682 Views
Page: 1
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.