Searching for a phrase - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 10. There's an updated version available that covers our most recent release.

26-11-2015

Searching for a phrase

When searching for a phrase, i.e. a number of words in a specific sequence, you might be tempted to write something like

final String query = "Hippo is the best CMS";
filter.addContains(".", query);

However, HST's querying logic extracts all words from your query string, translating it to a logical query of 'Hippo AND is AND the AND best AND CMS', which could also be coded as:

filter.addContains(".", "Hippo");
filter.addContains(".", "is");
filter.addContains(".", "the");
filter.addContains(".", "best");
filter.addContains(".", "CMS");

In above query, the ordering of the words of the phrase is gone. The query will produce results with all of these words present in arbitrary order. When you worry about the word order and really look for a specific phrase, put your phrase between double quotes:

final String phrase = "\"Hippo is the best CMS\"";
filter.addContains(".", phrase);

 

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?