Queryparser (single domain query)
The Queryparser subclass creates query queries for a single domain query, and constructs a method that requires an incoming Lucene version number to retrieve the domain name and the word breaker.
new QueryParser(Version.LUCENE_43, field, analyzer);// 查询字符串Query query = parser.parse("key");
Multifieldqueryparser (multi-domain query)
new MultiFieldQueryParser(Version.LUCENE_43, fields, analyzer);Query query2 = parser2.parse(key);
Termquery (single key field query)
TermQuery tq=new TermQuery(newkey));
Prefixquery (prefix character query)
Prefixquery only need to specify a number of characters prefix prestr, prestr start will be matched, such as "Lu" can Match "Luke", "Lucene".
PrefixQuery prefixQuery=new PrefixQuery(new Term("field,key));
Phrasequery (phrase query)
PhraseQuery phraseQuery=new PhraseQuery(); phraseQuery.setSlop(3);//关键词间距离 phraseQuery.add(new"key1"));//关键词1 phraseQuery.add(new"key2"));//关键词2
The above query instance can match the keyword Key1 and the key2 spacing is not more than 3 of the document, field for the query domain.
Wildcardquery (wildcard query)
WildcardQuery wildcardQuery=new WildcardQuery(new"基于?"));
Match 1 characters, * match any number of characters.
Termrangequery (String range Search)
TermRangeQuery rangeQuery=new TermRangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper);
The five parameters are the domain name, the lower limit of the field, the upper limit of the field, whether the lower limit is included, and whether the upper limit is included. Like what:
TermRangeQuery rangeQuery=new"aab""azz"truefalse);
Numericrangequery (Digital range Search)
Query q = NumericRangeQuery.newFloatRange("weight"0.03f0.10ftruetrue);
Matches all documents whose float valued ' weight ' field ranges from 0.03 to 0.10, inclusive.
Booleanquery (Boolean query)
Multiple query objects grouped into one object
BooleanQuery bQuery=new BooleanQuery(); bQuery.add(new TermQuery(new Term("title""lucene")), Occur.MUST); bQuery.add(new TermQuery(new Term("content""基于")), Occur.SHOULD); bQuery.add(new TermQuery(new Term("name""java")), Occur.MUST_NOT);
The above example is used to query that the title must contain "Lucene" (and) or that the cotent contains "based on" (or) but the name does not necessarily contain "Java" (not) of the document.
Lucene Query sub-class