Package com.browseengine.bobo.api

Examples of com.browseengine.bobo.api.BrowseRequest


    return facetHandlers;
  }

  public void testFacetNameForSimpleFacetHandler() throws Exception {
    BrowseRequest br = new BrowseRequest();
    br.setCount(20);
    br.setOffset(0);

    BrowseSelection colorSel = new BrowseSelection("mycolor");
    colorSel.addValue("yellow");
    br.addSelection(colorSel);

    BrowseSelection makeSel = new BrowseSelection("make");
    makeSel.addValue("rav4");
    br.addSelection(makeSel);

    FacetSpec spec = new FacetSpec();
    spec.setExpandSelection(true);
    spec.setOrderBy(FacetSortSpec.OrderHitsDesc);
    spec.setMaxCount(15);

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

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    int expectedHitNum = 3;
    try {
View Full Code Here


    return facetHandlers;
  }

  public void testNotValuesForSimpleFacetHandler() throws Exception {
    BrowseRequest br = new BrowseRequest();
    br.setCount(20);
    br.setOffset(0);

    BrowseSelection colorSel = new BrowseSelection("color");
    colorSel.addValue("red");
    br.addSelection(colorSel);

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

    BrowseResult result = null;
    BoboBrowser boboBrowser = null;
    int expectedHitNum = (_documentSize / 2) - 1;
    try {
View Full Code Here

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

    BooleanQuery bq = new BooleanQuery();
    bq.add(shapeQ, Occur.SHOULD);
    bq.add(colorQ, Occur.SHOULD);

    BrowseRequest br = new BrowseRequest();
    br.setSort(new SortField[] { SortField.FIELD_SCORE });
    br.setQuery(bq);
    br.setOffset(0);
    br.setCount(10);

    BrowseResult res = doTest(br, 6, null, new String[] { "4", "1", "7", "5", "3", "2" });
    BrowseHit[] hits = res.getHits();
    float[] scores = new float[] { 13, 11, 11, 10, 4.5f, 2.5f }; // default coord = 1/2
    for (int i = 0; i < hits.length; ++i) {
View Full Code Here

    HashMap<String, Float> map2 = new HashMap<String, Float>();
    map2.put("rabbit", 100.0f);
    map2.put("dog", 50.0f);
    FacetTermQuery tagQ = new FacetTermQuery(sel2, map2);

    BrowseRequest br = new BrowseRequest();
    br.setQuery(colorQ);
    br.setOffset(0);
    br.setCount(10);

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

    // BoboBrowser b = newBrowser();
    // Explanation expl = b.explain(colorQ, 0);

    br.setQuery(tagQ);
    doTest(br, 4, null, new String[] { "7", "1", "3", "2" });
    // expl = b.explain(tagQ, 6);

  }
View Full Code Here

    HashMap<String, Float> map2 = new HashMap<String, Float>();
    map2.put("rabbit", 100.0f);
    map2.put("dog", 50.0f);
    FacetTermQuery tagQ = new FacetTermQuery(sel2, map2);

    BrowseRequest br = new BrowseRequest();

    br.setOffset(0);
    br.setCount(10);

    BooleanQuery bq = new BooleanQuery(true);
    bq.add(colorQ, Occur.SHOULD);
    bq.add(tagQ, Occur.SHOULD);

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

  }
View Full Code Here

    HashMap<String, Float> map = new HashMap<String, Float>();
    map.put("000002", 100.0f);
    map.put("000010", 50.0f);
    FacetTermQuery numberQ = new FacetTermQuery(sel, map);

    BrowseRequest br = new BrowseRequest();
    br.setQuery(numberQ);
    br.setOffset(0);
    br.setCount(10);

    doTest(br, 4, null, new String[] { "5", "2", "1", "6" });
  }
View Full Code Here

    boostMaps.put("tag", map);

    Query q = new ScoreAdjusterQuery(new MatchAllDocsQuery(), new FacetBasedBoostScorerBuilder(
        boostMaps));

    BrowseRequest br = new BrowseRequest();
    br.setQuery(q);
    br.setOffset(0);
    br.setCount(10);
    br.setSort(new SortField[] { SortField.FIELD_SCORE });
    BoboBrowser b = newBrowser();

    BrowseResult r = b.browse(br);

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

    String[] ranges = new String[] { "[2001/01/01 TO 2001/12/30]", "[2007/01/01 TO 2007/12/30]" };
    FilteredRangeFacetHandler handler = new FilteredRangeFacetHandler("filtered_date", "date",
        Arrays.asList(ranges));
    browser.setFacetHandler(handler);

    BrowseRequest req = new BrowseRequest();
    req.setFacetSpec("filtered_date", new FacetSpec());
    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put(
      "filtered_date",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("[2001/01/01 TO 2001/12/30]", 1),
          new BrowseFacet("[2007/01/01 TO 2007/12/30]", 1) }));
View Full Code Here

    doTest(browser, req, 7, answer, null);
  }

  public void testCustomFacetSort() throws Exception {
    BrowseRequest req = new BrowseRequest();
    FacetSpec numberSpec = new FacetSpec();
    numberSpec.setCustomComparatorFactory(new ComparatorFactory() {

      @Override
      public IntComparator newComparator(final FieldValueAccessor fieldValueAccessor,
          final BigSegmentedArray counts) {

        return new IntComparator() {

          @Override
          public int compare(Integer v1, Integer v2) {
            Integer size1 = (Integer) fieldValueAccessor.getRawValue(v1);
            Integer size2 = (Integer) fieldValueAccessor.getRawValue(v2);

            int val = size1 - size2;
            if (val == 0) {
              val = counts.get(v1) - counts.get(v2);
            }
            return val;
          }

          @Override
          public int compare(int v1, int v2) {
            int size1 = (Integer) fieldValueAccessor.getRawValue(v1);
            int size2 = (Integer) fieldValueAccessor.getRawValue(v2);

            int val = size1 - size2;
            if (val == 0) {
              val = counts.get(v1) - counts.get(v2);
            }
            return val;
          }
        };
      }

      @Override
      public Comparator<BrowseFacet> newComparator() {
        return new Comparator<BrowseFacet>() {
          @Override
          public int compare(BrowseFacet o1, BrowseFacet o2) {
            int v1 = Integer.parseInt(o1.getValue());
            int v2 = Integer.parseInt(o2.getValue());
            int val = v2 - v1;
            if (val == 0) {
              val = o2.getFacetValueHitCount() - o1.getFacetValueHitCount();
            }
            return val;
          }
        };
      }
    });
    numberSpec.setOrderBy(FacetSortSpec.OrderByCustom);
    numberSpec.setMaxCount(3);
    req.setFacetSpec("number", numberSpec);

    HashMap<String, List<BrowseFacet>> answer = new HashMap<String, List<BrowseFacet>>();
    answer.put(
      "number",
      Arrays.asList(new BrowseFacet[] { new BrowseFacet("2130", 1), new BrowseFacet("1013", 1),
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.