Use multifieldqueryparser to search for multiple fields in lucene3.0

Source: Internet
Author: User
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 ());}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.