Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseResult


    int numHits = 0;
    int totalDocs = 0;
        for (int i = 0; i < futureList.length; i++)
    {
      try {
        BrowseResult res = futureList[i].get();
        BrowseHit[] hits = res.getHits();
        if (hits!=null){
          for (BrowseHit hit : hits){
          hit.setDocid(hit.getDocid()+totalDocs);
          }
        }
        iteratorList.add(Arrays.asList(res.getHits()).iterator());
       
        Map<String,FacetAccessible> facetMap = res.getFacetMap();
        if (facetMap!=null){
          facetList.add(facetMap);
        }
        //resultList.add(res);
        numHits += res.getNumHits();
        totalDocs += res.getTotalDocs();
      }
      catch (InterruptedException e) { logger.error(e.getMessage(),e); }
      catch (ExecutionException e) { logger.error(e.getMessage(),e); }
    }
       
        Map<String,FacetAccessible> mergedFacetMap = ListMerger.mergeSimpleFacetContainers(facetList,req);
        Comparator<BrowseHit> comparator = new Comparator<BrowseHit>(){
          public int compare(BrowseHit o1, BrowseHit o2) {
        Comparable c1=o1.getComparable();
        Comparable c2=o2.getComparable();
        if (c1==null || c2==null){
          return o2.getDocid() - o1.getDocid();
        }
        return c1.compareTo(c2);
      }
         
        };
       
        List<BrowseHit> mergedList = req.getCount() > 0 ? ListMerger.mergeLists(req.getOffset(), req.getCount(), iteratorList.toArray(new Iterator[iteratorList.size()]), comparator) : Collections.EMPTY_LIST;
        BrowseHit[] hits = mergedList.toArray(new BrowseHit[mergedList.size()]);
        long end = System.currentTimeMillis();
       
        BrowseResult merged = new BrowseResult();
        merged.setHits(hits);
        merged.setNumHits(numHits);
        merged.setTotalDocs(totalDocs);
        merged.setTime(end-start);
        merged.addAll(mergedFacetMap);
        return merged;
  }
View Full Code Here


        merged.addAll(mergedFacetMap);
        return merged;
  }
 
  private static BrowseResult parseResponse(QueryResponse res) throws UnsupportedEncodingException{
    BrowseResult result = new BrowseResult();
   
    result.setTime(res.getElapsedTime());
    List<FacetField> facetFields = res.getFacetFields();
    if (facetFields!=null){
      Map<String,FacetAccessible> facetMap = new HashMap<String,FacetAccessible>();
      for (FacetField ff : facetFields){
        String fieldName = ff.getName();
        List<Count> countList = ff.getValues();
        if (countList!=null){
          BrowseFacet[] facets = new BrowseFacet[countList.size()];
          int i=0;
          for (Count count : countList){
            facets[i++]=new BrowseFacet(count.getName(),(int)count.getCount());
          }
          facetMap.put(fieldName, new MappedFacetAccessible(facets));
        }
      }
      result.addAll(facetMap);
    }
   
    SolrDocumentList solrDocs = res.getResults();
    if (solrDocs!=null){
      result.setNumHits((int)solrDocs.getNumFound());
      ArrayList<BrowseHit> hits = new ArrayList<BrowseHit>(solrDocs.size());
      for (SolrDocument doc : solrDocs){
        BrowseHit hit = new BrowseHit();
        Map<String,String[]> fieldMap = new HashMap<String,String[]>();
        Collection<String> fieldNames = doc.getFieldNames();
        for (String fn : fieldNames){
          Collection<String> fvals = doc.getFieldNames();
          fieldMap.put(fn, fvals.toArray(new String[fvals.size()]));
        }
        hit.setFieldValues(fieldMap);
        hits.add(hit);
      }
      result.setHits(hits.toArray(new BrowseHit[hits.size()]));
    }
   
    return result;
  }
View Full Code Here

      {
        throw new IllegalArgumentException("both offset and count must be > 0: " + offset + "/" + count);
      }

      final Collector collector = senseiRequest.buildCollector(req.getQuery());
      BrowseResult res = null;
      BrowseHit[] hits = null;

      ScoreDoc[] scoreDocs = null;
      float [][] features = null;
      int totalHits;

      if (collector == null) {

        if (senseiRequest.isSimpleRelevance())
        {
          browser.setSimilarity(new SimpleTFSimilarity());
        }
        res = browser.browse(req);
        hits = res.getHits();
      }
      else {
        Map<String, FacetAccessible> facetCollectors = new HashMap<String, FacetAccessible>();
        Weight w = req.getQuery().createWeight(browser);
        browser.browse(req, w, collector, facetCollectors, offset);

        try {
          /**
           * A custom collector must implement topDocs() method and a getHitsFeatures() method.
           */
          scoreDocs = (ScoreDoc[]) collector.getClass().getMethod(TOP_DOCS_METHOD).invoke(collector);
          features = (float[][]) collector.getClass().getMethod(GET_HITS_FEATURES_METHOD).invoke(collector);
          hits = new BrowseHit[scoreDocs.length];
          Map<String, FacetHandler<?>> facetHandlerMap = browser.getFacetHandlerMap();

          int i = 0;

          for (ScoreDoc doc : scoreDocs) {
            BrowseHit hit = new BrowseHit();
            hit.setScore(doc.score);
            hit.setDocid(doc.doc);

            Map<String,String[]> map = new HashMap<String,String[]>();
            Map<String,Object[]> rawMap = new HashMap<String,Object[]>();

            for (Map.Entry<String, FacetHandler<?>> entry : facetHandlerMap.entrySet()) {
              map.put(entry.getKey(), browser.getFieldVal(doc.doc, entry.getKey()));
              rawMap.put(entry.getKey(), browser.getRawFieldVal(doc.doc, entry.getKey()));
            }

            hit.setFieldValues(map);
            hit.setRawFieldValues(rawMap);
            hits[i++] = hit;
          }

          res = new BrowseResult();
          res.setHits(hits);
          res.addAll(facetCollectors);
          res.setTid(req.getTid());

          totalHits = (Integer) collector.getClass().getMethod(GET_TOTAL_HITS_METHOD).invoke(collector);
          res.setNumHits(totalHits);
          res.setNumGroups(totalHits);
        } catch (Exception e) {
          logger.error(e.getMessage(), e);
        }

      }

      if (req.getMapReduceWrapper() != null) {
        result.setMapReduceResult(req.getMapReduceWrapper().getResult());
      }

      SenseiHit[] senseiHits = new SenseiHit[hits.length];
      Set<String> selectSet = senseiRequest.getSelectSet();
      for (int i = 0; i < hits.length; i++)
      {
        BrowseHit hit = hits[i];
        SenseiHit senseiHit = new SenseiHit();

        int docid = hit.getDocid();
        SubReaderInfo<BoboIndexReader> readerInfo = subReaderAccessor.getSubReaderInfo(docid);
        Long uid = (Long)hit.getRawField(PARAM_RESULT_HIT_UID);
        if (uid == null)
          uid = ((ZoieIndexReader<BoboIndexReader>) readerInfo.subreader.getInnerReader()).getUID(readerInfo.subdocid);
        senseiHit.setUID(uid);
        senseiHit.setDocid(docid);
        senseiHit.setScore(hit.getScore());
        senseiHit.setComparable(hit.getComparable());
        if (selectSet != null && selectSet.size() != 0)
        {
          // Clear the data those are not used:
          if (hit.getFieldValues() != null)
          {
            Iterator<String> iter = hit.getFieldValues().keySet().iterator();
            while (iter.hasNext())
            {
              if (!selectSet.contains(iter.next()))
              {
                iter.remove();
              }
            }
          }
          if (hit.getRawFieldValues() != null)
          {
            Iterator<String> iter = hit.getRawFieldValues().keySet().iterator();
            while (iter.hasNext())
            {
              if (!selectSet.contains(iter.next()))
              {
                iter.remove();
              }
            }
          }
        }

        if (features != null) {
          senseiHit.setFeatures(features[i]);
        }

        senseiHit.setFieldValues(hit.getFieldValues());
        senseiHit.setRawFieldValues(hit.getRawFieldValues());
        senseiHit.setStoredFields(hit.getStoredFields());
        senseiHit.setExplanation(hit.getExplanation());
        senseiHit.setGroupField(hit.getGroupField());
        senseiHit.setGroupValue(hit.getGroupValue());
        senseiHit.setRawGroupValue(hit.getRawGroupValue());
        senseiHit.setGroupHitsCount(hit.getGroupHitsCount());
        senseiHit.setTermFreqMap(hit.getTermFreqMap());

        senseiHits[i] = senseiHit;
      }
      result.setHits(senseiHits);
      result.setNumHits(res.getNumHits());
      result.setNumGroups(res.getNumGroups());
      result.setGroupAccessibles(res.getGroupAccessibles());
      result.setSortCollector(res.getSortCollector());
      result.setTotalDocs(browser.numDocs());
     
      result.addAll(res.getFacetMap());
     
      // Defer the closing of facetAccessibles till result merging time.
     
      // Collection<FacetAccessible> facetAccessibles = facetMap.values();
      // for (FacetAccessible facetAccessible : facetAccessibles){
View Full Code Here

    _closeReader = closeReader;
  }

  @Override
  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 {
        browser = new BoboBrowser(_reader);
View Full Code Here

    try {
      browser = new BoboBrowser(_boboReader);
      return browser.browse(req);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      return new BrowseResult();
    } finally {
      if (browser != null) {
        try {
          browser.close();
        } catch (IOException e) {
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

    Query query = qbuilder.parseQuery(qstring, df);
    Sort sort = qbuilder.parseSort(sortString);
    BrowseRequest br = null;
    try {
      br=BoboRequestBuilder.buildRequest(params,query,sort);
      BrowseResult result=_svc.browse(br);
      res.setCharacterEncoding("UTF-8");
      Writer writer=res.getWriter();
     
        try{
          String val=BrowseJSONSerializer.serialize(result);
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.