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


Java PriorityQueue.insertWithOverflow方法代码示例

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


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

示例1: bestTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
private String [] bestTerms(String field,int numTerms) throws IOException {
  PriorityQueue<TermDf> pq = new TermsDfQueue(numTerms);
  IndexReader ir = DirectoryReader.open(dir);
  try {
    int threshold = ir.maxDoc() / 10; // ignore words too common.
    Terms terms = MultiFields.getTerms(ir, field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      while (termsEnum.next() != null) {
        int df = termsEnum.docFreq();
        if (df<threshold) {
          String ttxt = termsEnum.term().utf8ToString();
          pq.insertWithOverflow(new TermDf(ttxt,df));
        }
      }
    }
  } finally {
    ir.close();
  }
  String res[] = new String[pq.size()];
  int i = 0;
  while (pq.size()>0) {
    TermDf tdf = pq.pop(); 
    res[i++] = tdf.word;
    System.out.println(i+".   word:  "+tdf.df+"   "+tdf.word);
  }
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:QualityQueriesFinder.java

示例2: mergePartitions

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/** Merge a list of sorted temporary files (partitions) into an output file */
void mergePartitions(List<File> merges, File outputFile) throws IOException {
  long start = System.currentTimeMillis();

  ByteSequencesWriter out = new ByteSequencesWriter(outputFile);

  PriorityQueue<FileAndTop> queue = new PriorityQueue<FileAndTop>(merges.size()) {
    @Override
    protected boolean lessThan(FileAndTop a, FileAndTop b) {
      return comparator.compare(a.current, b.current) < 0;
    }
  };

  ByteSequencesReader [] streams = new ByteSequencesReader [merges.size()];
  try {
    // Open streams and read the top for each file
    for (int i = 0; i < merges.size(); i++) {
      streams[i] = new ByteSequencesReader(merges.get(i));
      byte line[] = streams[i].read();
      if (line != null) {
        queue.insertWithOverflow(new FileAndTop(i, line));
      }
    }

    // Unix utility sort() uses ordered array of files to pick the next line from, updating
    // it as it reads new lines. The PQ used here is a more elegant solution and has 
    // a nicer theoretical complexity bound :) The entire sorting process is I/O bound anyway
    // so it shouldn't make much of a difference (didn't check).
    FileAndTop top;
    while ((top = queue.top()) != null) {
      out.write(top.current);
      if (!streams[top.fd].read(top.current)) {
        queue.pop();
      } else {
        queue.updateTop();
      }
    }

    sortInfo.mergeTime += System.currentTimeMillis() - start;
    sortInfo.mergeRounds++;
  } finally {
    // The logic below is: if an exception occurs in closing out, it has a priority over exceptions
    // happening in closing streams.
    try {
      IOUtils.close(streams);
    } finally {
      IOUtils.close(out);
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:51,代码来源:Sort.java


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