Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseResult


    br.setFacetSpec("mycolor", spec);
    br.setFacetSpec("id", spec);
    br.setFacetSpec("make", spec);

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    int expectedHitNum = 3;
    try {
      Directory ramIndexDir = createIndex();
      DirectoryReader srcReader = DirectoryReader.open(ramIndexDir);
      boboBrowser = new BoboBrowser(BoboMultiReader.getInstance(srcReader, _facetHandlers));
      result = boboBrowser.browse(br);

      assertEquals(expectedHitNum, result.getNumHits());
    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here


    BrowseSelection idSel = new BrowseSelection("id");
    idSel.addNotValue("0");
    br.addSelection(idSel);

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    int expectedHitNum = (_documentSize / 2) - 1;
    try {
      Directory ramIndexDir = createIndex();
      DirectoryReader srcReader = DirectoryReader.open(ramIndexDir);
      boboBrowser = new BoboBrowser(BoboMultiReader.getInstance(srcReader, _facetHandlers));
      result = boboBrowser.browse(br);

      assertEquals(expectedHitNum, result.getNumHits());

      StringBuilder buffer = new StringBuilder();
      BrowseHit[] hits = result.getHits();

      for (int i = 0; i < hits.length; ++i) {
        int expectedID = (i + 1) * 2;
        assertEquals(expectedID, Integer.parseInt(hits[i].getField("id")));
        if (i != 0) {
          buffer.append('\n');
        }
        buffer.append("id=" + hits[i].getField("id") + "," + "color=" + hits[i].getField("color"));
      }
      log.info(buffer.toString());

    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

  }

  public void testNotValuesForRangeFacetHandler() throws Exception {
    System.out.println("testNotValuesForRangeFacetHandler");
    BrowseResult result = null;
    BoboBrowser boboBrowser = null;

    try {
      Directory ramIndexDir = createIndexTwo();
      DirectoryReader srcReader = DirectoryReader.open(ramIndexDir);
      boboBrowser = new BoboBrowser(BoboMultiReader.getInstance(srcReader, _facetHandlers));

      BrowseRequest br = new BrowseRequest();
      br.setCount(20);
      br.setOffset(0);

      if (_idRanges == null) {
        log.error("_idRanges cannot be null in order to test NOT on RangeFacetHandler");
      }
      BrowseSelection idSel = new BrowseSelection("idRange");
      idSel.addNotValue(_idRanges[0]);
      int expectedHitNum = 1;
      br.addSelection(idSel);
      BooleanQuery q = new BooleanQuery();
      q.add(NumericRangeQuery.newIntRange("NUM", 10, 10, true, true), Occur.MUST_NOT);
      q.add(new MatchAllDocsQuery(), Occur.MUST);
      br.setQuery(q);

      result = boboBrowser.browse(br);

      assertEquals(expectedHitNum, result.getNumHits());
      for (int i = 0; i < result.getNumHits(); i++) {
        System.out.println(result.getHits()[i]);
      }

    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    BrowseSelection colorSel = new BrowseSelection("testStored");
    colorSel.addValue("stored");
    br.addSelection(colorSel);
    br.setFetchStoredFields(true);

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    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) {
          fieldValues.add(field.stringValue());
        }
      }
      String[] values = fieldValues.toArray(new String[fieldValues.size()]);

      assertNotNull(values);
      assertEquals(1, values.length);
      assertTrue("stored".equals(values[0]));

    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    BrowseSelection sizeSel = new BrowseSelection("size");
    sizeSel.addValue("[4 TO 4]");
    br.addSelection(sizeSel);

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    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) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    br.addSelection(sizeSel);

    br.setTermVectorsToFetch(new HashSet<String>(Arrays.asList(new String[] { "tv", "tvPositions",
        "tvOffsets", "tvPositionsAndOffsets" })));

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    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");
      assertNotNull(tv);

      assertEquals("bobo", tv.get(0).term);
      assertEquals(2, tv.get(0).freq.intValue());
      assertEquals(null, tv.get(0).positions);
      assertEquals(null, tv.get(0).startOffsets);
      assertEquals(null, tv.get(0).endOffsets);

      assertEquals("lucene", tv.get(1).term);
      assertEquals(3, tv.get(1).freq.intValue());
      assertEquals(null, tv.get(1).positions);
      assertEquals(null, tv.get(1).startOffsets);
      assertEquals(null, tv.get(1).endOffsets);

      assertEquals("test", tv.get(2).term);
      assertEquals(1, tv.get(2).freq.intValue());
      assertEquals(null, tv.get(2).positions);
      assertEquals(null, tv.get(2).startOffsets);
      assertEquals(null, tv.get(2).endOffsets);

      tv = tvMap.get("tvPositions");
      assertNotNull(tv);

      assertEquals("bobo", tv.get(0).term);
      assertEquals(2, tv.get(0).freq.intValue());
      List<Integer> positions = new ArrayList<Integer>(Arrays.asList(0, 1));
      assertEquals(positions, tv.get(0).positions);
      List<Integer> startOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1));
      assertEquals(startOffsets, tv.get(0).startOffsets);
      List<Integer> endOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1));
      assertEquals(endOffsets, tv.get(0).endOffsets);

      assertEquals("lucene", tv.get(1).term);
      assertEquals(3, tv.get(1).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(2, 3, 4));
      assertEquals(positions, tv.get(1).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
      assertEquals(startOffsets, tv.get(1).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
      assertEquals(endOffsets, tv.get(1).endOffsets);

      assertEquals("test", tv.get(2).term);
      assertEquals(1, tv.get(2).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(5));
      assertEquals(positions, tv.get(2).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(-1));
      assertEquals(startOffsets, tv.get(2).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(-1));
      assertEquals(endOffsets, tv.get(2).endOffsets);

      tv = tvMap.get("tvOffsets");
      assertNotNull(tv);

      assertEquals("bobo", tv.get(0).term);
      assertEquals(2, tv.get(0).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(-1, -1));
      assertEquals(positions, tv.get(0).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(0, 5));
      assertEquals(startOffsets, tv.get(0).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(4, 9));
      assertEquals(endOffsets, tv.get(0).endOffsets);

      assertEquals("lucene", tv.get(1).term);
      assertEquals(3, tv.get(1).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
      assertEquals(positions, tv.get(1).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(10, 17, 24));
      assertEquals(startOffsets, tv.get(1).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(16, 23, 30));
      assertEquals(endOffsets, tv.get(1).endOffsets);

      assertEquals("test", tv.get(2).term);
      assertEquals(1, tv.get(2).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(-1));
      assertEquals(positions, tv.get(2).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(31));
      assertEquals(startOffsets, tv.get(2).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(35));
      assertEquals(endOffsets, tv.get(2).endOffsets);

      tv = tvMap.get("tvPositionsAndOffsets");
      assertNotNull(tv);
      assertEquals("bobo", tv.get(0).term);
      assertEquals(2, tv.get(0).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(0, 1));
      assertEquals(positions, tv.get(0).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(0, 5));
      assertEquals(startOffsets, tv.get(0).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(4, 9));
      assertEquals(endOffsets, tv.get(0).endOffsets);

      assertEquals("lucene", tv.get(1).term);
      assertEquals(3, tv.get(1).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(2, 3, 4));
      assertEquals(positions, tv.get(1).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(10, 17, 24));
      assertEquals(startOffsets, tv.get(1).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(16, 23, 30));
      assertEquals(endOffsets, tv.get(1).endOffsets);

      assertEquals("test", tv.get(2).term);
      assertEquals(1, tv.get(2).freq.intValue());
      positions = new ArrayList<Integer>(Arrays.asList(5));
      assertEquals(positions, tv.get(2).positions);
      startOffsets = new ArrayList<Integer>(Arrays.asList(31));
      assertEquals(startOffsets, tv.get(2).startOffsets);
      endOffsets = new ArrayList<Integer>(Arrays.asList(35));
      assertEquals(endOffsets, tv.get(2).endOffsets);
    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

  public void testRawDataRetrieval() throws Exception {
    BrowseRequest br = new BrowseRequest();
    br.setCount(10);
    br.setOffset(0);
    br.setSort(new SortField[] { new SortField("date", SortField.Type.CUSTOM, false) });
    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd");
    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();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    return doTest((BoboBrowser) null, req, numHits, choiceMap, ids);
  }

  private BrowseResult doTest(BoboBrowser boboBrowser, BrowseRequest req, int numHits,
      HashMap<String, List<BrowseFacet>> choiceMap, String[] ids) {
    BrowseResult result = null;
    try {
      if (boboBrowser == null) {
        boboBrowser = newBrowser();
      }
      result = boboBrowser.browse(req);
      doTest(result, req, numHits, choiceMap, ids);
      return result;// result;
    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (IOException ioe) {
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    doTest(br, 7, null, new String[] { "5", "4", "6", "3", "2", "1", "7" });

    // now test with serialization

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    try {
      boboBrowser = newBrowser();

      result = boboBrowser.browse(br);

      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream oout = new ObjectOutputStream(bout);
      oout.writeObject(result);
      oout.flush();
      byte[] serialized = bout.toByteArray();

      ByteArrayInputStream bin = new ByteArrayInputStream(serialized);
      ObjectInputStream oin = new ObjectInputStream(bin);

      result = (BrowseResult) oin.readObject();

      doTest(result, br, 7, null, new String[] { "5", "4", "6", "3", "2", "1", "7" });

    } catch (BrowseException e) {
      e.printStackTrace();
      fail(e.getMessage());
    } catch (Exception ioe) {
      ioe.printStackTrace();
      fail(ioe.getMessage());
    } finally {
      if (boboBrowser != null) {
        try {
          if (result != null) result.close();
          boboBrowser.close();
        } catch (IOException e) {
          fail(e.getMessage());
        }
      }
View Full Code Here

    br.setOffset(0);
    br.setFacetSpec("number", new FacetSpec());

    BoboBrowser browser = newBrowser();

    BrowseResult res = browser.browse(br);
    FacetAccessible facetAccessor = res.getFacetAccessor("number");
    BrowseFacet facet = facetAccessor.getFacet("5");

    assertEquals(facet.getValue(), "0005");
    assertEquals(facet.getFacetValueHitCount(), 1);
    res.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.