http://akululu.iteye.com/blog/314130
多索引目录就是要在多个索引目录的中进行比较搜索,类似概念在SQL中就是select * from TableA union select * from TableB。
IndexSearcher[] searchers = new IndexSearcher[2];
searchers[0] = new IndexSearcher(IndexPath0);
searchers[1] = new IndexSearcher(IndexPath1);

方法a
MultiSearcher multisearcher = new MultiSearcher(searchers);
TopDocs multitopdocs = multisearcher.Search(query, null, 1000);
这个搜索的结果可能有相同的信息,比如你有一条相同的信息在多个目录中索引,搜索的结果就会出现多次相同的信息。

方法b
还有一种搜索方式是用到ParallelMultiSearcher这个对象,它是从MulitSearcher继承而来。
ParallelMultiSearcher parallelmultisearcher = new ParallelMultiSearcher(searchers);
TopDocs paralleltopdocs = parallelmultisearcher.Search(query, null, 1000);
这个搜索是对搜索后的结果进行合并,剔除重复的信息。
 
方法c
初始化多个IndexRader,一个目录就是一个IndexReader,最后整合成一个IndexReader数组,实例化IndexSearcher时传入他
List<IndexReader> allIndexReaderList = new ArrayList<IndexReader>();
for (String filePath : indexFilePathList) {
     File indexDirFile = new File(filePath);
     if (indexDirFile.exists()) {
          Directory indexDir = FSDirectory.open(indexDirFile);
          IndexReader indexReader = IndexReader.open(indexDir, true);
          allIndexReaderList.add(indexReader);
     }
}

IndexReader[] fileIndexReaderArr = allIndexReaderList.toArray(new IndexReader[0]);

MultiReader multiReader = new MultiReader(fileIndexReaderArr, true);

IndexSearcher indexSearcher = new IndexSearcher(multiReader);

lucene 多索引目录搜索实现方法的更多相关文章

  1. Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

  2. lucene写索引出现锁文件的原因之一

    lucene正常情况目录下的文件 有三个文件. segments.gen segments_a08, 还有一个类似 _uw.cfs名字的东西. 当然,不一定都一样, 但肯定是这三个. 如果出现了很多文 ...

  3. lucene全文搜索之二:创建索引器(创建IKAnalyzer分词器和索引目录管理)基于lucene5.5.3

    前言: lucene全文搜索之一中讲解了lucene开发搜索服务的基本结构,本章将会讲解如何创建索引器.管理索引目录和中文分词器的使用. 包括标准分词器,IKAnalyzer分词器以及两种索引目录的创 ...

  4. Lucene第二讲——索引与搜索

    一.Feild域 1.Field域的属性 是否分词:Tokenized 是:对该field存储的内容进行分词,分词的目的,就是为了索引. 否:不需要对field存储的内容进行分词,不分词,不代表不索引 ...

  5. 搜索引擎系列 ---lucene简介 创建索引和搜索初步

    一.什么是Lucene? Lucene最初是由Doug Cutting开发的,2000年3月,发布第一个版本,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎 :Lucene得名于Doug妻子 ...

  6. 理解Lucene索引与搜索过程中的核心类

    理解索引过程中的核心类 执行简单索引的时候需要用的类有: IndexWriter.ƒDirectory.ƒAnalyzer.ƒDocument.ƒField 1.IndexWriter IndexWr ...

  7. Lucene.net 从创建索引到搜索的代码范例

    关于Lucene.Net的介绍网上已经很多了在这里就不多介绍Lucene.Net主要分为建立索引,维护索引和搜索索引Field.Store的作用是通过全文检查就能返回对应的内容,而不必再通过id去DB ...

  8. lucene简介 创建索引和搜索初步

    lucene简介 创建索引和搜索初步 一.什么是Lucene? Lucene最初是由Doug Cutting开发的,2000年3月,发布第一个版本,是一个全文检索引擎的架构,提供了完整的查询引擎和索引 ...

  9. Lucene中最简单的索引和搜索示例

    package com.jiaoyiping.lucene; import org.apache.lucene.analysis.standard.StandardAnalyzer; import o ...

随机推荐

  1. [thinkphp]验证码不显示: 图像因存在错误无法显示

    我只想说,该死的BOM FUKKKKK!!!!!!!!

  2. HDU 1181.变形课-并查集

    变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submis ...

  3. POJ 2387 链式前向星下的SPFA

    (POJ)[http://poj.org/problem?id=2387] Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K ...

  4. CSU七月校赛B

    #include <iostream> #include<cstdio> #include<algorithm> #include<cstring> # ...

  5. C++string类常用函数

    C++string类常用函数 string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初 ...

  6. 【Android】 HttpClient 发送REST请求

    直接po代码吧,第一个是一个枚举类型的类,是四种rest http请求,get/post/put/delete: public enum HttpRequestMethod { HttpGet { @ ...

  7. [Atcoder Grand Contest 001] Tutorial

    Link: AGC001 传送门 A: …… #include <bits/stdc++.h> using namespace std; ; ]; int main() { scanf(& ...

  8. [Contest20180426]校门外的树

    $\newcommand{\align}[1]{\begin{align*}#1\end{align*}}$题意:对于一个排列$p_{1\cdots n}$构造一个图,如果$i\lt j$且$p_i\ ...

  9. python3开发进阶-Django框架的详解

    一.MVC框架和MTV框架 MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分: 模型(Model).视图(View)和控制器(Con ...

  10. Problem B: 调用函数,输出100到200之间的所有素数

    #include <stdio.h> int isPrime(unsigned int n)//定义素数函数 { int i; || n == ) ; ; i * i <= n; i ...