Create Lucene. NET and search multiple index files

Source: Internet
Author: User

Create parallel indexes of Lucene. net

Sometimes, for a document, some fields are frequently operated, while others are not. In this case, the field with frequent operations can be separated from other fields, while the two fields can be searched at the same time to extract a complete document.

This requires that the two indexes contain the same number of documents. When creating an index, you can create multiple indexwriter and split a document into multiple documents containing some fields as needed, add these documents to different indexes.

The parallelreader class must be used for integration during search.

Directory dir1 = fsdirectory. getdirectory (new file (index_dir1), false );
Directory dir2 = fsdirectory. getdirectory (new file (index_dir2), false );
Parallelreader preader = new parallelreader ();
Preader. Add (indexreader. Open (dir1 ));
Preader. Add (indexreader. Open (dir2 ));
Indexsearcher searcher = new indexsearcher (preader );

The subsequent operations are the same as general searches.

Lucene. Net simultaneously searches for Multiple indexes

When creating an index, you can create multiple indexes according to the category, and search for all indexes at the same time. This function is implemented by multisearcher.

Java mode:
Indexsearcher [] searchers = new indexsearcher [] {New indexsearcher (dir1), new indexsearcher (dir2 )};
Multisearcher msearcher = new multisearcher (searchers );

Query of multiple index files in Lucene. Net:

. Net mode:
Multireader reader = new multireader (New indexreader [] {
Indexreader. Open (system. Io. Path. Combine (TPL. commonset. Get ("threadsindexsdata"), "Main ")),
Indexreader. Open (system. Io. Path. Combine (TPL. commonset. Get ("threadsindexsdata"), "1 "))}
);
Indexsearcher searcher = new indexsearcher (Reader );

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.