Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseFacet


    output.setMaxCount(100);
    output.setMinHitCount(1);
    br.setFacetSpec("numberhisto", output);

    BrowseFacet[] answerBucketFacets = new BrowseFacet[5];
    answerBucketFacets[0] = new BrowseFacet("0000000000", 3);
    answerBucketFacets[1] = new BrowseFacet("0000000002", 1);
    answerBucketFacets[2] = new BrowseFacet("0000000009", 1);
    answerBucketFacets[3] = new BrowseFacet("0000000010", 1);
    answerBucketFacets[4] = new BrowseFacet("0000000021", 1);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("numberhisto", Arrays.asList(answerBucketFacets));

    doTest(br, 7, answer, null);

    // now with selection

    BrowseSelection sel = new BrowseSelection("color");
    sel.addValue("green");
    br.addSelection(sel);

    answerBucketFacets = new BrowseFacet[2];
    answerBucketFacets[0] = new BrowseFacet("0000000002", 1);
    answerBucketFacets[1] = new BrowseFacet("0000000021", 1);

    answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("numberhisto", Arrays.asList(answerBucketFacets));

    doTest(br, 2, answer, null);
View Full Code Here


    FacetSpec output = new FacetSpec();
    output.setOrderBy(FacetSortSpec.OrderHitsDesc);
    br.setFacetSpec("sets", output);

    BrowseFacet[] answerBucketFacets = new BrowseFacet[3];
    answerBucketFacets[0] = new BrowseFacet("s1", 5);
    answerBucketFacets[1] = new BrowseFacet("s2", 4);
    answerBucketFacets[2] = new BrowseFacet("s3", 3);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("sets", Arrays.asList(answerBucketFacets));
    doTest(br, 7, answer, null);

    br = new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);

    BrowseSelection sel = new BrowseSelection("sets");
    sel.addValue("s1");
    br.addSelection(sel);

    output = new FacetSpec();
    output.setOrderBy(FacetSortSpec.OrderHitsDesc);
    br.setFacetSpec("sets", output);

    answerBucketFacets = new BrowseFacet[3];
    answerBucketFacets[0] = new BrowseFacet("s1", 5);
    answerBucketFacets[1] = new BrowseFacet("s2", 3);
    answerBucketFacets[2] = new BrowseFacet("s3", 1);

    answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("sets", Arrays.asList(answerBucketFacets));
    doTest(br, 4, answer, null);
  }
View Full Code Here

    FacetSpec output = new FacetSpec();
    output.setOrderBy(FacetSortSpec.OrderHitsDesc);
    br.setFacetSpec("groups", output);

    BrowseFacet[] answerBucketFacets = new BrowseFacet[3];
    answerBucketFacets[0] = new BrowseFacet("g2", 3);
    answerBucketFacets[1] = new BrowseFacet("g1", 1);
    answerBucketFacets[2] = new BrowseFacet("g3", 1);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("groups", Arrays.asList(answerBucketFacets));
    doTest(br, 3, answer, null);

    br = new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);

    sel = new BrowseSelection("groups");
    sel.addValue("g2");
    sel.addValue("g1");
    sel.setSelectionOperation(ValueOperation.ValueOperationAnd);
    br.addSelection(sel);

    output = new FacetSpec();
    output.setOrderBy(FacetSortSpec.OrderHitsDesc);
    br.setFacetSpec("groups", output);

    answerBucketFacets = new BrowseFacet[2];
    answerBucketFacets[0] = new BrowseFacet("g1", 1);
    answerBucketFacets[1] = new BrowseFacet("g2", 1);

    answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("groups", Arrays.asList(answerBucketFacets));
    doTest(br, 1, answer, null);

    br = new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);

    sel = new BrowseSelection("groups");
    sel.addValue("g2");
    sel.addValue("g1");
    sel.setSelectionOperation(ValueOperation.ValueOperationOr);
    br.addSelection(sel);

    output = new FacetSpec();
    output.setOrderBy(FacetSortSpec.OrderHitsDesc);
    br.setFacetSpec("groups", output);

    answerBucketFacets = new BrowseFacet[3];
    answerBucketFacets[0] = new BrowseFacet("g1", 3);
    answerBucketFacets[1] = new BrowseFacet("g2", 3);
    answerBucketFacets[2] = new BrowseFacet("g3", 1);

    answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("groups", Arrays.asList(answerBucketFacets));
    doTest(br, 5, answer, null);
  }
View Full Code Here

    spec.setOrderBy(FacetSortSpec.OrderValueAsc);
    br.setFacetSpec("virtual", spec);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("virtual",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("0010", 1), new BrowseFacet("0011", 1) }));
    doTest(br, 2, answer, new String[] { "1", "2" });
  }
View Full Code Here

          counts.put(entry.getKey(), count);
        }
        for(BrowseFacet facet : entry.getValue().getFacets())
        {
          String val = facet.getValue();
          BrowseFacet oldValue = count.get(val);
          if(oldValue == null)
          {
            count.put(val, new BrowseFacet(val, facet.getHitCount()));
          }
          else
          {
            oldValue.setHitCount(oldValue.getHitCount() + facet.getHitCount());
          }
        }
      }
    }
View Full Code Here

        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (groupAccessibles != null &&
            hit.getGroupValue() != null &&
            groupAccessibles != null &&
            groupAccessibles.length > 0) {
          BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

    String foundValue=null;
    if (_list!=null)
    {
      for (FacetAccessible facetAccessor : _list)
      {
        BrowseFacet facet = facetAccessor.getFacet(value);
        if (facet!=null)
        {
          foundValue = facet.getValue();
          if (sum==-1) sum=facet.getHitCount();
          else sum+=facet.getHitCount();
        }
      }
    }
    if (sum==-1) return null;
    return new BrowseFacet(foundValue,sum);
  }
View Full Code Here

    if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy()))
    {
      while((facet = iter.next(minHits)) != null)
      {
        // find the next facet whose combined hit count obeys minHits
        list.add(new BrowseFacet(String.valueOf(facet), iter.count));
        if(++cnt >= maxCnt) break;                 
      }
    }
    else if(FacetSortSpec.OrderHitsDesc.equals(_fspec.getOrderBy()))
    {
      comparator = new Comparator<BrowseFacet>()
      {
        public int compare(BrowseFacet f1, BrowseFacet f2)
        {
          int val=f2.getHitCount() - f1.getHitCount();
          if (val==0)
          {
            val = (f1.getValue().compareTo(f2.getValue()));
          }
          return val;
        }
      };      
      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)
          list.add(new BrowseFacet(String.valueOf(facet), iter.count));
        Collections.sort(list, comparator);
      }
    }
    return list;
  }
View Full Code Here

        this.initialize(max);
      }
      @Override
      protected boolean lessThan(Object arg0, Object arg1)
      {
        BrowseFacet o1 = (BrowseFacet)arg0;
        BrowseFacet o2 = (BrowseFacet)arg1;
        return comparator.compare(o1, o2) > 0;
      }    
    };
    return queue;
  }
View Full Code Here

  private void filterByKeys(List<BrowseFacet> facets, char separator, int numFacetsPerKey, String[] values) {
    Map<String, AtomicInteger> keyOccurences = new HashMap<String, AtomicInteger>();
    Iterator<BrowseFacet> iterator = facets.iterator();
    String separatorString = String.valueOf(separator);
    while (iterator.hasNext()) {
      BrowseFacet facet = iterator.next();
      String value = facet.getValue();
      if (!value.contains(separatorString)) {
        iterator.remove();
        continue;
      }
      if (values !=null && values.length > 0) {
View Full Code Here

TOP

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

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.