Package com.browseengine.bobo.sort.SortCollector

Examples of com.browseengine.bobo.sort.SortCollector.CollectorContext


        {
          SortCollector sortCollector = res.getSortCollector();
          if (sortCollector == null) continue;
          int end = (res.getNumHits() % SortCollector.BLOCK_SIZE) - 1;
          Iterator<CollectorContext> contextIter = sortCollector.contextList.descendingIterator();
          CollectorContext currentContext = null;
          int contextLeft = 0;
          FacetDataCache[] dataCaches = new FacetDataCache[sortCollector.groupByMulti.length];
          FacetDataCache[] distinctDataCaches = new FacetDataCache[distinctLength];
          while (contextIter.hasNext()) {
            currentContext = contextIter.next();
            currentContext.restoreRuntimeFacets();
            contextLeft = currentContext.length;
            if (contextLeft > 0)
            {
              for (j=0; j<sortCollector.groupByMulti.length; ++j)
              {
                dataCaches[j] = (FacetDataCache)sortCollector.groupByMulti[j].getFacetData(currentContext.reader);
              }
              for (j=0; j<distinctLength; ++j)
              {
                distinctDataCaches[j] = (FacetDataCache)currentContext.
                    reader.
                    getFacetHandler(req.getDistinct()[j]).
                    getFacetData(currentContext.reader);
              }
              break;
            }
          }

          Iterator<float[]> scoreArrayIter = sortCollector.scorearraylist != null ? sortCollector.scorearraylist.descendingIterator():null;
          if (contextLeft > 0)
          {
            Iterator<int[]> docArrayIter = sortCollector.docidarraylist.descendingIterator();
            while (docArrayIter.hasNext())
            {
              int[] docs = docArrayIter.next();
              float[] scores = scoreArrayIter != null ? scoreArrayIter.next():null;
              for (i = end; i >= 0; --i)
              {
                doc = docs[i];
                score = scores != null ? scores[i]:0.0f;
                for (j=0; j<sortCollector.groupByMulti.length; ++j)
                {
                  rawGroupValue = extractRawGroupValue(rawGroupValueType, j, primitiveLongArrayWrapperTmp,
                      dataCaches[j].valArray.getRawValue(dataCaches[j].orderArray.get(doc)));

                  hitWithGroupQueue = groupMaps[j].get(rawGroupValue);
                  if (hitWithGroupQueue != null)
                  {
                    hitWithGroupQueue.hit.setGroupHitsCount(hitWithGroupQueue.hit.getGroupHitsCount() + 1);
                    if (hitWithGroupQueue.queue == null) break;
                    // Collect this hit.
                    if (tmpScoreDoc == null)
                      tmpScoreDoc = new MyScoreDoc(doc, score, currentContext.base + totalDocs + doc, currentContext.reader);
                    else
                    {
                      tmpScoreDoc.doc = doc;
                      tmpScoreDoc.score = score;
                      tmpScoreDoc.finalDoc = currentContext.base + totalDocs + doc;
                      tmpScoreDoc.reader = currentContext.reader;
                    }
                    tmpScoreDoc.sortValue = currentContext.comparator.value(tmpScoreDoc);
                    tmpScoreDoc.groupPos = j;
                    if (distinctLength > 0)
                    {
                      tmpScoreDoc.distinctValues = new Object[distinctLength];
                    }

                    if (hitWithGroupQueue.queue.size < maxPerGroup ||
                        tmpScoreDoc.sortValue.compareTo(((MyScoreDoc)hitWithGroupQueue.queue.top()).sortValue) < 0)
                    {
                      pre = null;
                      for (k = 0; k < distinctLength; ++k)
                      {
                        tmpScoreDoc.distinctValues[k] = extractRawGroupValue(distinctValueType,
                            k,
                            distinctPrimitiveLongArrayWrapperTmp,
                            distinctDataCaches[k].valArray.getRawValue(
                                distinctDataCaches[k].orderArray.get(doc)
                            ));
                        if (pre == null)
                          pre = hitWithGroupQueue.distinctMap[k].get(tmpScoreDoc.distinctValues[k]);
                      }
                      if (pre != null)
                      {
                        if (tmpScoreDoc.sortValue.compareTo(pre.sortValue) < 0)
                        {
                          hitWithGroupQueue.queue.replace(tmpScoreDoc, pre);
                          for (k = 0; k < distinctLength; ++k)
                          {
                            hitWithGroupQueue.distinctMap[k].remove(pre.distinctValues[k]);
                            hitWithGroupQueue.distinctMap[k].put(tmpScoreDoc.distinctValues[k], tmpScoreDoc);
                          }
                          tmpScoreDoc = pre;
                        }
                      }
                      else
                      {
                        if (hitWithGroupQueue.queue.size >= maxPerGroup) // queue full
                        {
                          pre = (MyScoreDoc)hitWithGroupQueue.queue.top();
                          hitWithGroupQueue.queue.replace(tmpScoreDoc);
                          for (k = 0; k < distinctLength; ++k)
                          {
                            hitWithGroupQueue.distinctMap[k].remove(pre.distinctValues[k]);
                            hitWithGroupQueue.distinctMap[k].put(tmpScoreDoc.distinctValues[k], tmpScoreDoc);
                          }
                          tmpScoreDoc = pre;
                        }
                        else
                        {
                          hitWithGroupQueue.queue.add(tmpScoreDoc);
                          for (k = 0; k < distinctLength; ++k)
                          {
                            hitWithGroupQueue.distinctMap[k].put(tmpScoreDoc.distinctValues[k], tmpScoreDoc);
                          }
                          tmpScoreDoc = null;
                        }
                      }
                    }
                    break;
                  }
                }
                --contextLeft;
                if (contextLeft <= 0)
                {
                  while (contextIter.hasNext()) {
                    currentContext = contextIter.next();
                    currentContext.restoreRuntimeFacets();
                    contextLeft = currentContext.length;
                    if (contextLeft > 0)
                    {
                      for (j=0; j<sortCollector.groupByMulti.length; ++j)
                      {
View Full Code Here


      int end = (res.getNumHits() % SortCollector.BLOCK_SIZE) - 1;

      Iterator<CollectorContext> contextIter = sortCollector.contextList.descendingIterator();

      // Populate dataCaches and contextLeft
      CollectorContext currentContext = null;
      int contextLeft = 0;
      FacetDataCache[] dataCaches = new FacetDataCache[sortCollector.groupByMulti.length];
      while (contextIter.hasNext()) {
        currentContext = contextIter.next();
        currentContext.restoreRuntimeFacets();
        contextLeft = currentContext.length;
        if (contextLeft > 0)
        {
          for (int j=0; j<sortCollector.groupByMulti.length; ++j)
            dataCaches[j] = (FacetDataCache)sortCollector.groupByMulti[j].getFacetData(currentContext.reader);
          break;
        }
      }

      Iterator<float[]> scoreArrayIter = sortCollector.scorearraylist != null ? sortCollector.scorearraylist.descendingIterator():null;

      if (contextLeft > 0)
      {
        Iterator<int[]> docArrayIter = sortCollector.docidarraylist.descendingIterator();
        while (docArrayIter.hasNext())
        {
          int[] docs = docArrayIter.next();
          float[] scores = scoreArrayIter != null ? scoreArrayIter.next():null;

          for (int i = end; i >= 0; --i)
          {
            tmpScoreDoc.doc = docs[i];
            tmpScoreDoc.score = scores != null ? scores[i] : 0.0f;
            tmpScoreDoc.finalDoc = currentContext.base + totalDocs + tmpScoreDoc.doc;
            tmpScoreDoc.reader = currentContext.reader;
            tmpScoreDoc.sortValue = currentContext.comparator.value(tmpScoreDoc);

            int j=0;

            if (!queueFull || tmpScoreDoc.sortValue.compareTo(bottom.sortValue) < 0)
            {
              for (;; ++j)
              {
                rawGroupValue = dataCaches[j].valArray.getRawValue(dataCaches[j].orderArray.get(tmpScoreDoc.doc));

                rawGroupValue = extractRawGroupValue(rawGroupValueType, j,
                    primitiveLongArrayWrapperTmp, rawGroupValue);

                pre = valueDocMaps[j].get(rawGroupValue);
                if (pre != null)
                {
                  j = -1;
                  break;
                }

                if (j >= combinedFacetAccessibles.length) break;

                if (rawGroupValueType[j] == LONG_ARRAY_GROUP_VALUE_TYPE)
                {
                  if (combinedFacetAccessibles[j].getCappedFacetCount(primitiveLongArrayWrapperTmp.data, 2) != 1)
                    break;
                }
                else
                {
                  if (combinedFacetAccessibles[j].getCappedFacetCount(rawGroupValue, 2) != 1)
                    break;
                }
              }
              if (j < 0)
              {
                if (tmpScoreDoc.sortValue.compareTo(pre.sortValue) < 0)
                {
                  tmpScoreDoc.groupPos = pre.groupPos;
                  tmpScoreDoc.rawGroupValue = pre.rawGroupValue;

                  // Pre has a higher score. Pop it in the queue!
                  bottom = (MyScoreDoc)docQueue.replace(tmpScoreDoc, pre);
                  valueDocMaps[tmpScoreDoc.groupPos].put(tmpScoreDoc.rawGroupValue, tmpScoreDoc);
                  tmpScoreDoc = pre;
                }
              }
              else
              {
                if (queueFull)
                {
                  tmpScoreDoc.groupPos = j;
                  tmpScoreDoc.rawGroupValue = rawGroupValue;
                  MyScoreDoc tmp = bottom;

                  valueDocMaps[tmp.groupPos].remove(tmp.rawGroupValue);

                  bottom = (MyScoreDoc)docQueue.replace(tmpScoreDoc);
                  valueDocMaps[j].put(rawGroupValue, tmpScoreDoc);
                  tmpScoreDoc = tmp;
                  if (rawGroupValueType[tmpScoreDoc.groupPos] == LONG_ARRAY_GROUP_VALUE_TYPE)
                  {
                    primitiveLongArrayWrapperTmp = (PrimitiveLongArrayWrapper)tmpScoreDoc.rawGroupValue;
                  }
                  else
                  {
                    primitiveLongArrayWrapperTmp = new PrimitiveLongArrayWrapper(null);
                  }
                }
                else
                {
                  MyScoreDoc tmp = new MyScoreDoc(tmpScoreDoc.doc, tmpScoreDoc.score, currentContext.base + totalDocs + tmpScoreDoc.doc, currentContext.reader);
                  tmp.groupPos = j;
                  tmp.rawGroupValue = rawGroupValue;
                  tmp.sortValue = tmpScoreDoc.sortValue;
                  bottom = (MyScoreDoc)docQueue.add(tmp);
                  valueDocMaps[j].put(rawGroupValue, tmp);
                  queueFull = (docQueue.size >= topHits);
                  if (rawGroupValueType[j] == LONG_ARRAY_GROUP_VALUE_TYPE)
                  {
                    primitiveLongArrayWrapperTmp = new PrimitiveLongArrayWrapper(null);
                  }
                }
              }
            }

            --contextLeft;
            if (contextLeft <= 0)
            {
              while (contextIter.hasNext())
              {
                currentContext = contextIter.next();
                currentContext.restoreRuntimeFacets();
                contextLeft = currentContext.length;
                if (contextLeft > 0)
                {
                  for (j=0; j<sortCollector.groupByMulti.length; ++j)
                    dataCaches[j] = (FacetDataCache)sortCollector.groupByMulti[j].getFacetData(currentContext.reader);
View Full Code Here

TOP

Related Classes of com.browseengine.bobo.sort.SortCollector.CollectorContext

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.