Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseHit$SerializableExplanation


    try {
      boboBrowser = newBrowser();

      result = boboBrowser.browse(br);
      assertEquals(1, result.getNumHits());
      BrowseHit hit = result.getHits()[0];
      assertNull(hit.getStoredFields());

      br.setFetchStoredFields(true);
      result = boboBrowser.browse(br);
      assertEquals(1, result.getNumHits());
      hit = result.getHits()[0];
      Map<String, List<BoboTerm>> tvMap = hit.getTermVectorMap();
      assertNotNull(tvMap);

      assertEquals(4, tvMap.size());

      List<BoboTerm> tv = tvMap.get("tv");
View Full Code Here


      boboBrowser = newBrowser();

      result = boboBrowser.browse(br);
      assertEquals(7, result.getNumHits());

      BrowseHit hit = result.getHits()[0];
      assertEquals(0, hit.getDocid());
      Object lowDate = hit.getRawField("date");
      Date date = dateFormatter.parse("2000/01/01");
      assertTrue(lowDate.equals(date.getTime()));

      hit = result.getHits()[6];
      assertEquals(5, hit.getDocid());
      Object highDate = hit.getRawField("date");
      date = dateFormatter.parse("2007/08/01");
      assertTrue(highDate.equals(date.getTime()));
    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    Collection<FacetHandler<?>> facetHandlers= facetHandlerMap.values();
    for (int i =scoreDocs.length-1; i >=0 ; i--)
    {
      MyScoreDoc fdoc = scoreDocs[i];
      BoboIndexReader reader = fdoc.reader;
      BrowseHit hit=new BrowseHit();
      if (fetchStoredFields)
      {
        hit.setStoredFields(reader.document(fdoc.doc));
      }
      if (termVectorsToFetch!=null && termVectorsToFetch.size()>0){
        Map<String,TermFrequencyVector> tvMap = new HashMap<String,TermFrequencyVector>();
        hit.setTermFreqMap(tvMap);
        for (String field : termVectorsToFetch){
          TermFreqVector tv = reader.getTermFreqVector(fdoc.doc, field);
          if (tv!=null){
            int[] freqs = tv.getTermFrequencies();
            String[] terms = tv.getTerms();
            tvMap.put(field, new TermFrequencyVector(terms, freqs));
          }
        }
      }
      Map<String,String[]> map = new HashMap<String,String[]>();
      Map<String,Object[]> rawMap = new HashMap<String,Object[]>();
      for (FacetHandler<?> facetHandler : facetHandlers)
      {
          map.put(facetHandler.getName(),facetHandler.getFieldValues(reader,fdoc.doc));
          rawMap.put(facetHandler.getName(),facetHandler.getRawFieldValues(reader,fdoc.doc));
      }
      hit.setFieldValues(map);
      hit.setRawFieldValues(rawMap);
      hit.setDocid(fdoc.doc+fdoc.queue.base);
      hit.setScore(fdoc.score);
      hit.setComparable(fdoc.getValue());
      if (groupBy != null) {
        hit.setGroupField(groupBy.getName());
        hit.setGroupValue(hit.getField(groupBy.getName()));
        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (groupAccessibles != null &&
            hit.getGroupValue() != null &&
            groupAccessibles != null &&
            groupAccessibles.length > 0) {
          BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

    Collection<FacetHandler<?>> facetHandlers= facetHandlerMap.values();
    for (int i =scoreDocs.length-1; i >=0 ; i--)
    {
      MyScoreDoc fdoc = scoreDocs[i];
      BoboIndexReader reader = fdoc.reader;
      BrowseHit hit=new BrowseHit();
      if (fetchStoredFields)
      {
        hit.setStoredFields(reader.document(fdoc.doc));
      }
      if (termVectorsToFetch!=null && termVectorsToFetch.size()>0){
        Map<String,TermFrequencyVector> tvMap = new HashMap<String,TermFrequencyVector>();
        hit.setTermFreqMap(tvMap);
        for (String field : termVectorsToFetch){
          TermFreqVector tv = reader.getTermFreqVector(fdoc.doc, field);
          if (tv!=null){
            int[] freqs = tv.getTermFrequencies();
            String[] terms = tv.getTerms();
            tvMap.put(field, new TermFrequencyVector(terms, freqs));
          }
        }
      }
      Map<String,String[]> map = new HashMap<String,String[]>();
      Map<String,Object[]> rawMap = new HashMap<String,Object[]>();
      for (FacetHandler<?> facetHandler : facetHandlers)
      {
          map.put(facetHandler.getName(),facetHandler.getFieldValues(reader,fdoc.doc));
          rawMap.put(facetHandler.getName(),facetHandler.getRawFieldValues(reader,fdoc.doc));
      }
      hit.setFieldValues(map);
      hit.setRawFieldValues(rawMap);
      hit.setDocid(fdoc.doc+fdoc.queue.base);
      hit.setScore(fdoc.score);
      hit.setComparable(fdoc.getValue());
      if (groupBy != null) {
        hit.setGroupValue(hit.getField(groupBy.getName()));
        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (hit.getGroupValue() != null && groupAccessible != null) {
          BrowseFacet facet = groupAccessible.getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

    BrowseHit[] hits = new BrowseHit[scoreDocs.length];
    Collection<FacetHandler<?>> facetHandlers = facetHandlerMap.values();
    for (int i = scoreDocs.length - 1; i >= 0; i--) {
      MyScoreDoc fdoc = scoreDocs[i];
      BoboSegmentReader reader = fdoc.reader;
      BrowseHit hit = new BrowseHit();
      if (fetchStoredFields) {
        hit.setStoredFields(reader.document(fdoc.doc));
      }
      if (termVectorsToFetch != null && termVectorsToFetch.size() > 0) {
        Map<String, List<BoboTerm>> tvMap = new HashMap<String, List<BoboTerm>>();
        hit.setTermVectorMap(tvMap);
        Fields fds = reader.getTermVectors(fdoc.doc);
        for (String field : termVectorsToFetch) {
          Terms terms = fds.terms(field);
          if (terms == null) {
            continue;
          }
          TermsEnum termsEnum = terms.iterator(null);
          BytesRef text;
          DocsAndPositionsEnum docsAndPositions = null;
          List<BoboTerm> boboTermList = new ArrayList<BoboTerm>();
          while ((text = termsEnum.next()) != null) {
            BoboTerm boboTerm = new BoboTerm();
            boboTerm.term = text.utf8ToString();
            boboTerm.freq = (int)termsEnum.totalTermFreq();
            docsAndPositions = termsEnum.docsAndPositions(null, docsAndPositions);
            if (docsAndPositions != null) {
              docsAndPositions.nextDoc();
              boboTerm.positions = new ArrayList<Integer>();
              boboTerm.startOffsets = new ArrayList<Integer>();
              boboTerm.endOffsets = new ArrayList<Integer>();
              for (int t = 0; t < boboTerm.freq; ++t) {
                boboTerm.positions.add(docsAndPositions.nextPosition());
                boboTerm.startOffsets.add(docsAndPositions.startOffset());
                boboTerm.endOffsets.add(docsAndPositions.endOffset());
              }
            }
            boboTermList.add(boboTerm);
          }
          tvMap.put(field, boboTermList);
        }
      }
      Map<String, String[]> map = new HashMap<String, String[]>();
      Map<String, Object[]> rawMap = new HashMap<String, Object[]>();
      for (FacetHandler<?> facetHandler : facetHandlers) {
        map.put(facetHandler.getName(), facetHandler.getFieldValues(reader, fdoc.doc));
        rawMap.put(facetHandler.getName(), facetHandler.getRawFieldValues(reader, fdoc.doc));
      }
      hit.setFieldValues(map);
      hit.setRawFieldValues(rawMap);
      hit.setDocid(fdoc.doc + fdoc.queue.base);
      hit.setScore(fdoc.score);
      hit.setComparable(fdoc.getValue());
      if (groupBy != null) {
        hit.setGroupField(groupBy.getName());
        hit.setGroupValue(hit.getField(groupBy.getName()));
        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (groupAccessibles != null && hit.getGroupValue() != null && groupAccessibles != null
            && groupAccessibles.length > 0) {
          BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

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

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

    BrowseHit[] hits = new BrowseHit[scoreDocs.length];
    Collection<FacetHandler<?>> facetHandlers = facetHandlerMap.values();
    for (int i = scoreDocs.length - 1; i >= 0; i--) {
      MyScoreDoc fdoc = scoreDocs[i];
      BoboSegmentReader reader = fdoc.reader;
      BrowseHit hit = new BrowseHit();
      if (fetchStoredFields) {
        hit.setStoredFields(reader.document(fdoc.doc));
      }
      if (termVectorsToFetch != null && termVectorsToFetch.size() > 0) {
        Map<String, TermFrequencyVector> tvMap = new HashMap<String, TermFrequencyVector>();
        hit.setTermFreqMap(tvMap);
        Fields fds = reader.getTermVectors(fdoc.doc);
        for (String field : termVectorsToFetch) {
          Terms terms = fds.terms(field);
          if (terms == null) {
            continue;
          }
          TermsEnum termsEnum = terms.iterator(null);
          List<String> texts = new ArrayList<String>();
          List<Integer> freqs = new ArrayList<Integer>();
          BytesRef text;
          while ((text = termsEnum.next()) != null) {
            texts.add(text.utf8ToString());
            int freq = (int) termsEnum.totalTermFreq();
            freqs.add(freq);
          }
          tvMap.put(field, new TermFrequencyVector(texts, freqs));
        }
      }
      Map<String, String[]> map = new HashMap<String, String[]>();
      Map<String, Object[]> rawMap = new HashMap<String, Object[]>();
      for (FacetHandler<?> facetHandler : facetHandlers) {
        map.put(facetHandler.getName(), facetHandler.getFieldValues(reader, fdoc.doc));
        rawMap.put(facetHandler.getName(), facetHandler.getRawFieldValues(reader, fdoc.doc));
      }
      hit.setFieldValues(map);
      hit.setRawFieldValues(rawMap);
      hit.setDocid(fdoc.doc + fdoc.queue.base);
      hit.setScore(fdoc.score);
      hit.setComparable(fdoc.getValue());
      if (groupBy != null) {
        hit.setGroupField(groupBy.getName());
        hit.setGroupValue(hit.getField(groupBy.getName()));
        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (groupAccessibles != null && hit.getGroupValue() != null && groupAccessibles != null
            && groupAccessibles.length > 0) {
          BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

    Collection<FacetHandler<?>> facetHandlers= facetHandlerMap.values();
    for (int i =scoreDocs.length-1; i >=0 ; i--)
    {
      MyScoreDoc fdoc = scoreDocs[i];
      BoboIndexReader reader = fdoc.reader;
      BrowseHit hit=new BrowseHit();
      if (fetchStoredFields)
      {
        hit.setStoredFields(reader.document(fdoc.doc));
      }
      if (termVectorsToFetch!=null && termVectorsToFetch.size()>0){
        Map<String,TermFrequencyVector> tvMap = new HashMap<String,TermFrequencyVector>();
        hit.setTermFreqMap(tvMap);
        for (String field : termVectorsToFetch){
          TermFreqVector tv = reader.getTermFreqVector(fdoc.doc, field);
          if (tv!=null){
            int[] freqs = tv.getTermFrequencies();
            String[] terms = tv.getTerms();
            tvMap.put(field, new TermFrequencyVector(terms, freqs));
          }
        }
      }
      Map<String,String[]> map = new HashMap<String,String[]>();
      Map<String,Object[]> rawMap = new HashMap<String,Object[]>();
      for (FacetHandler<?> facetHandler : facetHandlers)
      {
          map.put(facetHandler.getName(),facetHandler.getFieldValues(reader,fdoc.doc));
          rawMap.put(facetHandler.getName(),facetHandler.getRawFieldValues(reader,fdoc.doc));
      }
      hit.setFieldValues(map);
      hit.setRawFieldValues(rawMap);
      hit.setDocid(fdoc.doc+fdoc.queue.base);
      hit.setScore(fdoc.score);
      hit.setComparable(fdoc.getValue());
      if (groupBy != null) {
        hit.setGroupValue(hit.getField(groupBy.getName()));
        hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
        if (groupAccessibles != null &&
            hit.getGroupValue() != null &&
            groupAccessibles != null &&
            groupAccessibles.length > 0) {
          BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
          hit.setGroupHitsCount(facet.getFacetValueHitCount());
        }
      }
      hits[i] = hit;
    }
    return hits;
View Full Code Here

TOP

Related Classes of com.browseengine.bobo.api.BrowseHit$SerializableExplanation

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.