Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.FacetSpec


    FilteredRangeFacetHandler handler = new FilteredRangeFacetHandler("filtered_date", "date",
        Arrays.asList(ranges));
    browser.setFacetHandler(handler);

    BrowseRequest req = new BrowseRequest();
    req.setFacetSpec("filtered_date", new FacetSpec());
    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put(
      "filtered_date",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("[2001/01/01 TO 2001/12/30]", 1),
          new BrowseFacet("[2007/01/01 TO 2007/12/30]", 1) }));
View Full Code Here


    doTest(browser, req, 7, answer, null);
  }

  public void testCustomFacetSort() throws Exception {
    BrowseRequest req = new BrowseRequest();
    FacetSpec numberSpec = new FacetSpec();
    numberSpec.setCustomComparatorFactory(new ComparatorFactory() {

      @Override
      public IntComparator newComparator(final FieldValueAccessor fieldValueAccessor,
          final BigSegmentedArray counts) {

        return new IntComparator() {

          @Override
          public int compare(Integer v1, Integer v2) {
            Integer size1 = (Integer) fieldValueAccessor.getRawValue(v1);
            Integer size2 = (Integer) fieldValueAccessor.getRawValue(v2);

            int val = size1 - size2;
            if (val == 0) {
              val = counts.get(v1) - counts.get(v2);
            }
            return val;
          }

          @Override
          public int compare(int v1, int v2) {
            int size1 = (Integer) fieldValueAccessor.getRawValue(v1);
            int size2 = (Integer) fieldValueAccessor.getRawValue(v2);

            int val = size1 - size2;
            if (val == 0) {
              val = counts.get(v1) - counts.get(v2);
            }
            return val;
          }
        };
      }

      @Override
      public Comparator<BrowseFacet> newComparator() {
        return new Comparator<BrowseFacet>() {
          @Override
          public int compare(BrowseFacet o1, BrowseFacet o2) {
            int v1 = Integer.parseInt(o1.getValue());
            int v2 = Integer.parseInt(o2.getValue());
            int val = v2 - v1;
            if (val == 0) {
              val = o2.getFacetValueHitCount() - o1.getFacetValueHitCount();
            }
            return val;
          }
        };
      }
    });
    numberSpec.setOrderBy(FacetSortSpec.OrderByCustom);
    numberSpec.setMaxCount(3);
    req.setFacetSpec("number", numberSpec);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put(
      "number",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("2130", 1), new BrowseFacet("1013", 1),
          new BrowseFacet("0913", 1) }));

    doTest(req, 7, answer, null);

    numberSpec.setOrderBy(FacetSortSpec.OrderValueAsc);
    answer.put(
      "number",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("0005", 1), new BrowseFacet("0010", 1),
          new BrowseFacet("0011", 1) }));
View Full Code Here

    doTest(req, 7, answer, null);
  }

  public void testSimpleGroupbyFacetHandler() throws Exception {
    BrowseRequest req = new BrowseRequest();
    FacetSpec fspec = new FacetSpec();
    req.setFacetSpec("groupby", fspec);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put(
      "groupby",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("red,rectangle,0011", 1),
          new BrowseFacet("red,square,0005", 1), new BrowseFacet("red,square,0010", 1) }));

    BrowseSelection sel = new BrowseSelection("groupby");
    sel.addValue("red");
    req.addSelection(sel);

    doTest(req, 3, answer, null);

    sel.setValues(new String[] { "red,square" });
    answer.put(
      "groupby",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("red,square,0005", 1),
          new BrowseFacet("red,square,0010", 1) }));

    doTest(req, 2, answer, null);

    sel.setValues(new String[] { "red,square,0005" });
    answer.put("groupby",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("red,square,0005", 1) }));

    doTest(req, 1, answer, null);

    req.removeSelection("groupby");
    fspec.setMaxCount(2);
    answer.put(
      "groupby",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("blue,circle,0913", 1),
          new BrowseFacet("blue,square,1013", 1) }));
View Full Code Here

        Object rawGroupValue = null;

        if (_facetAccessibleLists != null) {
          _groupAccessibles = new CombinedFacetAccessible[_facetAccessibleLists.length];
          for (int i = 0; i < _facetAccessibleLists.length; ++i)
            _groupAccessibles[i] = new CombinedFacetAccessible(new FacetSpec(),
                _facetAccessibleLists[i]);
        }
        resList = new ArrayList<MyScoreDoc>(_count);
        Iterator<MyScoreDoc> mergedIter = ListMerger.mergeLists(iterList, MERGE_COMPATATOR);
        Set<Object> groupSet = new HashSet<Object>(_offset + _count);
View Full Code Here

    }

    Map<String, FacetAccessible> mergedFacetMap = new HashMap<String, FacetAccessible>();
    for(String facet : counts.keySet())
    {
      FacetSpec fs = req.getFacetSpec(facet);
     
      FacetSpec.FacetSortSpec sortSpec = fs.getOrderBy();
     
      Comparator<BrowseFacet> comparator;
      if (FacetSortSpec.OrderValueAsc.equals(sortSpec))
        comparator = FACET_VAL_COMPARATOR;
      else if (FacetSortSpec.OrderHitsDesc.equals(sortSpec))
        comparator = FacetHitcountComparatorFactory.FACET_HITS_COMPARATOR;
      else comparator = fs.getCustomComparatorFactory().newComparator();
     
      Map<String,BrowseFacet> facetValueCounts = counts.get(facet);
      BrowseFacet[] facetArray = facetValueCounts.values().toArray(new BrowseFacet[facetValueCounts.size()]);
      Arrays.sort(facetArray, comparator);
     
      int numToShow = facetArray.length;
      if (req != null)
      {
        FacetSpec fspec = req.getFacetSpec(facet);
        if (fspec != null)
        {
          int maxCount = fspec.getMaxCount();
          if(maxCount>0)
          {
            numToShow = Math.min(maxCount,numToShow);
          }
        }
View Full Code Here

          //_facetCountCollector = null;
        //}
        if (_facetAccessibleLists != null) {
          _groupAccessibles = new CombinedFacetAccessible[_facetAccessibleLists.length];
          for (int i=0; i<_facetAccessibleLists.length; ++i)
            _groupAccessibles[i] = new CombinedFacetAccessible(new FacetSpec(), _facetAccessibleLists[i]);
        }
        resList = new ArrayList<MyScoreDoc>(_count);
        Iterator<MyScoreDoc> mergedIter = ListMerger.mergeLists(iterList, MERGE_COMPATATOR);
        Set<Object> groupSet = new HashSet<Object>(_offset+_count);
        int offsetLeft = _offset;
View Full Code Here

    _req.removeSelection(name);
    return this;
  }
 
  public BrowseRequestBuilder applyFacetSpec(String name, int minHitCount, int maxCount, boolean expand, FacetSortSpec orderBy){
    FacetSpec fspec = new FacetSpec();
    fspec.setMinHitCount(minHitCount);
    fspec.setMaxCount(maxCount);
    fspec.setExpandSelection(expand);
    fspec.setOrderBy(orderBy);
    _req.setFacetSpec(name, fspec);
    return this;
  }
View Full Code Here

   
   
    BrowseRequest req = new BrowseRequest();
    req.setQuery(query);
   
    FacetSpec fspec = new FacetSpec();
    fspec.setExpandSelection(true);
    fspec.setMaxCount(5);
    fspec.setOrderBy(FacetSortSpec.OrderHitsDesc);
   
    req.setFacetSpec("ccid", fspec);
    req.setFacetSpec("pcid", fspec);
    req.setFacetSpec("education_id", fspec);
    req.setFacetSpec("geo_region", fspec);
View Full Code Here

        if (_facetCountCollector != null)
        {
          collectTotalGroups();
          _facetCountCollector = null;
        }
        _groupAccessible = new CombinedFacetAccessible(new FacetSpec(), _facetAccessibles);
        resList = new ArrayList<MyScoreDoc>(_count);
        Iterator<MyScoreDoc> mergedIter = ListMerger.mergeLists(iterList, MERGE_COMPATATOR);
        Set<Object> groupSet = new HashSet<Object>(_offset+_count);
        int offsetLeft = _offset;
        while(mergedIter.hasNext())
View Full Code Here

    }

    Map<String, FacetAccessible> mergedFacetMap = new HashMap<String, FacetAccessible>();
    for(String facet : counts.keySet())
    {
      FacetSpec fs = req.getFacetSpec(facet);
     
      FacetSpec.FacetSortSpec sortSpec = fs.getOrderBy();
     
      Comparator<BrowseFacet> comparator;
      if (FacetSortSpec.OrderValueAsc.equals(sortSpec))
        comparator = FACET_VAL_COMPARATOR;
      else if (FacetSortSpec.OrderHitsDesc.equals(sortSpec))
        comparator = FacetHitcountComparatorFactory.FACET_HITS_COMPARATOR;
      else comparator = fs.getCustomComparatorFactory().newComparator();
     
      Map<String,BrowseFacet> facetValueCounts = counts.get(facet);
      BrowseFacet[] facetArray = facetValueCounts.values().toArray(new BrowseFacet[facetValueCounts.size()]);
      Arrays.sort(facetArray, comparator);
     
      int numToShow = facetArray.length;
      if (req != null)
      {
        FacetSpec fspec = req.getFacetSpec(facet);
        if (fspec != null)
        {
          int maxCount = fspec.getMaxCount();
          if(maxCount>0)
          {
            numToShow = Math.min(maxCount,numToShow);
          }
        }
View Full Code Here

TOP

Related Classes of com.browseengine.bobo.api.FacetSpec

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.