|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectSimpleQueryRewriter
QuerySpeller
public class QuerySpeller
Handles spelling correction for simple queries produced by the Lucene
QueryParser
. Allows a custom QueryParser
to be supplied,
though it must retain the case of the input tokens, so that we can supply
spelling corrections using the same case the user did.
Field Summary | |
---|---|
private HashSet<String> |
fieldSet
Set of fields we're allowed to collect terms for |
private QueryParser |
queryParser
Used to parse queries |
private SpellReader |
spellReader
Used to get spelling suggestions |
private HashMap<String,String> |
suggestMap
Mapping of terms to replace |
private LinkedHashSet<String> |
terms
List of terms collected |
Constructor Summary | |
---|---|
QuerySpeller(SpellReader spellReader)
Construct a new speller using a given dictionary reader. |
|
QuerySpeller(SpellReader spellReader,
QueryParser queryParser)
Construct a new speller using a given dictionary reader and analyzer (note that the analyzer should do MINIMAL token filtering, without any case conversion). |
Method Summary | |
---|---|
protected Term |
rewrite(Term t)
This is the way we slip in to grab or rewrite terms |
String |
suggest(String inQuery)
Suggest alternate spellings for terms in a Lucene query. |
String |
suggest(String inQuery,
String[] fields)
Suggest alternate spellings for terms in a Lucene query, limiting suggestions to the specified fields only. |
private void |
validateAnalyzer()
Make sure the analyzer preserves the case of input tokens. |
Methods inherited from class SimpleQueryRewriter |
---|
rewrite, rewrite, rewrite, rewriteQuery |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private SpellReader spellReader
private HashSet<String> fieldSet
private LinkedHashSet<String> terms
private HashMap<String,String> suggestMap
private QueryParser queryParser
Constructor Detail |
---|
public QuerySpeller(SpellReader spellReader)
MinimalAnalyzer
, and the default field
name will be "text".
spellReader
- source for spelling suggestions -- see
SpellReader.open(File)
.public QuerySpeller(SpellReader spellReader, QueryParser queryParser)
spellReader
- source for spelling suggestions -- see
SpellReader.open(File)
.queryParser
- used to parse queries; note that the analyzer it uses
should do only MINIMAL token filtering, not even conversion to
lower case, so that suggestions can be made in the same case the
user typed them. In particular, StandardAnalyzer should not be
used.Method Detail |
---|
private void validateAnalyzer()
public String suggest(String inQuery) throws ParseException, IOException
inQuery
- the original query to scan
ParseException
IOException
public String suggest(String inQuery, String[] fields) throws ParseException, IOException
inQuery
- the original query to scanfields
- to consider for correction, or null for all
ParseException
IOException
protected Term rewrite(Term t)
rewrite
in class SimpleQueryRewriter
t
- The term to rewrite
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |