Package org.apache.lucene.util

Examples of org.apache.lucene.util.PriorityQueue


    return list;
  }

  private PriorityQueue createPQ(final int max, final Comparator<BrowseFacet> comparator)
  {
    PriorityQueue queue = new PriorityQueue()
    {
      {
        this.initialize(max);
      }
      @Override
View Full Code Here


    private final PriorityQueue _queue;

    public MergedIterator(final List<Iterator<T>> sources, final Comparator<T> comparator)
    {
      _queue = new PriorityQueue()
      {
        {
          this.initialize(sources.size());
        }
     
View Full Code Here

   * @see #retrieveTerms(java.io.Reader)
   * @see #setMaxQueryTerms
   */
  public String[] retrieveInterestingTerms( Reader r) throws IOException {
    ArrayList al = new ArrayList( maxQueryTerms);
    PriorityQueue pq = retrieveTerms( r);
    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 (String[]) al.toArray( res);
View Full Code Here

     * @see #retrieveTerms(java.io.Reader)
     * @see #setMaxQueryTerms
     */
    public String[] retrieveInterestingTerms( Reader r) throws IOException {
        ArrayList al = new ArrayList( maxQueryTerms);
        PriorityQueue pq = retrieveTerms( r);
        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
        for (Object cur = pq.pop(); cur != null && lim-- > 0; cur = pq.pop()) {
            Object[] ar = (Object[]) cur;
            al.add(ar[0]); // the 1st entry is the interesting word
        }
        return (String[]) al.toArray(new String[al.size()]);
    }
View Full Code Here

      };      
      if(maxCnt != Integer.MAX_VALUE)
      {
        // we will maintain a min heap of size maxCnt
        // Order by hits in descending order and max count is supplied
        PriorityQueue queue = createPQ(maxCnt, comparator);
        int qsize = 0;
        while( (qsize < maxCnt) && ((facet = iter.next(minHits)) != null) )
        {
          queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
          qsize++;
        }
        if(facet != null)
        {
          BrowseFacet rootFacet = (BrowseFacet)queue.top();
          minHits = rootFacet.getHitCount() + 1;
          // facet count less than top of min heap, it will never be added
          while(((facet = iter.next(minHits)) != null))
          {
            rootFacet.setValue(String.valueOf(facet));
            rootFacet.setHitCount(iter.count);
            rootFacet = (BrowseFacet) queue.updateTop();
            minHits = rootFacet.getHitCount() + 1;
          }
        }
        // at this point, queue contains top maxCnt facets that have hitcount >= minHits
        while(qsize-- > 0)
        {
          // append each entry to the beginning of the facet list to order facets by hits descending
          list.addFirst((BrowseFacet) queue.pop());
        }
      }
      else
      {
        // no maxCnt specified. So fetch all facets according to minHits and sort them later
        while((facet = iter.next(minHits)) != null)
          list.add(new BrowseFacet(String.valueOf(facet), iter.count));
        Collections.sort(list, comparator);
      }
    }
    else // FacetSortSpec.OrderByCustom.equals(_fspec.getOrderBy()
    {
      comparator = _fspec.getCustomComparatorFactory().newComparator();
      if(maxCnt != Integer.MAX_VALUE)
      {
        PriorityQueue queue = createPQ(maxCnt, comparator);
        BrowseFacet browseFacet = new BrowseFacet();       
        int qsize = 0;
        while( (qsize < maxCnt) && ((facet = iter.next(minHits)) != null) )
        {
          queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
          qsize++;
        }
        if(facet != null)
        {
          while((facet = iter.next(minHits)) != null)
          {
            // check with the top of min heap
            browseFacet.setHitCount(iter.count);
            browseFacet.setValue(String.valueOf(facet));
            browseFacet = (BrowseFacet)queue.insertWithOverflow(browseFacet);
          }
        }
        // remove from queue and add to the list
        while(qsize-- > 0)
          list.addFirst((BrowseFacet)queue.pop());
      }
      else
      {
        // order by custom but no max count supplied
        while((facet = iter.next(minHits)) != null)
View Full Code Here

    return list;
  }

  private PriorityQueue createPQ(final int max, final Comparator<BrowseFacet> comparator)
  {
    PriorityQueue queue = new PriorityQueue()
    {
      {
        this.initialize(max);
      }
      @Override
View Full Code Here

    private final PriorityQueue _queue;

    private MergedIterator(final int length, final Comparator<T> comparator)
    {
      _queue = new PriorityQueue()
      {
        {
          this.initialize(length);
        }
     
View Full Code Here

    * @see #setMaxQueryTerms
    */
   public String[] retrieveInterestingTerms(Reader r) throws IOException
   {
      ArrayList al = new ArrayList(maxQueryTerms);
      PriorityQueue pq = retrieveTerms(r);
      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()];
View Full Code Here

   * @see #retrieveTerms(java.io.Reader)
   * @see #setMaxQueryTerms
   */
  public String[] retrieveInterestingTerms( Reader r) throws IOException {
    ArrayList al = new ArrayList( maxQueryTerms);
    PriorityQueue pq = retrieveTerms( r);
    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 (String[]) al.toArray( res);
View Full Code Here

            // nothing to highlight
            return createDefaultExcerpt(text, excerptStart, excerptEnd,
                    fragmentStart, fragmentEnd, surround * 2);
        }

        PriorityQueue bestFragments = new FragmentInfoPriorityQueue(maxFragments);
        for (int i = 0; i < offsets.length; i++) {
            if (offsets[i].getEndOffset() <= text.length()) {
                FragmentInfo fi = new FragmentInfo(offsets[i], surround * 2);
                for (int j = i + 1; j < offsets.length; j++) {
                    if (offsets[j].getEndOffset() > text.length()) {
                        break;
                    }
                    if (!fi.add(offsets[j], text)) {
                        break;
                    }
                }
                bestFragments.insert(fi);
            }
        }

        if (bestFragments.size() == 0) {
            return createDefaultExcerpt(text, excerptStart, excerptEnd,
                    fragmentStart, fragmentEnd, surround * 2);
        }

        // retrieve fragment infos from queue and fill into list, least
        // fragment comes out first
        List infos = new LinkedList();
        while (bestFragments.size() > 0) {
            FragmentInfo fi = (FragmentInfo) bestFragments.pop();
            infos.add(0, fi);
        }

        Map offsetInfos = new IdentityHashMap();
        // remove overlapping fragment infos
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.PriorityQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.