Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseHit


public class BrowseHitConverter implements Converter {

  public void marshal(Object obj, HierarchicalStreamWriter writer,
      MarshallingContext ctx) {
    writer.startNode("hit");
    BrowseHit hit=(BrowseHit)obj;
    writer.addAttribute("score", String.valueOf(hit.getScore()));
    writer.addAttribute("docid", String.valueOf(hit.getDocid()));

   
    Map<String,String[]> fieldVals=hit.getFieldValues();
    writer.addAttribute("numfields", fieldVals==null ? "0" : String.valueOf(fieldVals.size()));
   
    if (fieldVals!=null)
    {
     
View Full Code Here


    writer.endNode();
  }

  public Object unmarshal(HierarchicalStreamReader reader,
      UnmarshallingContext ctx) {
    BrowseHit hit=new BrowseHit();
    reader.moveDown();
    String scoreString=reader.getAttribute("score");
    if (scoreString!=null){
      hit.setScore(Float.parseFloat(scoreString));
    }
    String docidString=reader.getAttribute("docid");
    if (docidString!=null){
      hit.setDocid(Integer.parseInt(docidString));
    }
   
    int numFields=0;
    String fieldCountString=reader.getAttribute("numfields");
    if (fieldCountString!=null){
      numFields=Integer.parseInt(fieldCountString);
    }
   
    Map<String,String[]> fieldVals=new HashMap<String,String[]>();
    hit.setFieldValues(fieldVals);
    for (int i=0;i<numFields;++i){
      reader.moveDown();
      String fieldname=reader.getNodeName();
      String fieldval = reader.getValue();
      String s2=fieldval.substring(1,fieldval.length()-1);
View Full Code Here

      try {
        boboBrowser=newBrowser();
       
          result = boboBrowser.browse(br);
          assertEquals(1,result.getNumHits());
          BrowseHit hit = result.getHits()[0];
          Document storedFields = hit.getStoredFields();
          assertNotNull(storedFields);
         
          String[] values = storedFields.getValues("testStored");
          assertNotNull(values);
          assertEquals(1, values.length);
View Full Code Here

      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];
          Document storedFields = hit.getStoredFields();
          assertNotNull(storedFields);
         
          String stored = storedFields.get("testStored");
          assertTrue("stored".equals(stored));
         
View Full Code Here

      try {
        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();
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));
      }
      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()));
        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

      return new PathFacetIterator(new ArrayList<BrowseFacet>(_data.values()));
    }
  }
 
  public static BrowseHit convert(BrowseResultBPO.Hit hit){
    BrowseHit bhit = new BrowseHit();
    bhit.setDocid(hit.getDocid());
    bhit.setScore(hit.getScore());
    List<BrowseResultBPO.FieldVal> fieldValueList = hit.getFieldValuesList();
    Map<String,String[]> fielddata = new HashMap<String,String[]>();
    for (BrowseResultBPO.FieldVal fieldVal : fieldValueList){
      List<String> valList = fieldVal.getValsList();
      fielddata.put(fieldVal.getName(), valList.toArray(new String[valList.size()]));
    }
    bhit.setFieldValues(fielddata);
    return bhit;
  }
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

    try {
      boboBrowser = newBrowser();

      result = boboBrowser.browse(br);
      assertEquals(1, result.getNumHits());
      BrowseHit hit = result.getHits()[0];
      List<SerializableField> storedFields = hit.getStoredFields();
      assertNotNull(storedFields);

      List<String> fieldValues = new ArrayList<String>();
      for (SerializableField field : storedFields) {
        if (field.name().equals("testStored") && field.stringValue() != null) {
View Full Code Here

    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];
      String stored = hit.getFieldStringValue("testStored");
      assertTrue("stored".equals(stored));
    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
View Full Code Here

TOP

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

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.