Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Simplesearch fails on multiple terms

Started by Daniel Wrightson 6 years ago · 6 replies · 533 views
6 years ago

I may be missing something blindingly obvious, but simplesearch seems to not work on multiple search terms.

If I search for "Chanel" I get 19 results.
If I search for "Bag" I get 12 results
If I search for "Chanel b" I get 10 results
Then "Chanel ba" or "Chanel bag" gets 0 results

Does simplesearch just not cope with multiple terms? Or is there a setting I've missed?

6 years ago

I've looked into this further by testing other websites and grav skeletons that use simplesearch. It seems that it will only find adjacent terms, which seems fairly inefficient to me.

For example, on the SoraArticle skeleton, the first article is "Sunshine in the Hills"

If I search for "sunshine" I get the article
If I search for "hills" I also get the article
If I search for "sunshine hills" I get a zero result.

Surely this should work better than this, even for a simple search?

6 years ago

@dan-james, A quick look at the code reveals SimpleSearch does an explode(',', $query) and removes the page from the page collection if not all substrings from the explode exist in the page.

Meaning: A comma splits the search string and all sub-strings must exist in the page.

So try: "sunshine, hills"

I must admit it is a rather undocumented feature...

You also might want to take a look at TNTSearch which is index based and offers more functionality.

last edited 07/31/20 by pamtbaau
6 years ago

Thanks again pamtbaau! I didn't spot that - I did have a quick look through the code. These clients won't be putting commas in so I'll go for TNTSearch. Thanks for solving that.

It would make sense for simplesearch to explode on a gap - I don't know anybody who uses commas in search queries anymore... but that's for another day.

6 years ago

@dan-james, During my quick view I had the same thoughts on the use of commas...

Replacing the comma with space in explode and implode worked fine on first sight by the way.

6 years ago

Thanks - it looked like it should, but I went straight for TNTSearch which is now up and running very smartly. : )

👍 1
6 years ago

@dan-james, 👍

I agree that TNTSearch is probably the better choice for customers searching a vintage catalog.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 54 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1181 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 73 2 months ago