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?