Lucene.Net Multi-field multiple index directory search

Source: Internet
Author: User
Keywords Yes nbsp;
Tags .mall .net content development development process directory index information

Lucene.Net is an open source project for Full-text indexing that is currently widely used in. NET environments and is used for full-text indexing in project development.
A few small problems in the development process are searching for multiple fields and multiple indexed directories.

1, a multiple-field search is to have more than one field of the content of the comparison search, similar concepts in SQL is select * from Table where a like '%query% ' or b '%query% '.

Single field query in Lucene.Net Everyone is familiar with the field content search

Query query = queryparser.parse (querystr, Content, New Chineseanalyzer ());
Hits Hits = searcher. Search (query);

A Multifieldqueryparser object is used for multiple field queries that inherit from query, and we want to search for field title,content.

String] fields = {"Content", "title"};
Query multiquery = Multifieldqueryparser.parse (querystr,fields,new chineseanalyzer ());
Hits Hits = searcher. Search (Multiquery);

2. Multiple indexed directories are to compare searches in multiple index directories, similar to the SELECT * FROM TableA Union SELECT * FROM TableB in SQL.

Indexsearcher[] Searchers = new indexsearcher[2];
Searchers[0] = new Indexsearcher (IndexPath0);
SEARCHERS[1] = new Indexsearcher (IndexPath1);

Multisearcher multisearcher = new Multisearcher (searchers);
Topdocs Multitopdocs = Multisearcher. Search (query, NULL, 1000);

The results of this search may have the same information, such as you have a similar information in multiple directories indexed, search results will appear many times the same information.

Another way to search is to use the Parallelmultisearcher object, which is inherited from Mulitsearcher.

Parallelmultisearcher parallelmultisearcher = new Parallelmultisearcher (searchers);
Topdocs Paralleltopdocs = Parallelmultisearcher. Search (query, NULL, 1000);

This search is a search for the results of the merger, eliminating duplicate information.

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.