Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.FacetSpec


     
      BrowseSelection tageSel = new BrowseSelection("tag");
      tageSel.addValue("rabbit");
      browseRequest.addSelection(tageSel);
     
      FacetSpec colorFacetSpec = new FacetSpec();
      colorFacetSpec.setExpandSelection(true);
      colorFacetSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
     
      FacetSpec tagFacetSpec = new FacetSpec();
             
      browseRequest.setFacetSpec("color", colorFacetSpec);
      browseRequest.setFacetSpec("tag", tagFacetSpec);
     
      FacetSpec shapeSpec = new FacetSpec();
      shapeSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
      browseRequest.setFacetSpec("shape", shapeSpec);
     
      FacetSpec dateSpec=new FacetSpec();
      dateSpec.setExpandSelection(true);
      browseRequest.setFacetSpec("date", dateSpec);
     
      BoboBrowser boboBrowser = newBrowser();
     
      browseRequest.setSort(new SortField[]{new SortField("compactnum",SortField.CUSTOM,true)});
View Full Code Here


    String[] ranges = new String[]{"[2001/01/01 TO 2001/12/30]","[2007/01/01 TO 2007/12/30]"};
    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)}));
       
    doTest(browser,req,7,answer,null);
  }
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() {
     
      public IntComparator newComparator(final FieldValueAccessor fieldValueAccessor,
          final int[] counts) {
       
        return new IntComparator(){

          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[v1]-counts[v2];
            }
            return val;
          }
         
          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[v1]-counts[v2];
            }
            return val;
          }
        };
      }

      public Comparator<BrowseFacet> newComparator() {
        return new Comparator<BrowseFacet>(){
          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.getHitCount()-o1.getHitCount();
            }
            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)}));
     
    doTest(req,7,answer,null);
  }
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)}));
     
    doTest(req,7,answer,null);

  }
View Full Code Here

    FacetHandler<?> facetHandler = new DynamicTimeRangeFacetHandler("timerange", "timeinmillis", now, ranges );
    browser.setFacetHandler(facetHandler );
// 
    BrowseRequest req = new BrowseRequest();
    BrowseFacet facet = null;
    FacetSpec facetSpec = new FacetSpec();
    req.setFacetSpec("timerange", facetSpec);
    BrowseResult result = browser.browse(req);
    FacetAccessible facetholder = result.getFacetAccessor("timerange");
    List<BrowseFacet> facets = facetholder.getFacets();
    facet = facets.get(0);
    assertEquals("order by value", "000000001", facet.getValue());
    assertEquals("order by value", 1 , facet.getFacetValueHitCount());
    facet = facets.get(1);
    assertEquals("order by value", "000010000", facet.getValue());
    assertEquals("order by value", 1 , facet.getFacetValueHitCount());
    facet = facets.get(5);
    assertEquals("order by value", "001000000", facet.getValue());
    assertEquals("order by value", 20 , facet.getFacetValueHitCount());
    facet = facets.get(7);
    assertEquals("order by value", "003000000", facet.getValue());
    assertEquals("order by value", 3 , facet.getFacetValueHitCount());
// 
    req = new BrowseRequest();
    facetSpec = new FacetSpec();
    facetSpec.setMinHitCount(0);
    facetSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
    req.setFacetSpec("timerange", facetSpec);
    result = browser.browse(req);
    facetholder = result.getFacetAccessor("timerange");
    facets = facetholder.getFacets();
    facet = facets.get(0);
    assertEquals("", "002000000", facet.getValue());
    assertEquals("", 25 , facet.getFacetValueHitCount());
    facet = facets.get(1);
    assertEquals("", "001000000", facet.getValue());
    assertEquals("", 20 , facet.getFacetValueHitCount());
    facet = facets.get(2);
    assertEquals("", "003000000", facet.getValue());
    assertEquals("", 3 , facet.getFacetValueHitCount());
    facet = facets.get(8);
    assertEquals("minCount=0", "004000000", facet.getValue());
    assertEquals("minCount=0", 0 , facet.getFacetValueHitCount());
// 
    req = new BrowseRequest();
    facetSpec = new FacetSpec();
    BrowseSelection sel = new BrowseSelection("timerange");
    sel.addValue("001000000");
    req.addSelection(sel);
    facetSpec.setExpandSelection(true);
    req.setFacetSpec("timerange", facetSpec);
    result = browser.browse(req);
    facetholder = result.getFacetAccessor("timerange");
    facets = facetholder.getFacets();
    facet = facets.get(0);
    assertEquals("", "000000001", facet.getValue());
    assertEquals("", 1 , facet.getFacetValueHitCount());
    facet = facets.get(6);
    assertEquals("", "002000000", facet.getValue());
    assertEquals("", 25 , facet.getFacetValueHitCount());
    facet = facets.get(7);
    assertEquals("", "003000000", facet.getValue());
    assertEquals("", 3 , facet.getFacetValueHitCount());
// 
    req = new BrowseRequest();
    facetSpec = new FacetSpec();
    sel = new BrowseSelection("timerange");
    sel.addValue("001000000");
    sel.addValue("003000000");
    sel.addValue("004000000");
    req.addSelection(sel );
    facetSpec.setExpandSelection(false);
    req.setFacetSpec("timerange", facetSpec);
    result = browser.browse(req);
    facetholder = result.getFacetAccessor("timerange");
    facet = facetholder.getFacet("001000000");
    assertEquals("001000000", 20, facet.getFacetValueHitCount());
View Full Code Here

  public void testHistogramFacetHandler() throws Exception{
    BrowseRequest br=new BrowseRequest();
      br.setCount(0);
      br.setOffset(0);
     
      FacetSpec output=new FacetSpec();
      output.setMaxCount(100);
      output.setMinHitCount(1);
      br.setFacetSpec("numberhisto", output);
     
     
      BrowseFacet[] answerBucketFacets = new BrowseFacet[5];    
      answerBucketFacets[0] new BrowseFacet("0000000000", 3);
View Full Code Here

      */
     BrowseRequest br=new BrowseRequest();
        br.setCount(10);
        br.setOffset(0);
       
        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);
View Full Code Here

     
      BrowseSelection sel=new BrowseSelection("groups");
        sel.addValue("g2");
        br.addSelection(sel);
   
      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);
View Full Code Here

    int nThreads = 2;
    final int numIters = 200;
   
    String fname1 = "facet1";
    String fname2 = "facet2";
    final FacetSpec fspec = new FacetSpec();
    fspec.setExpandSelection(true);
    fspec.setMaxCount(50);
    fspec.setMinHitCount(1);
    fspec.setOrderBy(FacetSortSpec.OrderHitsDesc);
   
    final List<FacetAccessible> list1 = new ArrayList<FacetAccessible>(numSegs);
    for (int i=0;i<numSegs;++i){
      list1.add(buildSubAccessible(fname1, i, fspec));
    }
View Full Code Here

   
    BrowseSelection makeSel=new BrowseSelection("make");
    makeSel.addValue("rav4");
    br.addSelection(makeSel);
       
    FacetSpec spec=new FacetSpec();
    spec.setExpandSelection(true);
    spec.setOrderBy(FacetSortSpec.OrderHitsDesc);
    spec.setMaxCount(15);
   
    br.setFacetSpec("mycolor", spec);
    br.setFacetSpec("id", spec);
    br.setFacetSpec("make", spec);
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.