Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseRequest


    BoboBrowser browser = newBrowser();
    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);
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

    ranges.add("003000000");
    ranges.add("004000000");
    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());
    facet = facetholder.getFacet("003000000");
View Full Code Here

    assertEquals("004000000", 0, facet.getFacetValueHitCount());
    assertEquals("",23,result.getNumHits());
  }
 
  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);
      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);
       
View Full Code Here

        Map<String,String[]> predefinedNumberSets = new HashMap<String,String[]>();
        predefinedNumberSets.put("s1", predefinedBuckets2[0]);
        predefinedNumberSets.put("s2", predefinedBuckets2[1]);
        predefinedNumberSets.put("s3", predefinedBuckets2[2]);
      */
     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);
        answerBucketFacets[2] new BrowseFacet("s3", 1);
View Full Code Here

          answer.put("sets", Arrays.asList(answerBucketFacets));
        doTest(br,4,answer,null);
   }
  
   public void testBucketFacetHandlerForStrings() throws Exception{
      BrowseRequest br=new BrowseRequest();
      br.setCount(10);
      br.setOffset(0);
     
      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);
      answerBucketFacets[2] new BrowseFacet("g3", 1);
View Full Code Here

    buffer.append("}").append('\n');
    return buffer.toString();
  }

  public void testStoredFacetField() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);

        BrowseSelection colorSel=new BrowseSelection("testStored");
        colorSel.addValue("stored");
        br.addSelection(colorSel);
        br.setFetchStoredFields(true);
       
        BrowseResult result = null;
        BoboBrowser boboBrowser=null;
      try {
        boboBrowser=newBrowser();
View Full Code Here

      }
       
  }
 
  public void testStoredField() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);

        BrowseSelection colorSel=new BrowseSelection("color");
        colorSel.addValue("red");
        br.addSelection(colorSel);

        BrowseSelection shapeSel=new BrowseSelection("shape");
        shapeSel.addValue("square");
        br.addSelection(shapeSel);
       
        BrowseSelection sizeSel=new BrowseSelection("size");
        sizeSel.addValue("[4 TO 4]");
        br.addSelection(sizeSel);

        BrowseResult result = null;
        BoboBrowser boboBrowser=null;
      try {
        boboBrowser=newBrowser();
       
          result = boboBrowser.browse(br);
          assertEquals(1,result.getNumHits());
          BrowseHit hit = result.getHits()[0];
          assertNull(hit.getStoredFields());
         
          br.setFetchStoredFields(true);
          result = boboBrowser.browse(br);
          assertEquals(1,result.getNumHits());
          hit = result.getHits()[0];
          Document storedFields = hit.getStoredFields();
          assertNotNull(storedFields);
View Full Code Here

      }
       
  }
 
  public void testRawDataRetrieval() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);
    br.setSort(new SortField[]{new SortField("date",SortField.CUSTOM,false)});
    BrowseResult result = null;
        BoboBrowser boboBrowser=null;
        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd");
      try {
        boboBrowser=newBrowser();
View Full Code Here

TOP

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

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.