About
Resources
Plans
Download
Jakarta
|
Overview
|
Although Lucene provides the ability to create your own query's though its API, it also provides a rich query language through the QueryParser.
This page provides syntax of Lucene's Query Parser, a lexer which interprets a string into a Lucene Query using JavaCC.
|
|
Terms
|
A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.
A Single Term is a single word such as "test" or "hello".
A Phrase is a group of words surrounded by double quotes such as "hello dolly".
Multiple terms can be combined together with Boolean operators to form a more complex query (see below).
|
|
Term Modifiers
|
Lucene supports modifying query terms to provide a wide range of searching options.
Wildcard Searches
|
Lucene supports single and multiple character wildcard searches.
To perform a single character wildcard search use the "?" symbol.
To perform a multiple character wildcard search use the "*" symbol.
The single character wildcard search looks for terms that match that with the single character replaced. For example, to search for "text" or "test" you can use the search:
Multiple character wildcard searches looks for 0 or more characters. For example, to search for test, tests or tester, you can use the search:
You can also use the wildcard searches in the middle of a term.
Note: You cannot use a * or ? symbol as the first character of a search.
|
|
Fuzzy Searches
|
Lucene supports fuzzy searches based on the Levenshtein Distance, or Edit Distance algorithm. To do a fuzzy search use the tilde, "~", symbol at the end of a term. For example to search for a term similar in spelling to "roam" use the fuzzy search:
This search will find terms like foam and roams
Note:Terms found by the fuzzy search will automatically get a boost factor of 0.2
|
|
|
|
Boolean operators
|
Boolean operators allow terms to be combined through logic operators.
Lucene supports AND, "+", OR, NOT and "-" as Boolean operators(Note: Boolean operators must be ALL CAPS).
+
|
The "+" or required operator requires that the term after the "+" symbol exist somewhere in a the field of a single document. For example, to search for documents that contain jakarta or lucene:
|
|
|
|
|