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.

General Questions

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

Search results returning javascript file in assets


Reply

5 Posts   1787 Views

Avatar
HilaryB

13 February 2010 at 12:29am (Last edited: 13 February 2010 12:55am), Community Member, 11 Posts

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)?

Avatar
Mo

13 February 2010 at 5:26am Community Member, 509 Posts

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

Avatar
purplespider

15 February 2010 at 1:47am Community Member, 82 Posts

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?

Avatar
HilaryB

15 February 2010 at 11:06pm Community Member, 11 Posts

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.

Avatar
Yellow7 Jon

10 August 2010 at 8:17am Community Member, 39 Posts

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