Lucene is used for full-text search. Generally, we often search for multiple fields (fields), but we do not necessarily care about the fields that contain the values to be searched. for example, in the search box, enter "Parent-Child software development" as long as the title, content, and author contain "Parent-Child software development. MultiFieldQueryParser in Lucene provides convenience for searching multiple fields.
MultiFieldQueryParser multiParser =
New MultiFieldQueryParser (Version. inclue_current
, New String [] {"title", "content", "author"}, analyzer );
MultiParser. setPhraseSlop (3); // you can specify 3 as the slope of a phrase search. The default value is 0.
MultiParser. setDefaultOperator (QueryParser. Operator. AND );
// Set the link of the phrase separated by spaces. The default is or;
Query query = multiParser. parse (str );
However, the MultiFieldQueryParser of javase3.0 is a bit problematic, that is, it cannot be used after setPhraseSlop. You just need to change 0 to this. getPhraseSlop () in line 1 of the source code.
Protected Query getFieldQuery (String field, String queryText) throws ParseException {
Return getFieldQuery (field, queryText, this. getPhraseSlop ());}