public class SearchQueryParser extends Object
The syntax is as follows:
*
*
or empty string is the match-all operator, it should not be combined with otherssometext
sometext
in the default fieldfield:sometext
field
-field:sometext
field
but negates the search conditionfield:some,text
field
twice, as if field:some field:text
was given
Whitespace is used to separate words, if whitespace is important you can quote the string with single or double quotes: field:'hello world'
.
The class needs two parameters, the default field name to use for query text and the set of allowed fields to search in. The default field name must be the database name.
If the external field names should be different to what is used by the database, you can optionally pass the allowed fields as a Map
. The parser will then try to replace each field name with the corresponding value in the map.
If the key has no mapping the default field name is used instead and the field name is recorded as being invalid. This lets the caller execute the query but still allows for error checking. It is the callers responsibility to decide which behavior is applicable.
Instances of this class are safe to use from multiple threads.Modifier and Type | Class and Description |
---|---|
static class |
SearchQueryParser.FieldValue |
Modifier and Type | Field and Description |
---|---|
static SearchQueryOperator |
DEFAULT_OPERATOR |
Constructor and Description |
---|
SearchQueryParser(String defaultField,
Map<String,SearchQueryField> allowedFieldsWithMapping)
Constructs a new parser with explicit field mapping.
|
SearchQueryParser(String defaultField,
Set<String> allowedFields)
Constructs a new parser without field mapping.
|
public static final SearchQueryOperator DEFAULT_OPERATOR
public SearchQueryParser(@Nonnull String defaultField, @Nonnull Set<String> allowedFields)
defaultField
- the name of the default fieldallowedFields
- the names of allowed fields in the querypublic SearchQueryParser(@Nonnull String defaultField, @Nonnull Map<String,SearchQueryField> allowedFieldsWithMapping)
defaultField
- the name of the default field (already mapped)allowedFieldsWithMapping
- the map of field mappings, keys are the allowed fields, values are the replacementspublic SearchQuery parse(String queryString)
Copyright © 2012–2018 Graylog, Inc.. All rights reserved.