zoukankan      html  css  js  c++  java
  • Lucene.NET搜索多个索引文件

    有时对于一个Document来说,有一些Field会被频繁地操作,而另一些Field则不会。这时可以将频繁操作的Field和其他Field分开存放,而在搜索时同时检索这两部分Field而提取出一个完整的Document。 

        这要求两个索引包含的Document的数量必须相同, 在创建索引的时候,可以同时创建多个IndexWriter,将一个Document根据需要拆分成多个包含部分Field的Document,并将这些Document分别添加到不同的索引。

         而在搜索时,则必须借助ParallelReader类来整合。

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

    之后的操作和一般的搜索相同。

    Lucene.NET 同时搜索多个索引

      在创建索引的时候可以根据分类需要创建多个索引,而在搜索时可以同时搜索所有的索引, 这一功能通过MultiSearcher实现。

    Java模式的写法:
    IndexSearcher[] searchers
    =new IndexSearcher[]{new IndexSearcher(dir1),new IndexSearcher(dir2)};
           MultiSearcher msearcher
    =new MultiSearcher(searchers);

    .NET模式的写法:
    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);

  • 相关阅读:
    HLS Coding Style: Hardware Efficient C Code
    HLS Coding Style: Arrays and Data Types
    HLS Coding Style: Unsupported C Constructs
    HLS Optimization: Latency V.S. Throughput
    HLS Optimization: Pipeline V.S. Unroll
    HLS Coding Style: Functions and Loops
    HLS Optimization: Latency
    HLS Optimization: Throughput
    hive常见报错
    Neo4j 第三篇:Cypher查询入门
  • 原文地址:https://www.cnblogs.com/wudingfeng/p/Lucene.html
Copyright © 2011-2022 走看看