當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。