当前位置: 首页>>代码示例>>Java>>正文


Java IndexReader.open方法代码示例

本文整理汇总了Java中org.apache.lucene.index.IndexReader.open方法的典型用法代码示例。如果您正苦于以下问题:Java IndexReader.open方法的具体用法?Java IndexReader.open怎么用?Java IndexReader.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.index.IndexReader的用法示例。


在下文中一共展示了IndexReader.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildAndRegisterDeltaReader

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private IndexReader buildAndRegisterDeltaReader(String id) throws IOException
{
    IndexReader reader;
    // only register on write to avoid any locking for transactions that only ever read
    File location = getDeltaLocation(id);
    // File location = ensureDeltaIsRegistered(id);
    // Create a dummy index reader to deal with empty indexes and not
    // persist these.
    if (IndexReader.indexExists(location))
    {
        reader = IndexReader.open(location);
    }
    else
    {
        reader = IndexReader.open(emptyIndex);
    }
    return reader;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:IndexInfo.java

示例2: buildReferenceCountingIndexReader

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private IndexReader buildReferenceCountingIndexReader(String id, long size) throws IOException
{
    IndexReader reader;
    File location = new File(indexDirectory, id).getCanonicalFile();
    double folderSize = getSizeInMb(location);
    if (IndexReader.indexExists(location))
    {
        if ((size < maxDocsForInMemoryIndex) && (folderSize < maxRamInMbForInMemoryIndex))
        {
            RAMDirectory rd = new RAMDirectory(location);
            reader = IndexReader.open(rd);
        }
        else
        {
            reader = IndexReader.open(location);
        }
    }
    else
    {
        reader = IndexReader.open(emptyIndex);
    }
    reader = ReferenceCountingReadOnlyIndexReaderFactory.createReader(id, reader, true, config);
    return reader;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:IndexInfo.java

示例3: main

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
      Directory directory = FSDirectory.getDirectory("demo index", false);
      IndexReader reader = IndexReader.open(directory);

//       Term term = new Term("path", "pizza");
//       int deleted = reader.delete(term);

//       System.out.println("deleted " + deleted +
// 			 " documents containing " + term);

      for (int i = 0; i < reader.maxDoc(); i++)
	reader.delete(i);

      reader.close();
      directory.close();

    } catch (Exception e) {
      System.out.println(" caught a " + e.getClass() +
			 "\n with message: " + e.getMessage());
    }
  }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:DeleteFiles.java

示例4: indexDocs

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private static void indexDocs(File file, String index, boolean create)
      throws Exception {
   if (!create) {				  // incrementally update

     reader = IndexReader.open(index);		  // open existing index
     uidIter = reader.terms(new Term("uid", "")); // init uid iterator

     indexDocs(file);

     if (deleting) {				  // delete rest of stale docs
while (uidIter.term() != null && uidIter.term().field() == "uid") {
  System.out.println("deleting " +
		     HTMLDocument.uid2url(uidIter.term().text()));
  reader.delete(uidIter.term());
  uidIter.next();
}
deleting = false;
     }

     uidIter.close();				  // close uid iterator
     reader.close();				  // close existing index

   } else					  // don't have exisiting
     indexDocs(file);
 }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:IndexHTML.java

示例5: QueryProcessor

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
public QueryProcessor(Search parent, String name, int id, String index, String outBase, String queryBase, String field, String normsField, boolean raw,
    int hitsPerPage) {
  this.parent = parent;
  this.field = field;
  this.raw = raw;
  this.hitsPerPage = hitsPerPage;
  try {
    reader = IndexReader.open(index);
    if (normsField != null)
      reader = new OneNormsReader(reader, normsField);
    searcher = new IndexSearcher(reader);

    String query = queryBase + (id < 10 ? "00" : (id < 100 ? "0" : "")) + id + ".txt";
    in = new BufferedReader(new FileReader(query));
    out = new PrintWriter(new BufferedWriter(new FileWriter(outBase + id)));

  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:21,代码来源:Search.java

示例6: resetClassFields

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
@Override
public void resetClassFields() throws IOException {
    Directory directory = FSDirectory.open(new File(appConfig.getOldAllIndexDir()));
    if (!IndexReader.indexExists(directory)) {
        logger.error("Please reset index firstly!");
        return;
    }
    Directory ram = new RAMDirectory(directory);
    IndexReader preIndexReader = this.indexReader;
    this.indexReader = IndexReader.open(ram);
    logger.info("IndexReader has numDos: {}", this.indexReader.numDocs());

    IndexSearcher preIndexSearcher = this.indexSearcher;
    this.indexSearcher = new IndexSearcher(indexReader);
    IOUtils.closeQuietly(preIndexSearcher, preIndexReader);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:17,代码来源:SearchServiceImpl.java

示例7: searchIndex

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
/**
 * 查询索引
 * 
 * @param keywords
 * @return
 * @throws Exception
 */
public List<Document> searchIndex(Integer typeId, String keywords) throws Exception {
    // 1.init searcher
    Analyzer analyzer = new PaodingAnalyzer();
    IndexReader reader = IndexReader.open(typeId == appConfig.getGameTypeId() ? appConfig.getGameIndexDir()
            : appConfig.getSoftIndexDir());
    BooleanClause.Occur[] flags = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD,
            BooleanClause.Occur.SHOULD };
    Query query = MultiFieldQueryParser.parse(keywords, appConfig.getQueryFields(), flags, analyzer);
    query = query.rewrite(reader);

    // 2.search
    List<Document> docs = new ArrayList<Document>();
    Hits hits = (typeId == appConfig.getGameTypeId() ? gameSearcher.search(query, Sort.RELEVANCE) : softSearcher
            .search(query, Sort.RELEVANCE));// searcher.search(query,
                                            // Sort.RELEVANCE);
    for (int i = 0; i < hits.length(); i++) {
        docs.add(hits.doc(i));
    }

    // 3.return
    reader.close();
    return docs;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:31,代码来源:SearchServiceImpl.java

示例8: run

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private void run() throws IOException {
    IndexSearcher indexSearcher = new IndexSearcher(IndexReader.open(FSDirectory.open(new File(indexPath))));
    List<FieldList> fields = new ArrayList<>();
    Map<String, FieldList> fieldMap = new HashMap<>();
    for (int i = 0; i < indexSearcher.maxDoc(); i++) {
        Document document = indexSearcher.doc(i);
        String key = document.get(keyField);
        if (key.isEmpty()) {
            continue;
        }
        String value = document.get(valueField);
        int freq = Integer.parseInt(document.get(freqField));
        FieldList list = fieldMap.get(key);
        if (list == null) {
            list = new FieldList(key);
            fieldMap.put(key, list);
            fields.add(list);
        }
        list.add(value, freq);
    }
    try (PrintWriter writer = new PrintWriter(outputPath)) {
        fields.stream().sorted().limit(maxEntries).forEach(list -> writer.println(list.toString()));
    }
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:25,代码来源:LuceneIndexReader.java

示例9: getReader

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
@CheckForNull
private synchronized IndexReader getReader() throws IOException {
    if (cachedReader == null) {
        try {
            cachedReader = IndexReader.open(getDirectory(),true);
        } catch (FileNotFoundException fnf) {
            //pass - returns null
        }
    }
    return cachedReader;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:MemoryIndex.java

示例10: search

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private void search() throws IOException {		
	Directory dir = FSDirectory.open(indexDir);
	try (IndexReader indexReader = IndexReader.open(dir)) {
		try (IndexSearcher indexSearcher = new IndexSearcher(indexReader)) {
			TopDocs topDocs = indexSearcher.search(query, Integer.MAX_VALUE);
			PubMedIndexUtils.log("found %d hits", topDocs.totalHits);
			output(indexReader, topDocs);
			PubMedIndexUtils.log("done");
		}
	}
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:12,代码来源:PubMedIndexSearcher.java

示例11: resetQuickTips

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private void resetQuickTips() throws IOException {
    String indexDir = appConfig.getOldAllQuickTipsIndex();
    Directory directory = FSDirectory.open(new File(indexDir));
    if (!IndexReader.indexExists(directory)) {
        logger.info("Please reset index firstly!");
        return;
    }
    Directory ram = new RAMDirectory(directory);
    this.quickTipsIndexReader = IndexReader.open(ram);
    logger.info("IndexReader has numDos: {}", this.quickTipsIndexReader.numDocs());

    IndexSearcher preIndexSearcher = this.quickTipsSearcher;
    this.quickTipsSearcher = new IndexSearcher(quickTipsIndexReader);
    IOUtils.closeQuietly(preIndexSearcher);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:16,代码来源:QuickTipsServiceImpl.java

示例12: initialize

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private void initialize(File indexDir) {
    try {
        Stopwatch stopwatch = Stopwatch.createStarted();
        indexSearcher = new IndexSearcher(IndexReader.open(FSDirectory.open(indexDir)));
        analyzer = new StandardAnalyzer(Version.LUCENE_36);
        log.info("Initialized lucene index at {} ({})", indexDir.getPath(), stopwatch.stop());
    } catch (IOException e) {
        throw new RuntimeException("Unable to locate Lucene index.", e);
    }
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:11,代码来源:LuceneWrapper.java

示例13: createIndexReader

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private IndexReader createIndexReader(IndexType indexType) throws IOException {
    File dir = getIndexDirectory(indexType);
    return IndexReader.open(FSDirectory.open(dir), true);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:5,代码来源:SearchService.java

示例14: PubmedIndexProperties

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
public PubmedIndexProperties(IndexWriter indexWriter) throws CorruptIndexException, IOException {
	this(IndexReader.open(indexWriter, true));
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:4,代码来源:PubmedIndexProperties.java

示例15: reopenIndexSearcher

import org.apache.lucene.index.IndexReader; //导入方法依赖的package包/类
private void reopenIndexSearcher(Directory ram) throws CorruptIndexException, IOException {
    this.indexReader = IndexReader.open(ram);
    this.indexSearcher = new IndexSearcher(this.indexReader);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:5,代码来源:QuickTipsService1Impl.java


注:本文中的org.apache.lucene.index.IndexReader.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。