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

Question about Searchable Field


Go to End


7 Posts   1726 Views

Avatar
Webdoc

Community Member, 349 Posts

12 August 2015 at 5:23pm

I have 'Productcode' => 'Text' as a text field in my cms and template it works well just i need to be searchable

have this in Swipestripe code:
private static $searchable_fields = array(
'Title' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Name'
)
);
do i need to add some extracode to swipestripe product.php to make the product code searchable

Avatar
muskie9

Community Member, 24 Posts

12 August 2015 at 5:39pm

Edited: 12/08/2015 5:40pm

Webdoc I think it would be something along these lines (in a DataExtension if it's for something in the module):

private static $searchable_fields = array(
    'Productcode' => array(
        'field' => 'TextField',
        'filter' => 'PartialMatchFilter',
        'title' => 'Product Code'
    )
);

Avatar
Webdoc

Community Member, 349 Posts

13 August 2015 at 6:17am

As i understand from the google search its also needed to add some code to Page.php to make it work. Where you have the Page-type and the field also
I have the field in Swipestripe Product.php

Avatar
Pyromanik

Community Member, 419 Posts

13 August 2015 at 10:15pm

Don't alter core code (ie, swipestripe core).
Make an extension like muskie9 has suggested and use that to add both the definition and the extra method :)
I'd be midly surprised if there's not already some kind of search function in swipestripe for seraching products though...

Avatar
mikeyc7m

Community Member, 19 Posts

14 August 2015 at 5:42pm

$searchable_fields is just for backend filtering. Added fields aren't included in the default site search. You'll have to provide your own search service. Check the Silverstripe tutorials, it's an easy job. Alternatively it is possible to extend the search service to include the extra field. It's all in the docs.

Avatar
Pyromanik

Community Member, 419 Posts

18 August 2015 at 12:05am

Edited: 18/08/2015 12:05am

$searchable_fields is for whatever kind of filtering you want, provided your custom search makes use of it.
By default it's not a part of SearchForm via FulltextSearchable, no. But then not much is, and it's not very extensible at all.
However IIRC SearchContext does make use of it, if one were inclined to use that.

Avatar
Webdoc

Community Member, 349 Posts

28 August 2015 at 10:56am

Edited: 28/08/2015 5:19pm

If i dont add the code below to Swipestripe Product.Php where i add it?? And how i can make it work. Any good pointers where to look for help like posts

private static $searchable_fields = array(
    'Productcode' => array(
        'field' => 'TextField',
        'filter' => 'PartialMatchFilter',
        'title' => 'Product Code'
    )
);

Is there a way to add it to the fulltext search or do i need to make my own searchform like in lesson 15?