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 );