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

Hide assets/Forms from Site Search Results


Go to End


4 Posts   2104 Views

Avatar
goodness

Community Member, 38 Posts

4 February 2014 at 5:56am

Is there a simple way to tell Silverstripe to not include the Forms folder under Assets in local site search results?
I am using version 3.0.5

Thanks!

Avatar
goodness

Community Member, 38 Posts

5 February 2014 at 3:17am

I'm surprised no one has encountered this before. Perhaps I didn't explain what I'm trying to accomplish very clearly.

I have PDF files with the path: www.mydomainname.com/assets/Forms/FileName.pdf

What I want to do is stop the internal site search from showing anything inside the Forms folder in the search results.

Is anyone able (and willing) to give me specific instructions on how to achieve this?

Thanks!

Avatar
Matt

Community Member, 86 Posts

5 February 2014 at 11:15am

Edited: 05/02/2014 11:18am

Hey goodness,

There is a 'ShowInSearch' boolean field on the File class already, but it's not surfaced in the Files section of the CMS at the moment. You have two options:

Option 1: Follow either of the instructions here to disable searching all File objects (or, using the SQL, you could disable searching for only a sub-set of files (by finding the 'ID' of the Forms folder as you mention below, and amending the SQL query).

Option 2: Add a 'FileExtension' class which surfaces that checkbox, so that for individual files, you can use the CMS to change whether or not you want that file shown in search. That extension class would look something like this (untested, use at your risk!): http://sspaste.com/paste/show/52f163516d33b.

Avatar
Matt

Community Member, 86 Posts

5 February 2014 at 11:18am

For what it's worth, the code that actually performs the search is specific to the database engine in use. I presume you're using MySQL, so the code that searches by default is here: https://github.com/silverstripe/silverstripe-framework/blob/3.0/model/MySQLDatabase.php#L842