Parses a simple search-box query string into structured must/must-not terms, splitting free text from field:value clauses (for example title:foo -tag:draft) so a caller can turn each field clause into a proper search query. A combine:and or combine:or clause switches whether the parsed terms are combined with AND or OR; everything else becomes either a plain text term or a field-scoped term, negated with a leading minus sign.
Properties
| Property | Returns | Description |
|---|---|---|
| combineWithAnd | boolean | Whether the parsed terms should be combined with AND (true) or OR (false) when building a query from them. Defaults to true, and can be overridden in the query string with a combine:and or combine:or clause. |
| queryMust | Set<KQueryField> | Field-scoped query terms that results must match, each pairing a field name with the value it must equal. |
| queryMustNot | Set<KQueryField> | Field-scoped query terms that results must not match, each pairing a field name with the value it must not equal. |
| textMust | Set<String> | Free-text search terms (not scoped to a field) that results must match. |
| textMustNot | Set<String> | Free-text search terms (not scoped to a field) that results must not match. |
Methods
getTextMust() · getTextMustNot() · getQueryMust() · getQueryMustNot() · isCombineWithAnd() · containsTerm(String name) · findMustTerm(String name) · findMustNotTerm(String name) · removeTerm(String name) · parseQuery(String queryString) · getQueryMust(String fieldName) · getQueryMustNot(String fieldName) · mapField(String userEntered, String queryFieldName)
getTextMust()
Returns: Set<String>
Free-text search terms (not scoped to a field) that results must match.
getTextMustNot()
Returns: Set<String>
Free-text search terms (not scoped to a field) that results must not match.
getQueryMust()
Returns: Set<KQueryField>
Field-scoped query terms that results must match, each pairing a field name with the value it must equal.
getQueryMustNot()
Returns: Set<KQueryField>
Field-scoped query terms that results must not match, each pairing a field name with the value it must not equal.
isCombineWithAnd()
Returns: boolean
Whether the parsed terms should be combined with AND (true) or OR (false) when building a query from them. Defaults to true, and can be overridden in the query string with a combine:and or combine:or clause.
containsTerm(String name)
Returns: boolean
Whether any must or must-not field-scoped term uses the given field name.
| Parameter | Description |
|---|---|
name | the field name to check for |
findMustTerm(String name)
Returns: String
Value of the must-match field term for the given field name, if one was parsed.
| Parameter | Description |
|---|---|
name | the field name to look up |
findMustNotTerm(String name)
Returns: String
Value of the must-not-match field term for the given field name, if one was parsed.
| Parameter | Description |
|---|---|
name | the field name to look up |
removeTerm(String name)
Returns: KSearchQuery
Removes every must and must-not field-scoped term for the given field name, leaving free-text terms untouched.
| Parameter | Description |
|---|---|
name | the field name whose terms should be removed |
parseQuery(String queryString)
Returns: void
Parses a search-box query string, replacing this query's current terms with the ones parsed from it. Splits the string on unquoted whitespace (double-quoted phrases are kept together), strips leading minus signs into a must-not flag, and for each remaining part either records it as a free-text term or, if it contains a colon, as a field:value term - except for a combine:and or combine:or part, which instead sets whether terms are combined with AND or OR.
| Parameter | Description |
|---|---|
queryString | the search-box query string to parse |
getQueryMust(String fieldName)
Returns: KQueryField
Must-match field term for the given field name, if one was parsed.
| Parameter | Description |
|---|---|
fieldName | the field name to look up |
getQueryMustNot(String fieldName)
Returns: KQueryField
Must-not-match field term for the given field name, if one was parsed. Note this looks the field name up in the must-match terms, not the must-not-match terms - the value is null unless the same field also has a must-match term.
| Parameter | Description |
|---|---|
fieldName | the field name to look up |
mapField(String userEntered, String queryFieldName)
Returns: KSearchQuery
Renames a field across every parsed must and must-not term, so a simpler name shown to the user (for example module) can be mapped on to the actual field name stored in the database (for example moduleCode). Must be called after parseQuery.
| Parameter | Description |
|---|---|
userEntered | the field name as entered by the user |
queryFieldName | the field name as stored in the database |