Step by step and learn from me Lucene (8) Query principle and Query tool class example---lucene search index

Source: Internet
Author: User

Yesterday we learned about the Indexsearcher build process for Lucene search (http://blog.csdn.net/wuyinggui10000/article/details/45698667), Have a general understanding of Lucene's indexsearcher, know how to create indexsearcher, we should begin to learn to use Indexsearcher to index the search, In this section we learn the principles of indexing and the writing of tool classes that write indexed queries based on their related principles;

Indexsearcher provides several common methods:

    • Indexsearcher.doc (int docID) Gets the related field of the Nth index store in the index file, returned as the document type, which can read the field of the Field.STORE.YES in the document accordingly;
    • Indexsearcher.doc (int docID, storedfieldvisitor fieldvisitor) Gets the document for the field specified by Storedfieldvisitor, Storedfieldvisitor is defined as follows
        Storedfieldvisitor visitor = new Documentstoredfieldvisitor (String ... fields);
    • Indexsearcher.doc (int docID, set<string> fieldstoload) This method is the same as the upper Indexsearcher.doc (int DocID, storedfieldvisitor Fieldvisitor), which is implemented as

    • Indexsearcher.count (query query) counts the number of document matching the query criteria
    • Indexsearcher.searchafter (final scoredoc After, query query, int numhits) This method returns the Numhits records that match the query criteria and after the after;

Its implementation principle is:

Read the maximum number of data bars of the current index file limit, and then determine if after is empty and after the subscript of the document exceeds the limit limits, and if exceeded, throws an illegal parameter exception;

Set the number of reads to be the smallest in numhits and limit (due to the possibility of exceeding the maximum number of bars, avoiding the exception caused by exceeding the limit)

Next, create an object of type Collectormanager that defines the number of Topdocs to return, the end of document on the previous page (after), and the analysis merge for the query results

Finally call search (Query,manager) to query the results

    • Indexsearcher.search (query query, int n) queries the top N records that match the query criteria
    • Indexsearcher.search (query query, Collector results) queries records that conform to Collector, Collector defines information such as pagination
    • Indexsearcher.search (query query, int n,sort sort, Boolean dodocscores, Boolean Domaxscore) implements arbitrary-ordered queries while controlling whether hit is calculated Whether score and Max score are counted, query the first n of the document that meets the query criteria;
    • Indexsearcher.search (query query, collectormanager<c, t> Collectormanager) Using the given collectormanager to get the results that match the query criteria, the execution flow is as follows:

First of all to determine whether there are executorservice to perform query tasks, if there is no executor,indexsearcher will be in a single task under the query operation;

If the Indexsearcher has executor, then each thread will control the reading of a part of the index, and the process of querying is using the future mechanism, which is to append data to the result set by reading edge, this kind of different

The processing mechanism of the step also improves the efficiency, the execution process is as follows:

It's not too early, and today it's written here, and tomorrow will be supplemented by adding relevant examples, everybody goodnight



Step by step and learn from me Lucene (8) Query principle and Query tool class example---lucene search index

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.