1.3. Search by Entry -termquery
query query = NULL;
Query=new Termquery (New term ("name", "Word1 A and");
Hits=searcher.search (query);//Find name:word1 A and a total of 0 results
System.out.println ("Find " +query.tostring () + "Total " + hits.length () + "results ");
1.4. Press "and or" to search for -booleanquery
1. And: must and must_not
2. Or: should and should
the must of 3.A and B-B and must_not
Query Query1=null;
Query Query2=null;
Booleanquery Query=null;
Query1=new Termquery (New term ("name", "Word1"));
Query2=new Termquery (New term ("name", "Word2"));
Query=new Booleanquery ();
Query.add (Query1,booleanclause.occur.must);
Query.add (Query2,booleanclause.occur.must_not);
1.5. Search for -rangequery within a range
Term begintime=new term ("Time", "200001");
Term endtime=new term ("Time", "200005");
Rangequery Query=null;
Query=new rangequery (Begintime,endtime,false);//does not contain boundary values
1.6. Search -prefixquery with a prefix
Term pre1=new term ("name", "wor");
Prefixquery Query=null;
query = new Prefixquery (pre1);
1.7. Phrase search-phrasequery
A) The default slope is 0
Phrasequery query = new Phrasequery ();
Query.add (New term ("bookname", "Steel"));
Query.add (New term ("bookname", "Iron"));
Hits hits=searcher.search (query); Search for "steel" phrases rather than "steel" and "iron"
b) Set slope, default to 0
Phrasequery query = new Phrasequery ();
Query.add (New term ("bookname", "Steel"));
Query.add (New term ("bookname", "Iron"));
Query.setslop (1);
Hits hits=searcher.search (query);//Search for "steel" or "Steel * iron" with one word
1.8. Multi-phrase search -multiphrasequery
A
Multiphrasequery query=new multiphrasequery ();
First add the prefix to the phrase you want to find
Query.add (New term ("bookname", "Steel"));
Construct 3 term as a suffix of a phrase
Term t1=new term ("bookname", "Iron");
Term t2=new term ("bookname", "and");
Term t3=new term ("bookname", "want");
add all the suffixes to query, together with the prefixes, they will form 3 phrases
Query.add (New term[]{t1,t2,t3});
Hits hits=searcher.search (query);
for (int i=0;i
System.out.println (Hits.doc (i));
b
Multiphrasequery query=new multiphrasequery ();
Term t1=new term ("bookname", "Steel");
Term t2 = new Term ("bookname", "and");
Query.add (New term[]{t1,t2});
Query.add (New term ("bookname", "Iron"));
C
Multiphrasequery query=new multiphrasequery ();
Term t1=new term ("bookname", "Steel");
Term t2 = new Term ("bookname", "and");
Query.add (New term[]{t1,t2});
Query.add (New term ("bookname", "Iron"));
Term t3=new term ("bookname", "yes");
Term t4=new term ("bookname", "war");
Query.add (New Term[]{t3,t4});
1.9. Fuzzy search-fuzzyquery
The algorithm used is the Levenshtein algorithm, which divides the action into 3 types when comparing two strings:
L plus a single letter
L Delete one letter
L Change a letter
Fuzzyquery query=new Fuzzyquery (New term ("content", "work"));
Public Fuzzyquery (term)
Public Fuzzyquery (Term,float minimumsimilarity) throws IllegalArgumentException
Public Fuzzyquery (Term,float minimumsimilarity,int prefixlength) throws IllegalArgumentException
Where minimumsimilarity is the minimum similarity, the smaller the number of documents. The default is 0.5. The value must be <1.0
Fuzzyquery query=new Fuzzyquery (New term ("content", "work"), 0.1f);
Where prefixlength indicates how many prefix letters must match exactly
Fuzzyquery query=new Fuzzyquery (New term ("content", "work"), 0.1f,1);
1.10. Wildcard Search-wildcardquery
* Represents 0 to more characters
? Represents a single character
Wildcardquery query=new Wildcardquery (New term ("content", "? qq*"));
1.11. Span Search1.11.1. spantermquery
The same effect as termquery
Spantermquery query=new Spantermquery (New term ("content", "abc"));
1.11.2. spanfirstquery
finds the specified entry in a fixed width, starting at the beginning of field content
Spanfirstquery query=new Spanfirstquery (New term ("content", "abc"), 3);//Is the first 3 word, not byte
1.11.3. spannearquery
Spannearquery quite with Phasequery
Spantermquery people=new Spantermquery (New term ("content", "Mary"));
Spantermquery how=new Spantermquery (New term ("content", "poor"));
Spannearquery query=new spannearquery (new Spanquery[]{people,how},3,false);
1.11.4. spanorquery
Put together the results of all spanquery.
Spantermquery s1=new Spantermquery (New term ("content", "AA");
Spantermquery s2=new Spantermquery (New term ("content", "CC");
Spantermquery s3=new Spantermquery (New term ("content", "GG");
Spantermquery s4=new Spantermquery (New term ("content", "KK");
Spannearquery query1=new spannearquery (new Spanquery[]{s1,s2},1,false);
Spannearquery query2=new spannearquery (new Spanquery[]{s3,s4},3,false);
Spanorquery query=new spanorquery (New Spanquery[]{query1,query2});
1.11.5. spannotquery
From the results of the query in the 1 spanquery, remove the query results from the 2 spanquery
Spantermquery s1=new Spantermquery (New term ("content", "AA");
Spanfirstquery query1=new spanfirstquery (s1,3);
Spantermquery s3=new Spantermquery (New term ("content", "GG");
Spantermquery s4=new Spantermquery (New term ("content", "KK");
Spannearquery query2=new spannearquery (new Spanquery[]{s3,s4},4,false);
Spannotquery query=new spannotquery (Query1,query2);
1.12. query for regexquery-regular Expressions
String regex= "http://[a-z]{1,3}\\.abc\\.com/.*";
Regexquery query=new Regexquery (New term ("url", regex));
Ext.: http://www.blogjava.net/fanyingjie/archive/2010/06/21/324038.html
Lucene Query Types