Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseResult


        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


    Sort sort = qbuilder.parseSort(sortString);
    BrowseRequest br = null;
    try {
      br=BoboRequestBuilder.buildRequest(params,query,sort);
      logger.info("REQ: "+BrowseProtobufConverter.toProtoBufString(br));
      BrowseResult result=_svc.browse(br);
      res.setCharacterEncoding("UTF-8");
      Writer writer=res.getWriter();
     
      String outputFormat=req.getParameter("output");
      if ("json".equals(outputFormat)){
View Full Code Here

    Sort sort = qbuilder.parseSort(sortString);
    BrowseRequest br = null;
    try {
      br=BoboRequestBuilder.buildRequest(params,query,sort);
      logger.info("REQ: "+BrowseProtobufConverter.toProtoBufString(br));
      BrowseResult result=_svc.browse(br);
      res.setCharacterEncoding("UTF-8");
      Writer writer=res.getWriter();
     
      String outputFormat=req.getParameter("output");
      if ("json".equals(outputFormat)){
View Full Code Here

        BoboBrowser svc = null;
        long time = 0L;
        Exception ex = null;
        try {
          svc = new BoboBrowser(_reader);
          BrowseResult res = svc.browse(req);
          // System.out.println("num hits: "+res.getNumHits());
          getFacets(res);
          time = res.getTime();
        } catch (Exception e) {
          e.printStackTrace();
          ex = e;
        } finally {
          if (_collector != null) {
View Full Code Here

public class BrowseResultConverter implements Converter {

  public void marshal(Object obj, HierarchicalStreamWriter writer,
      MarshallingContext ctx) {
    BrowseResult result=(BrowseResult)obj;
    writer.addAttribute("numhits", String.valueOf(result.getNumHits()));
    writer.addAttribute("totaldocs", String.valueOf(result.getTotalDocs()));
    writer.addAttribute("time", String.valueOf(result.getTime()));
   
    writer.startNode("facets");
    Set<Entry<String,FacetAccessible>> facetAccessors=result.getFacetMap().entrySet();
   
    writer.addAttribute("count", String.valueOf(facetAccessors.size()));
   
    for (Entry<String,FacetAccessible> entry : facetAccessors){
      String choiceName=entry.getKey();
      FacetAccessible facetAccessor = entry.getValue();
     
      List<BrowseFacet> facetList = facetAccessor.getFacets();
     
      writer.startNode("facet");
      writer.addAttribute("name", choiceName);
     
      writer.addAttribute("facetcount", String.valueOf(facetList.size()));
     
      for (BrowseFacet facet : facetList){
        writer.startNode("facet-value");
        writer.addAttribute("value", String.valueOf(facet.getValue()));
        writer.addAttribute("count", String.valueOf(facet.getHitCount()));
        writer.endNode();
      }
      writer.endNode();
    }
    writer.endNode();
    writer.startNode("hits");
    BrowseHit[] hits=result.getHits();

    writer.addAttribute("length", String.valueOf(hits==null ? 0 : hits.length));
   
    for (BrowseHit hit : hits){
      ctx.convertAnother(hit);
View Full Code Here

    writer.endNode();
  }

  public Object unmarshal(HierarchicalStreamReader reader,
      UnmarshallingContext ctx) {   
    BrowseResult res=new BrowseResult();
   
    String numHitsString=reader.getAttribute("numhits");
    if (numHitsString!=null){
      res.setNumHits(Integer.parseInt(numHitsString));
    }
   
    String totalDocsString=reader.getAttribute("totaldocs");
    if (totalDocsString!=null){
      res.setTotalDocs(Integer.parseInt(totalDocsString));
    }
   
    String timeString=reader.getAttribute("time");
    if (timeString!=null){
      res.setTime(Long.parseLong(timeString));
    }
   
    while (reader.hasMoreChildren()){
      reader.moveDown();
      if ("facets".equals(reader.getNodeName())){
        Map<String,FacetAccessible> facetMap = new HashMap<String,FacetAccessible>();
        String facetCountString = reader.getAttribute("count");
        if (facetCountString!=null){
          int count = Integer.parseInt(facetCountString);
          if (count > 0){
            for (int i=0;i<count;++i){
              reader.moveDown();
              String name = reader.getAttribute("name");
              String countStr = reader.getAttribute("facetcount");
              int fcount = 0;
              if (countStr!=null){
                fcount = Integer.parseInt(countStr);
              }
              BrowseFacet[] facets = new BrowseFacet[fcount];
              for (int k=0;k<fcount;++k){
                facets[k]=new BrowseFacet();
                reader.moveDown();
                String valueString=reader.getAttribute("value");
                facets[k].setValue(valueString);
               
                String countString=reader.getAttribute("count");
                if (countString!=null){
                  facets[k].setHitCount(Integer.parseInt(countString));
                }
                reader.moveUp();
              }
              facetMap.put(name,new MappedFacetAccessible(facets));
              reader.moveUp();
            }
            res.addAll(facetMap);
          }
        }
      }
      else if ("hits".equals(reader.getNodeName())){
        String countStr = reader.getAttribute("length");
        int hitLen = Integer.parseInt(countStr);
        BrowseHit[] hits = new BrowseHit[hitLen];
        for (int i = 0; i< hitLen; ++i){
          hits[i]=(BrowseHit)ctx.convertAnother(res, BrowseHit.class);
        }
        res.setHits(hits);
      }
      reader.moveUp();
    }
    return res;
  }
View Full Code Here

          for (BrowseRequest req : reqs)
          {
            try
            {
              long start = System.currentTimeMillis();
              BrowseResult result = svc.browse(req);
              long end = System.currentTimeMillis();
 
              long time = result.getTime();
              System.out.println("took: (c):" + (end - start) + " / (s):" + time);
              Thread.sleep(200);
            }
            catch(Exception e)
            {
              e.printStackTrace();
            }
          }
        }
        public void run2()
        {
          while (true)
          {
            try
            {
              BrowseRequest req = new BrowseRequest();
              BrowseSelection sel = new BrowseSelection("color");
              sel.addValue("red");
              req.addSelection(sel);

              FacetSpec fspec = new FacetSpec();
              fspec.setExpandSelection(true);
              fspec.setMaxCount(10);
              fspec.setOrderBy(FacetSortSpec.OrderHitsDesc);

              req.setFacetSpec("color", fspec);
              req.setFacetSpec("category", fspec);
              req.setFacetSpec("makemodel", fspec);
              req.setFacetSpec("city", fspec);
              req.setFacetSpec("price", fspec);
              req.setFacetSpec("year", fspec);

              long start = System.currentTimeMillis();
              BrowseResult result = svc.browse(req);
              long end = System.currentTimeMillis();

              long time = result.getTime();
              System.out.println("took: (c):" + (end - start) + " / (s):" + time);
              Thread.sleep(200);
            }
            catch (Exception e)
            {
View Full Code Here

           req.setFacetSpec("proposal_accepts", fspec);
           req.setFacetSpec("num_endorsers", fspec);
           //req.setFacetSpec("group_id", fspec);
          long start = System.currentTimeMillis();
         
          BrowseResult result = svc.browse(req);
          long end = System.currentTimeMillis();
          System.out.println("took: "+(end-start));
          svc.close();
         
          Thread.sleep(200);
View Full Code Here

   
    FacetSpec fs = new FacetSpec();
    fs.setMinHitCount(1);
    req.setFacetSpec(PathHandlerName, fs);
   
    BrowseResult res = browser.browse(req);
    assertEquals(res.getNumHits(),1);
    FacetAccessible fa = res.getFacetAccessor(PathHandlerName);
    List<BrowseFacet> facets = fa.getFacets();
    System.out.println(facets);
    assertEquals(1,facets.size());
    BrowseFacet facet = facets.get(0);
    assertEquals(1,facet.getFacetValueHitCount());
View Full Code Here

    br.setFacetSpec("industry_norm", industrySpec);
        br.setFacetSpec("geo_region", regionSpec);
        br.setFacetSpec("num_endorsers_norm", numEndorserSpec);

    long start=System.currentTimeMillis();
    BrowseResult res=browser.browse(br);
    long end=System.currentTimeMillis();
    System.out.println("result: "+res);
    System.out.println("took: "+(end-start));
    browser.close();
  }
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.