Forum
Status fields, excluding from search
I have created a "status" field for my collections, so things can be temporarily removed from the site. I'm using "suppress=true" so the status is never shown on the site (though that's not really necessary for me as I don't use my "master template" for the collection to output anything).
The issues are with search:
Firstly, the "search string" sometimes shows the word "active" (which is one of the statuses). Is this avoidable. Is there an attribute which would exclude the field from search (so that the word active doesn't show)? I guess a search for the word "active" would also return it, which again isn't desirable in this case.
There are probably other checkbox fields for which this would be useful.
Lastly, is there a way to stop the whole item appearing in search results IF the status is not "active" (or for some other condition or other)? Or do I just have to tell the client to delete the item?
The option of having a "status" for each item in your collection would be ideal for this scenario I guess.
I suppose one option would be "status" field type, which didn't add anything to the search string, and so stopped "active" from being added to the search excerpt or returned is a possibility, and something I could develop fairly easily, but stopping items from being returned IF the status field matched a certain value would be something more core to Perch I think.
Yes, use
no-index="true"
on the tag.Not currently, but it's something we've been thinking about.
That's great. Thanks Drew. Assuming I can still filter on the field even if it's set to no-index="true" (that it only affects search, not filtering in perch_content_custom()) for example?
Status might be cool, or another way to hide things from search without deleting them.
I guess I need to re-save each item in the collection to get the change to the template to take effect?
That's great. Thanks Drew. Assuming I can still filter on the field even if it's set to no-index="true" (that it only affects search, not filtering in perch_content_custom()) for example?
Status might be cool, or another way to hide things from search without deleting them.
I guess I need to re-save each item in the collection to get the change to the template to take effect?
Sorry, not
no-index
- you're right, that controls the index.Instead, use
searchable="false"
Thanks, Drew - that works. With no-index, I've found that if you try and filter on that field, you get nothing back. The searchable attribute does seem to be what I'm after. Neither are in the docs, but I imagine you're aware of that.
I guess a possible solution to excluding certain things from search results would be to allow a "filter" attribute on the perch_content_search() function, so I could filter out inactive entries from that, or limit just to certain collections etc. That would be neat. At the moment, search does feel a little limited.
As I say, it's something we've been thinking about doing.
Thanks, Drew - appreciate all your help.