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


Java PriorityQueue.pop方法代码示例

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


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

示例1: addToQuery

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Add to an existing boolean query the More Like This query from this PriorityQueue
 */
private void addToQuery(PriorityQueue<ScoreTerm> q, BooleanQuery query) {
    ScoreTerm scoreTerm;
    float bestScore = -1;

    while ((scoreTerm = q.pop()) != null) {
        TermQuery tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));

        if (boost) {
            if (bestScore == -1) {
                bestScore = (scoreTerm.score);
            }
            float myScore = (scoreTerm.score);
            tq.setBoost(boostFactor * myScore / bestScore);
        }

        try {
            query.add(tq, BooleanClause.Occur.SHOULD);
        }
        catch (BooleanQuery.TooManyClauses ignore) {
            break;
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:XMoreLikeThis.java

示例2: createQuery

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Create the More like query from a PriorityQueue
 */
private Query createQuery(PriorityQueue<ScoreTerm> q) {
  BooleanQuery query = new BooleanQuery();
  ScoreTerm scoreTerm;
  float bestScore = -1;

  while ((scoreTerm = q.pop()) != null) {
    TermQuery tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));

    if (boost) {
      if (bestScore == -1) {
        bestScore = (scoreTerm.score);
      }
      float myScore = (scoreTerm.score);
      tq.setBoost(boostFactor * myScore / bestScore);
    }

    try {
      query.add(tq, BooleanClause.Occur.SHOULD);
    }
    catch (BooleanQuery.TooManyClauses ignore) {
      break;
    }
  }
  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:MoreLikeThis.java

示例3: buildDocHits

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/** Construct the array of doc hits for the hit group. */
private void buildDocHits(int group, ResultGroup resultGroup) 
{
  PriorityQueue queue = hitQueue[group];
  int nFound = queue.size();
  DocHitImpl[] hitArray = new DocHitImpl[nFound];
  for (int i = 0; i < nFound; i++) {
    int index = nFound - i - 1;
    hitArray[index] = (DocHitImpl)queue.pop();
  }

  int start = startDoc[group];
  int max = maxDocs[group];

  int nHits = Math.max(0, Math.min(nFound - start, max));
  resultGroup.docHits = new DocHit[nHits];

  resultGroup.totalDocs = nDocHits(group);
  resultGroup.startDoc = start;
  resultGroup.endDoc = start + nHits;

  for (int i = startDoc[group]; i < nFound; i++)
    resultGroup.docHits[i - start] = hitArray[i];
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:25,代码来源:GroupCounts.java

示例4: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException {
    ArrayList<Object> al = new ArrayList<>(maxQueryTerms);
    PriorityQueue<ScoreTerm> pq = retrieveTerms(docNum);
    ScoreTerm scoreTerm;
    int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
    // we just want to return the top words
    while (((scoreTerm = pq.pop()) != null) && lim-- > 0) {
        al.add(scoreTerm.word); // the 1st entry is the interesting word
    }
    String[] res = new String[al.size()];
    return al.toArray(res);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:XMoreLikeThis.java

示例5: getMostInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Compute the top most interesting terms from the priority queue of all RF Terms
 */
private List<RFTerm> getMostInterestingTerms(PriorityQueue<RFTerm> q) {

    int maxTerms = (maxQueryTermsPerField <= 0) ? Integer.MAX_VALUE : maxQueryTermsPerField;
    double sumQuaredBoost = 0.0f;

    List<RFTerm> interestingTerms = new ArrayList<RFTerm>();
    RFTerm currentTerm = null;
    while ((currentTerm = q.pop()) != null
            && interestingTerms.size() < maxTerms) {
        // if not boost, then set score to 1.0 not tf.idf
        // now implemented inside RFTerm

        // if not boost, boostValue == 1.0, so this just adds 1 as desired
        sumQuaredBoost += Math.pow(currentTerm.getTermWeight(),2);
        interestingTerms.add(currentTerm);
    }

    float vectorLength = (float) Math.sqrt(sumQuaredBoost);
    if(vectorLength <= 0.0){
        return new ArrayList<RFTerm>();
    }

    if(this.isNormalizeFieldBoosts()){
        for(RFTerm term: interestingTerms){
            term.setVectorLength(vectorLength);
        }
    }
    return interestingTerms;
}
 
开发者ID:DiceTechJobs,项目名称:RelevancyFeedback,代码行数:33,代码来源:RelevancyFeedback.java

示例6: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException
{
  ArrayList<Object> al = new ArrayList<>(maxQueryTerms);
  PriorityQueue<ScoreTerm> pq = retrieveTerms(docNum);
  ScoreTerm scoreTerm;
  int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not
                           // useful to our caller...
  // we just want to return the top words
  while (((scoreTerm = pq.pop()) != null) && lim-- > 0) {
    al.add(scoreTerm.word); // the 1st entry is the interesting word
  }
  String[] res = new String[al.size()];
  return al.toArray(res);
}
 
开发者ID:oeuvres,项目名称:Alix,代码行数:18,代码来源:MoreLikeThis.java

示例7: 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

示例8: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException {
  ArrayList<Object> al = new ArrayList<>(maxQueryTerms);
  PriorityQueue<ScoreTerm> pq = retrieveTerms(docNum);
  ScoreTerm scoreTerm;
  int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
  // we just want to return the top words
  while (((scoreTerm = pq.pop()) != null) && lim-- > 0) {
    al.add(scoreTerm.word); // the 1st entry is the interesting word
  }
  String[] res = new String[al.size()];
  return al.toArray(res);
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:MoreLikeThis.java

示例9: getMostInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Compute the top most interesting terms from the priority queue of all MLT Terms
 */
private List<MLTTerm> getMostInterestingTerms(PriorityQueue<MLTTerm> q) {

    int maxTerms = (maxQueryTermsPerField <= 0) ? Integer.MAX_VALUE : maxQueryTermsPerField;
    double sumQuaredBoost = 0.0f;

    List<MLTTerm> interestingTerms = new ArrayList<MLTTerm>();
    MLTTerm currentTerm = null;
    while ((currentTerm = q.pop()) != null
            && interestingTerms.size() < maxTerms) {
        // if not boost, then set score to 1.0 not tf.idf
        // now implemented inside MLTTerm

        // if not boost, boostValue == 1.0, so this just adds 1 as desired
        sumQuaredBoost += Math.pow(currentTerm.getTermWeight(),2);
        interestingTerms.add(currentTerm);
    }

    float vectorLength = (float) Math.sqrt(sumQuaredBoost);
    if(vectorLength <= 0.0){
        return new ArrayList<MLTTerm>();
    }

    if(this.isNormalizeFieldBoosts()){
        for(MLTTerm term: interestingTerms){
            term.setVectorLength(vectorLength);
        }
    }
    return interestingTerms;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:33,代码来源:MoreLikeThis.java

示例10: createQuery

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Create the More like query from a PriorityQueue
 */
private Query createQuery(PriorityQueue<Object[]> q) {
  BooleanQuery query = new BooleanQuery();
  Object cur;
  int qterms = 0;
  float bestScore = 0;

  while ((cur = q.pop()) != null) {
    Object[] ar = (Object[]) cur;
    TermQuery tq = new TermQuery(new Term((String) ar[1], (String) ar[0]));

    if (boost) {
      if (qterms == 0) {
        bestScore = ((Float) ar[2]);
      }
      float myScore = ((Float) ar[2]);

      tq.setBoost(boostFactor * myScore / bestScore);
    }

    try {
      query.add(tq, BooleanClause.Occur.SHOULD);
    }
    catch (BooleanQuery.TooManyClauses ignore) {
      break;
    }

    qterms++;
    if (maxQueryTerms > 0 && qterms >= maxQueryTerms) {
      break;
    }
  }

  return query;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:38,代码来源:MoreLikeThis.java

示例11: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException {
  ArrayList<Object> al = new ArrayList<Object>(maxQueryTerms);
  PriorityQueue<Object[]> pq = retrieveTerms(docNum);
  Object cur;
  int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
  // we just want to return the top words
  while (((cur = pq.pop()) != null) && lim-- > 0) {
    Object[] ar = (Object[]) cur;
    al.add(ar[0]); // the 1st entry is the interesting word
  }
  String[] res = new String[al.size()];
  return al.toArray(res);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:MoreLikeThis.java

示例12: 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

示例13: createQuery

import org.apache.lucene.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Create the More like query from a PriorityQueue
 */
private Query createQuery(IndexReader indexReader, PriorityQueue q)
  throws IOException 
{
  // Pop everything from the queue.
  QueryWord[] queryWords = new QueryWord[q.size()];
  for (int i = q.size() - 1; i >= 0; i--)
    queryWords[i] = (QueryWord)q.pop();

  BooleanQuery query = new BooleanQuery(true /*disable coord*/);

  // At the moment, there's no need to scale by the best score. It simply
  // clouds the query explanation. It doesn't affect the scores, since
  // Lucene applies a query normalization factor anyway.
  //
  //float bestScore = (queryWords.length > 0) ? queryWords[0].score : 0.0f;
  for (int i = 0; i < fieldNames.length; i++) 
  {
    ArrayList fieldClauses = new ArrayList();

    for (int j = 0; j < queryWords.length; j++) 
    {
      QueryWord qw = queryWords[j];
      Term term = new Term(fieldNames[i], qw.word);

      // Skip words not present in this field.
      int docFreq = indexReader.docFreq(term);
      if (docFreq == 0)
        continue;

      // Add it to the query.
      SpanTermQuery tq = new SpanTermQuery(term);
      if (boost)
        tq.setBoost(qw.score);
      fieldClauses.add(tq);
    } // for j

    // If no terms for this field, skip it.
    if (fieldClauses.isEmpty())
      continue;

    SpanQuery[] clauses = (SpanQuery[])fieldClauses.toArray(
      new SpanQuery[fieldClauses.size()]);

    // Now make a special Or-Near query out of the clauses.
    SpanOrNearQuery fieldQuery = new SpanOrNearQuery(clauses, 10, false);

    // Boost if necessary.
    if (fieldBoosts != null)
      fieldQuery.setBoost(fieldBoosts[i]);
    
    // We currently don't support more-like-this queries on the full text.
    // It would involve de-chunking, and also fancier logic to pick the
    // "most interesting" terms in the first place.
    //
    if (fieldNames[i].equals("text"))
      throw new RuntimeException("MoreLikeThisQuery does not support 'text' field.");

    // And add to the main query.
    query.add(fieldQuery, BooleanClause.Occur.SHOULD);
  } // for i

  // All done.
  return query;
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:68,代码来源:MoreLikeThisQuery.java


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