Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseRequest


    return facetHandlers;
  }
 
 
  public void testNotValuesForSimpleFacetHandler() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setCount(20);
    br.setOffset(0);

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

    BrowseSelection idSel=new BrowseSelection("id");
    idSel.addNotValue("0");
    br.addSelection(idSel);

    BrowseResult result = null;
    BoboBrowser boboBrowser=null;
    int expectedHitNum = (_documentSize/2) - 1;
    try {
View Full Code Here


    try {
      Directory ramIndexDir = createIndexTwo();
      IndexReader srcReader=IndexReader.open(ramIndexDir,true);
      boboBrowser = new BoboBrowser(BoboIndexReader.getInstance(srcReader,_facetHandlers, null));
     
      BrowseRequest br=new BrowseRequest();
      br.setCount(20);
      br.setOffset(0);

      if(_idRanges==null)
      {
        log.error("_idRanges cannot be null in order to test NOT on RangeFacetHandler");
      }
      BrowseSelection idSel=new BrowseSelection("idRange");
      int rangeIndex = 2;
      idSel.addNotValue(_idRanges[0]);
      int expectedHitNum = 1;
      br.addSelection(idSel);
      BooleanQuery q = new BooleanQuery();
      q.add(NumericRangeQuery.newIntRange("NUM", 10, 10, true, true), Occur.MUST_NOT);
      q.add(new MatchAllDocsQuery(), Occur.MUST);
      br.setQuery(q);
     
      result = boboBrowser.browse(br);
     
      assertEquals(expectedHitNum,result.getNumHits());
      for(int i=0; i<result.getNumHits();i++)
View Full Code Here

    return facetHandlers;
  }
 
 
  public void testFacetNameForSimpleFacetHandler() throws Exception{
    BrowseRequest br=new BrowseRequest();
    br.setCount(20);
    br.setOffset(0);

    BrowseSelection colorSel=new BrowseSelection("mycolor");
    colorSel.addValue("yellow");
    br.addSelection(colorSel);
   
    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);

    BrowseResult result = null;
    BoboBrowser boboBrowser=null;
    int expectedHitNum = 3;
    try {
View Full Code Here

  public void setQuery(String qString){
    _qString = qString;
  }
 
  public void clear(){
    _req = new BrowseRequest();
    _req.setOffset(0);
    _req.setCount(5);
    _req.setFetchStoredFields(true);
    _qString = null;
  }
View Full Code Here

    res.setHits(browseHits);
    return res;
  }
 
  public static BrowseRequest convert(BrowseRequestBPO.Request req,QueryParser qparser) throws ParseException{
    BrowseRequest breq = new BrowseRequest();
    String query = req.getQuery();
   
    if (qparser!=null && query!=null && query.length() > 0){
      try{
        Query q = qparser.parse(query);
        breq.setQuery(q);
      }
      catch(Exception e){
        throw new ParseException(e.getMessage());
      }
    }
    breq.setOffset(req.getOffset());
    breq.setCount(req.getCount());
   
    int i = 0;
   
    List<BrowseRequestBPO.Sort> sortList = req.getSortList();
    SortField[] sortFields = new SortField[sortList == null ? 0 : sortList.size()];
    for (BrowseRequestBPO.Sort s : sortList){
      String fieldname = s.getField();
      if (fieldname!=null && fieldname.length() == 0){
        fieldname=null;
      }
      SortField sf = new SortField(fieldname,s.getType(),s.getReverse());
      sortFields[i++] = sf;
    }
    if (sortFields.length > 0){
     breq.setSort(sortFields);
    }
   
    List<BrowseRequestBPO.FacetSpec> fspecList = req.getFacetSpecsList();
    for (BrowseRequestBPO.FacetSpec fspec : fspecList){
      FacetSpec facetSpec = new FacetSpec();
      facetSpec.setExpandSelection(fspec.getExpand());
      facetSpec.setMaxCount(fspec.getMax());
      facetSpec.setMinHitCount(fspec.getMinCount());
      BrowseRequestBPO.FacetSpec.SortSpec fsort = fspec.getOrderBy();
      if (fsort == BrowseRequestBPO.FacetSpec.SortSpec.HitsDesc)
      {
        facetSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
      }
      else
      {
        facetSpec.setOrderBy(FacetSortSpec.OrderValueAsc)
      }
      breq.setFacetSpec(fspec.getName(), facetSpec);
    }
   
    List<BrowseRequestBPO.Selection> selList = req.getSelectionsList();
    for (BrowseRequestBPO.Selection sel : selList){
      BrowseSelection bsel = null;
     
      List<String> vals = sel.getValuesList();
      if (vals!=null)
      {
        if (bsel==null)
        {
          bsel = new BrowseSelection(sel.getName());
        }
        bsel.setValues(vals.toArray(new String[vals.size()]));
       
      }
      vals = sel.getNotValuesList();
      if (vals!=null)
      {
        if (bsel==null)
        {
          bsel = new BrowseSelection(sel.getName());
        }
        bsel.setNotValues(vals.toArray(new String[vals.size()]));
       
      }
     
      if (bsel!= null){
        BrowseRequestBPO.Selection.Operation operation = sel.getOp();
        if (operation == BrowseRequestBPO.Selection.Operation.OR){
          bsel.setSelectionOperation(ValueOperation.ValueOperationOr);
        }
        else{
          bsel.setSelectionOperation(ValueOperation.ValueOperationAnd);
        }
        List<BrowseRequestBPO.Property> props = sel.getPropsList();
        if (props!=null)
        {
          for (BrowseRequestBPO.Property prop : props){
            bsel.setSelectionProperty(prop.getKey(), prop.getVal());
          }
        }
        breq.addSelection(bsel);
      }
     
    }
    return breq;
  }
View Full Code Here

    return createRequest(minHitCount, ValueOperation.ValueOperationOr, terms);
  }

  public BrowseRequest createRequest(int minHitCount, BrowseSelection.ValueOperation operation,
      String... terms) {
    BrowseRequest req = new BrowseRequest();

    BrowseSelection sel = new BrowseSelection(AttributeHandlerName);
    for (String term : terms) {
      sel.addValue(term);
    }
    sel.setSelectionProperties(selectionProperties);
    sel.setSelectionOperation(operation);
    req.addSelection(sel);
    req.setCount(50);
    FacetSpec fs = new FacetSpec();
    fs.setMinHitCount(minHitCount);
    req.setFacetSpec(AttributeHandlerName, fs);
    return req;
  }
View Full Code Here

    req.setFacetSpec(AttributeHandlerName, fs);
    return req;
  }

  public void test1Filter() throws Exception {
    BrowseRequest request = createRequest(1, "prop3");
    RandomAccessFilter randomAccessFilter = attributesFacetHandler.buildFilter(request
        .getSelection(AttributeHandlerName));
    DocIdSetIterator iterator = randomAccessFilter.getDocIdSet(
      boboReader.getSubReaders().get(0).getContext(), null).iterator();
    int docId = iterator.nextDoc();
    int[] docIds = new int[2];
View Full Code Here

    BrowseFacet facet = facets.get(0);
    assertEquals(1, facet.getFacetValueHitCount());
  }

  public void test2PropertyRetrieval() throws Exception {
    BrowseRequest request = createRequest(1, "prop3");
    BrowseResult res = browser.browse(request);
    assertEquals(res.getNumHits(), 2);
    assertEquals(res.getHits()[0].getDocid(), 1);
    assertEquals(res.getHits()[1].getDocid(), 2);
    List<BrowseFacet> facets = res.getFacetAccessor(AttributeHandlerName).getFacets();
View Full Code Here

    assertEquals(facets.get(2).getValue(), "prop3=val3");
    assertEquals(facets.get(2).getFacetValueHitCount(), 1);
  }

  public void test3PropertyInEachDocRetrieval() throws Exception {
    BrowseRequest request = createRequest(1, "prop1");
    BrowseResult res = browser.browse(request);
    assertEquals(res.getNumHits(), 6);
    assertEquals(res.getHits()[0].getDocid(), 0);
    assertEquals(res.getHits()[5].getDocid(), 5);
    List<BrowseFacet> facets = res.getFacetAccessor(AttributeHandlerName).getFacets();
View Full Code Here

    assertEquals(facets.get(1).getValue(), "prop1=val2");
    assertEquals(facets.get(1).getFacetValueHitCount(), 2);
  }

  public void test4PropertyInFirstDocRetrieval() throws Exception {
    BrowseRequest request = createRequest(1, "prop5");
    BrowseResult res = browser.browse(request);
    assertEquals(res.getNumHits(), 1);
    assertEquals(res.getHits()[0].getDocid(), 0);

    List<BrowseFacet> facets = res.getFacetAccessor(AttributeHandlerName).getFacets();
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.