The Solr search type supports a range of useful operators for prefix/suffix queries and boolean logic.
- Keyword matching
-
Keywords can contain one or more terms with qualifiers:
filename:foo
filename isfoo
comment:bar
termbar
exists in a commentcomment:"foo bar"
phrasefoo bar
exists in a comment - Boolean logic
-
Keywords can be combined as logical specifiers in the search specification:
filename:foo AND comment:"to do"
filename isfoo
and phraseto do
exists in a commentfilename:foo -bar
filename isfoo
and contents don't contain the termbar
filename:foo -comment:bar
filename isfoo
and comments don't contain the termbar
comment:("beta 1" OR "beta 2")
phrasebeta 1
orbeta 2
exists in a comment - Allowed characters
-
Any Unicode character may be used in terms, but certain characters are reserved and must be escaped. The Krugle Solr reserved characters are:
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /
Any reserved character can be escaped with a backslash, e.g.
\*
to indicate that*
is NOT a wildcard. This includes the backslash character itself, via\\
Additionally, any characters (except double quotes) are interpreted literally when surrounded by double quotes:
"john@solr-demo.com"
- Wildcard matching
-
The asterisk symbol
*
can be used to represent any character or group of characters. WARNING: Wildcard searches that start with the wildcard symbol*
can be very slow and should only be used when the results cannot be specified with other query options.foo*
find terms that start withfoo
*bar
find terms that end withbar
foo*bar
find terms that start withfoo
and end withbar
- Proximity
-
The tilde symbol
~
can be used to find terms within a specified distance. Note that exact matches have proximity 0 and that word transpositions (bar foo instead of foo bar) have proximity 1:"foo bar"
findfoo
immediately followed bybar
(proximity 1 is the default)"foo bar"~3
find matches wherefoo
andbar
are within 3 terms - Regular Expression
Enclosing the search query within slash characters
/ /
denotes that the pattern within the slashes is a regular expression. Note that the regular expression doesn't span across tokens/foo*bar/
will find occurrences where the term starts withfo
and is followed by 0 or more occurences ofo
followed bybar
/foo+bar/
will find occurrences where the term starts withfo
and is followed by 1 or more occurences ofo
followed bybar
More details on the regular expression support can be found here.