Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseRequest


      SolrParams solrParams = rb.req.getParams();

    String shardsVal = solrParams.get(ShardParams.SHARDS, null);
   
      BrowseRequest br = null;
      try{
        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();
View Full Code Here


    String df = params.get(CommonParams.DF);
    String sortString = params.get(CommonParams.SORT);
    BoboDefaultQueryBuilder qbuilder = new BoboDefaultQueryBuilder();
    Query query = qbuilder.parseQuery(qstring, df);
    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");
View Full Code Here

    String df = params.get(CommonParams.DF);
    String sortString = params.get(CommonParams.SORT);
    BoboDefaultQueryBuilder qbuilder = new BoboDefaultQueryBuilder();
    Query query = qbuilder.parseQuery(qstring, df);
    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");
View Full Code Here

    }
  }

  public void run() {
    while (true) {
      BrowseRequest req = _iter.next();
      if (req != null) {
        BoboBrowser svc = null;
        long time = 0L;
        Exception ex = null;
        try {
View Full Code Here

        {
          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();
View Full Code Here

          String[] parts2 = parts1[1].split(",");
          if (parts2.length>0)
          {
            BrowseSelection sel = new BrowseSelection(parts1[0]);
            sel.setValues(parts2);
            BrowseRequest req = new BrowseRequest();
            req.addSelection(sel);
            for (String facet : facets)
            {
              FacetSpec fspec = new FacetSpec();
              fspec.setOrderBy(FacetSortSpec.OrderHitsDesc);
              fspec.setMaxCount(10);
              req.setFacetSpec(facet, fspec);
            }
            reqList.add(req);
          }
        }
      }
View Full Code Here

      {
        for (int i=0;i<numIter;++i)
        {

          BoboBrowser svc = new BoboBrowser(_reader);
          BrowseRequest req = new BrowseRequest();
         
          //req.setQuery(q);
         
          //BrowseSelection sel = new BrowseSelection("ccid");
          //sel.addValue("1009");
          //req.addSelection(sel);
         
          BrowseSelection sel2 = new BrowseSelection("industry");
          sel2.addValue("4");
          req.addSelection(sel2);
         
          FacetSpec fspec = new FacetSpec();
          fspec.setExpandSelection(true);
          fspec.setMaxCount(10);
          fspec.setOrderBy(FacetSortSpec.OrderHitsDesc);
         
           req.setFacetSpec("ccid", fspec);
           req.setFacetSpec("pcid", fspec);
           req.setFacetSpec("education_id", fspec);
           req.setFacetSpec("geo_region", fspec);
           req.setFacetSpec("geo_country", fspec);
           req.setFacetSpec("industry", fspec);
           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();
View Full Code Here

    doConvert(new TermRangeQuery("tags", "a", "x", false, false));
    doConvert(new TermRangeQuery("tags", "a", "x", true, true));
  }

  public void doConvert(Query query) throws ParseException {
    BrowseRequest boboReqBefore = new BrowseRequest();
    boboReqBefore.setQuery(query);
    BrowseRequestBPO.Request req = (BrowseRequestBPO.Request) BrowseProtobufConverter.convert(boboReqBefore);
//    System.out.println("request after conversion to msg:\n" + req.toString());
    String reqString = TextFormat.printToString(req);
    reqString = reqString.replace('\r', ' ').replace('\n', ' ');
//    System.out.println(reqString);
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
    QueryParser _qparser = new QueryParser(Version.LUCENE_CURRENT,"", analyzer);
//    System.out.println("msg to req");
    BrowseRequest boboReqAfter = BrowseProtobufConverter.convert(req, _qparser);
//    System.out.println("get query 2: "
//        + (boboReqAfter.getQuery() != null ? boboReqAfter.getQuery().getClass()
//            : "null query"));
//    System.out.println("----------");
    assertEquals(query.getClass(), boboReqAfter.getQuery().getClass());
  }
View Full Code Here

  public void testMultiValPath() throws Exception{
    IndexReader reader = IndexReader.open(directory,true);
    BoboIndexReader boboReader = BoboIndexReader.getInstance(reader, facetHandlers);
   
    BoboBrowser browser = new BoboBrowser(boboReader);
    BrowseRequest req = new BrowseRequest();
   
    BrowseSelection sel = new BrowseSelection(PathHandlerName);
    sel.addValue("/a");
    HashMap<String,String> propMap = new HashMap<String,String>();
    propMap.put(PathFacetHandler.SEL_PROP_NAME_DEPTH,"0");
    propMap.put(PathFacetHandler.SEL_PROP_NAME_STRICT,"false");
    sel.setSelectionProperties(propMap);
   
    req.addSelection(sel);
   
    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();
View Full Code Here

  static void doBrowse(BoboBrowser browser) throws Exception
  {
    String q="java";
    QueryParser parser=new QueryParser(Version.LUCENE_CURRENT,"b",new StandardAnalyzer(Version.LUCENE_CURRENT));
    Query query=parser.parse(q);
    BrowseRequest br=new BrowseRequest();
    //br.setQuery(query);
    br.setOffset(0);
    br.setCount(0);

        BrowseSelection geoSel=new BrowseSelection("geo_region");
        geoSel.addValue("5227");
        BrowseSelection industrySel=new BrowseSelection("industry_norm");
        industrySel.addValue("1");
   
        //br.addSelection(geoSel);
        br.addSelection(industrySel);
   
    FacetSpec regionSpec=new FacetSpec();
    regionSpec.setExpandSelection(true);
    regionSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
    regionSpec.setMaxCount(5);
   
        FacetSpec industrySpec=new FacetSpec();
        industrySpec.setExpandSelection(true);
        industrySpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
        industrySpec.setMaxCount(5);
       

        FacetSpec numEndorserSpec=new FacetSpec();
        numEndorserSpec.setExpandSelection(true);
   
    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);
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.