Exemplo n.º 1
0
 private static DocComparatorSource getComparatorSource(Browsable browser, SortField sf) {
   DocComparatorSource compSource = null;
   if (SortField.FIELD_DOC.equals(sf)) {
     compSource = new DocIdDocComparatorSource();
   } else if (SortField.FIELD_SCORE.equals(sf) || sf.getType() == SortField.SCORE) {
     // we want to do reverse sorting regardless for relevance
     compSource = new ReverseDocComparatorSource(new RelevanceDocComparatorSource());
   } else if (sf instanceof BoboCustomSortField) {
     BoboCustomSortField custField = (BoboCustomSortField) sf;
     DocComparatorSource src = custField.getCustomComparatorSource();
     assert src != null;
     compSource = src;
   } else {
     Set<String> facetNames = browser.getFacetNames();
     String sortName = sf.getField();
     if (facetNames.contains(sortName)) {
       FacetHandler<?> handler = browser.getFacetHandler(sortName);
       assert handler != null;
       compSource = handler.getDocComparatorSource();
     } else { // default lucene field
       logger.info("doing default lucene sort for: " + sf);
       compSource = getNonFacetComparatorSource(sf);
     }
   }
   boolean reverse = sf.getReverse();
   if (reverse) {
     compSource = new ReverseDocComparatorSource(compSource);
   }
   compSource.setReverse(reverse);
   return compSource;
 }
Exemplo n.º 2
0
 public FacetHandler<?> getFacet(String name) {
   for (Object handlerObject : resolveBeansByListKey(FACET_CONF_PREFIX, Object.class)) {
     if (!(handlerObject instanceof FacetHandler)) {
       continue;
     }
     FacetHandler<?> handler = (FacetHandler<?>) handlerObject;
     if (handler.getName().equals(name)) {
       return handler;
     }
   }
   return null;
 }
Exemplo n.º 3
0
 private static SortField convert(Browsable browser, SortField sort) {
   String field = sort.getField();
   FacetHandler<?> facetHandler = browser.getFacetHandler(field);
   if (facetHandler != null) {
     browser.getFacetHandler(field);
     BoboCustomSortField sortField =
         new BoboCustomSortField(field, sort.getReverse(), facetHandler.getDocComparatorSource());
     return sortField;
   } else {
     return sort;
   }
 }
Exemplo n.º 4
0
 @Override
 public String[] getFieldValues(BoboIndexReader reader, int id) {
   ArrayList<String> valList = new ArrayList<String>();
   for (FacetHandler<?> handler : _facetHandlers) {
     StringBuffer buf = new StringBuffer();
     boolean firsttime = true;
     String[] vals = handler.getFieldValues(reader, id);
     if (vals != null && vals.length > 0) {
       if (!firsttime) {
         buf.append(",");
       } else {
         firsttime = false;
       }
       for (String val : vals) {
         buf.append(val);
       }
     }
     valList.add(buf.toString());
   }
   return valList.toArray(new String[valList.size()]);
 }
Exemplo n.º 5
0
  @Override
  public RandomAccessDocIdSet getRandomAccessDocIdSet(BoboIndexReader reader) throws IOException {
    final MultiValueFacetDataCache dataCache =
        (MultiValueFacetDataCache) _facetHandler.getFacetData(reader);
    final int[] index = _valueConverter.convert(dataCache, _vals);
    final BigNestedIntArray nestedArray = dataCache._nestedArray;
    final OpenBitSet bitset = new OpenBitSet(dataCache.valArray.size());

    for (int i : index) {
      bitset.fastSet(i);
    }

    if (_takeCompliment) {
      // flip the bits
      int size = dataCache.valArray.size();
      for (int i = 0; i < size; ++i) {
        bitset.fastFlip(i);
      }
    }

    long count = bitset.cardinality();

    if (count == 0) {
      final DocIdSet empty = EmptyDocIdSet.getInstance();
      return new RandomAccessDocIdSet() {
        @Override
        public boolean get(int docId) {
          return false;
        }

        @Override
        public DocIdSetIterator iterator() throws IOException {
          return empty.iterator();
        }
      };
    } else {
      return new RandomAccessDocIdSet() {
        @Override
        public DocIdSetIterator iterator() {
          return new MultiValueOrFacetDocIdSetIterator(dataCache, bitset);
        }

        @Override
        public final boolean get(int docId) {
          return nestedArray.contains(docId, bitset);
        }
      };
    }
  }
Exemplo n.º 6
0
 public double getFacetSelectivity(BoboIndexReader reader) {
   double selectivity = 0;
   MultiValueFacetDataCache dataCache =
       (MultiValueFacetDataCache) _facetHandler.getFacetData(reader);
   int[] idxes = _valueConverter.convert(dataCache, _vals);
   if (idxes == null) {
     return 0.0;
   }
   int accumFreq = 0;
   for (int idx : idxes) {
     accumFreq += dataCache.freqs[idx];
   }
   int total = reader.maxDoc();
   selectivity = (double) accumFreq / (double) total;
   if (selectivity > 0.999) {
     selectivity = 1.0;
   }
   return selectivity;
 }