[Tutorial 6 of ipve4.8] queryparser and query subclass: how to generate a query object

Source: Internet
Author: User
Tags java keywords

For a search, the core statement is:

 
Searcher. Search (query, 10 );
In this case, the most important parameter is a qeury object. There are two methods to construct a query object: [search for Java keywords in the contents domain as an example]

(1) Use a subclass of query, such as booleanquery, constantscorequery, disjunctionmaxquery, filteredquery, matchalldocsquery, multiphrasequery, multitermquery, phrasequery, spanquery, and termquery to instantiate an external interface:

 
Searcher. Search (New termquery (new term ("contents", "Java"), 10 );

The following statement structure is clearer:

Term term = new term ("contents", "Java"); termquery TQ = new termquery (TERM); searcher. Search (TQ, 10 );

In addition, search for documents containing Java in the contents domain.

(2) Use the parse () method of queryparser to explain the Input key words in the search and return the query object.

 
Queryparser parser = new queryparser (version. inclue_48, "contents", new simpleanalyzer (version. required e_48); query = NULL; try {query = parser. parse ("Java");} catch (parseexception e) {e. printstacktrace ();} topdocs docs = searcher. search (query, 10 );
The preceding statement creates a queryparser, whose default search domain is contents, and converts the search vocabulary to a query object.

If queryparser is specified, the default search domain is all? How to specify a query search domain?

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.