Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseResult


    br.setQuery(parser.parse("color:red OR shape:square"));
    br.setCount(10);
    br.setOffset(0);

    br.setSort(new SortField[] { SortField.FIELD_SCORE });
    BrowseResult res = doTest(br, 4, null, new String[] { "1", "7", "2", "5" });

    BrowseHit[] hits = res.getHits();
    for (BrowseHit hit : hits) {
      assertNull(hit.getExplanation());
    }

    br.setShowExplanation(true);
    res = doTest(br, 4, null, new String[] { "1", "7", "2", "5" });
    hits = res.getHits();

    for (BrowseHit hit : hits) {
      assertNotNull(hit.getExplanation());
    }

    Query rawQuery = br.getQuery();

    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
    Date d = format.parse("2006/06/01");
    long fromTime = d.getTime();

    RecencyBoostScorerBuilder recencyBuilder = new RecencyBoostScorerBuilder("date", 2.0f,
        TimeUnit.DAYS.convert(fromTime, TimeUnit.MILLISECONDS), 30L, TimeUnit.DAYS);
    ScoreAdjusterQuery sq = new ScoreAdjusterQuery(rawQuery, recencyBuilder);
    br.setQuery(sq);

    res = doTest(br, 4, null, new String[] { "7", "1", "2", "5" });

    hits = res.getHits();
    for (BrowseHit hit : hits) {
      assertNotNull(hit.getExplanation());
      System.out.println(hit.getExplanation());
    }
  }
View Full Code Here


    browseRequest
        .setSort(new SortField[] { new SortField("compactnum", SortField.Type.CUSTOM, true) });

    MultiBoboBrowser multiBoboBrowser = new MultiBoboBrowser(new Browsable[] { boboBrowser,
        boboBrowser });
    BrowseResult mergedResult = multiBoboBrowser.browse(browseRequest);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put("color",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("red", 4), new BrowseFacet("green", 2) }));
    answer.put(
      "tag",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("animal", 2), new BrowseFacet("dog", 2),
          new BrowseFacet("humane", 2), new BrowseFacet("pet", 2), new BrowseFacet("rabbit", 4) }));
    answer.put("shape", Arrays.asList(new BrowseFacet[] { new BrowseFacet("square", 4) }));
    answer.put("date",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("[2000/01/01 TO 2003/05/05]", 2) }));

    doTest(mergedResult, browseRequest, 4, answer, new String[] { "7", "7", "1", "1" });

    browseRequest
        .setSort(new SortField[] { new SortField("multinum", SortField.Type.CUSTOM, true) });
    mergedResult = multiBoboBrowser.browse(browseRequest);
    doTest(mergedResult, browseRequest, 4, answer, new String[] { "7", "7", "1", "1" });
    mergedResult.close();
    multiBoboBrowser.close();
  }
View Full Code Here

    br.setSort(new SortField[] { SortField.FIELD_SCORE });
    br.setQuery(bq);
    br.setOffset(0);
    br.setCount(10);

    BrowseResult res = doTest(br, 6, null, new String[] { "4", "1", "7", "5", "3", "2" });
    BrowseHit[] hits = res.getHits();
    float[] scores = new float[] { 13, 11, 11, 10, 4.5f, 2.5f }; // default coord = 1/2
    for (int i = 0; i < hits.length; ++i) {
      assertEquals(scores[i], hits[i].getScore());
    }
  }
View Full Code Here

    br.setOffset(0);
    br.setCount(10);
    br.setSort(new SortField[] { SortField.FIELD_SCORE });
    BoboBrowser b = newBrowser();

    BrowseResult r = b.browse(br);

    doTest(r, br, 7, null, new String[] { "7", "2", "1", "3", "4", "5", "6" });
  }
View Full Code Here

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

    _closeReader=closeReader;
  }

  @SuppressWarnings("serial")
  public BrowseResult browse(BrowseRequest req) throws BrowseException {
    BrowseResult result=BrowseService.EMPTY_RESULT;
    if (req.getOffset() < 0) throw new BrowseException("Invalid offset: "+req.getOffset());
    if (_reader!=null){
      BoboBrowser browser;
      try
      {
View Full Code Here

      }
    }
    else if ("browse".equalsIgnoreCase(cmd)){
      BrowseRequest req = _reqBuilder.getRequest();
     
      BrowseResult res = _svc.browse(req);
      String output = BrowseResultFormatter.formatResults(res);
      System.out.println(output);
    }
    else{
      System.out.println("Unknown command: "+cmd+", do help for list of supported commands");
View Full Code Here

    req.setFacetSpec("group_id", fspec);
   
    BoboIndexReader reader = BoboIndexReader.getInstance(IndexReader.open(idxDir));
    BoboBrowser browser = new BoboBrowser(reader);
   
    BrowseResult res = browser.browse(req);
   
    Map<String,FacetAccessible> facetMap = res.getFacetMap();
    Collection<FacetAccessible> facetCountCollectors = facetMap.values();
    Iterator<FacetAccessible> iter = facetCountCollectors.iterator();
    while (iter.hasNext())
    {
      FacetAccessible f = iter.next();
View Full Code Here

      return browser.browse(req);
    }
        catch(Exception e)
    {
      logger.error(e.getMessage(),e);
      return new BrowseResult();
    }
    finally
    {
      if (browser!=null)
      {
View Full Code Here

        br=BoboRequestBuilder.buildRequest(solrParams,query,sort);
      }
      catch(Exception e){
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
      }
      BrowseResult res = null;
      if (shardsVal == null && !solrParams.getBool(ShardParams.IS_SHARD, false))
    {

      SolrIndexSearcher searcher=rb.req.getSearcher();
     
      SolrIndexReader solrReader = searcher.getReader();
      BoboIndexReader reader = (BoboIndexReader)solrReader.getWrappedReader();
     
      if (reader instanceof BoboIndexReader){
          try {
            List<Query> filters = rb.getFilters();
            if (filters!=null){
              final ArrayList<DocIdSet> docsets = new ArrayList<DocIdSet>(filters.size());
                for (Query filter : filters){
                  Weight weight = filter.createWeight(rb.req.getSearcher());
                  final Scorer scorer = weight.scorer(reader, false, true);
                  docsets.add(new DocIdSet(){
                @Override
                public DocIdSetIterator iterator() throws IOException {
                  return scorer;
                }
                   
                  });
                }
               
                if (docsets.size()>0){
                  br.setFilter(
                    new Filter(){
                @Override
                public DocIdSet getDocIdSet(IndexReader reader)
                    throws IOException {
                  return new AndDocIdSet(docsets);
                }
                  });
                }
            }
             
            Set<String> facetNames = reader.getFacetNames();
            Set<String> returnFields = rb.rsp.getReturnFields();
            Set<String> storedFields = new HashSet<String>();
            if (returnFields!=null){
              for (String fld : returnFields){
              if (!facetNames.contains(fld)){
                storedFields.add(fld);
              }
              }
              br.setFetchStoredFields(!storedFields.isEmpty());
            }
           
           
                  BoboBrowser browser = new BoboBrowser(reader);
                 
          res=browser.browse(br);
         
        } catch (Exception e) {
          logger.error(e.getMessage(),e);
          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e.getMessage(),e);
        }
        
      }
      else{
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"invalid reader, please make sure BoboIndexReaderFactory is set.");
      }
    }
    else{
      // multi sharded request
      String[] shards = shardsVal.split(",");
      res = DispatchUtil.broadcast(_threadPool, solrParams, br, shards, 5);
    }
     
      SolrDocumentList docList = new SolrDocumentList();
     
     
      docList.setNumFound(res.getNumHits());
      docList.setStart(br.getOffset());
     
      rb.stage = ResponseBuilder.STAGE_GET_FIELDS;
      boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
     
      BrowseHit[] hits = res.getHits();
      if (hits!=null){
        for (BrowseHit hit : hits){
        SolrDocument doc = convert(hit,rb.rsp.getReturnFields());
        if (doc!=null){
          if (returnScores){
View Full Code Here

TOP

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

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.