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.

General Questions /

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

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

Search results returning javascript file in assets


Go to End


5 Posts   2686 Views

Avatar
HilaryB

Community Member, 11 Posts

13 February 2010 at 12:29am

Edited: 13/02/2010 12:55am

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

Community Member, 541 Posts

13 February 2010 at 5:26am

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

Community Member, 89 Posts

15 February 2010 at 1:47am

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

Community Member, 11 Posts

15 February 2010 at 11:06pm

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

Community Member, 39 Posts

10 August 2010 at 8:17am

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