Java 类org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner 实例源码

项目:search    文件:HighlighterTest.java   
public void testNearSpanSimpleQuery() throws Exception {
  doSearching(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "beginning")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false));

  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();

  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 2);
}
项目:search    文件:HighlighterTest.java   
public void testSpanHighlighting() throws Exception {
  Query query1 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordx")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")) }, 1, false);
  Query query2 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordc")) }, 1, false);
  BooleanQuery bquery = new BooleanQuery();
  bquery.add(query1, Occur.SHOULD);
  bquery.add(query2, Occur.SHOULD);
  doSearching(bquery);
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 7);
}
项目:search    文件:HighlighterTest.java   
public void testNotSpanSimpleQuery() throws Exception {
  doSearching(new SpanNotQuery(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "shot")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false), new SpanTermQuery(
      new Term(FIELD_NAME, "john"))));
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 4);
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsConstantScore() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      if (random().nextBoolean()) {
        BooleanQuery bq = new BooleanQuery();
        bq.add(new ConstantScoreQuery(new QueryWrapperFilter(new TermQuery(
            new Term(FIELD_NAME, "kennedy")))), Occur.MUST);
        bq.add(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME, "kennedy"))), Occur.MUST);
        doSearching(bq);
      } else {
        doSearching(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME,
            "kennedy"))));
      }
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetFuzzyFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term(FIELD_NAME, "kinnedy"), 2);
      fuzzyQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(fuzzyQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this, true);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetWildCardFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      WildcardQuery wildcardQuery = new WildcardQuery(new Term(FIELD_NAME, "k?nnedy"));
      wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(wildcardQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetMidWildCardFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      WildcardQuery wildcardQuery = new WildcardQuery(new Term(FIELD_NAME, "k*dy"));
      wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(wildcardQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsPhrase() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      PhraseQuery phraseQuery = new PhraseQuery();
      phraseQuery.add(new Term(FIELD_NAME, "john"));
      phraseQuery.add(new Term(FIELD_NAME, "kennedy"));
      doSearching(phraseQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsQueryScorer() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")),
          new SpanTermQuery(new Term("contents", "kennedy")), };

      SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
      doSearching(snq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testOffByOne() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      TermQuery query = new TermQuery(new Term("data", "help"));
      Highlighter hg = new Highlighter(new SimpleHTMLFormatter(), new QueryTermScorer(query));
      hg.setTextFragmenter(new NullFragmenter());

      String match = hg.getBestFragment(analyzer, "data", "help me [54-65]");
      assertEquals("<B>help</B> me [54-65]", match);

    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsFilteredQuery() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      TermRangeFilter rf = TermRangeFilter.newStringRange("contents", "john", "john", true, true);
      SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")),
          new SpanTermQuery(new Term("contents", "kennedy")), };
      SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
      FilteredQuery fq = new FilteredQuery(snq, rf);

      doSearching(fq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsFilteredPhraseQuery() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      TermRangeFilter rf = TermRangeFilter.newStringRange("contents", "john", "john", true, true);
      PhraseQuery pq = new PhraseQuery();
      pq.add(new Term("contents", "john"));
      pq.add(new Term("contents", "kennedy"));
      FilteredQuery fq = new FilteredQuery(pq, rf);

      doSearching(fq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsMultiTerm() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      BooleanQuery booleanQuery = new BooleanQuery();
      booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "john")), Occur.SHOULD);
      PrefixQuery prefixQuery = new PrefixQuery(new Term(FIELD_NAME, "kenn"));
      prefixQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      booleanQuery.add(prefixQuery, Occur.SHOULD);

      doSearching(booleanQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetBestFragmentsWithOr() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;

      BooleanQuery query = new BooleanQuery();
      query.add(new TermQuery(new Term(FIELD_NAME, "jfk")), Occur.SHOULD);
      query.add(new TermQuery(new Term(FIELD_NAME, "kennedy")), Occur.SHOULD);

      doSearching(query);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };
  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testGetSimpleHighlight() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      doSearching(new TermQuery(new Term(FIELD_NAME, "kennedy")));
      // new Highlighter(HighlighterTest.this, new QueryTermScorer(query));

      for (int i = 0; i < hits.totalHits; i++) {
        String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME);
        TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text);
        Highlighter highlighter = getHighlighter(query, FIELD_NAME,
            HighlighterTest.this);
        String result = highlighter.getBestFragment(tokenStream, text);
        if (VERBOSE) System.out.println("\t" + result);
      }
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };
  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testMaxSizeHighlight() throws Exception {
  final MockAnalyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
  // we disable MockTokenizer checks because we will forcefully limit the 
  // tokenstream and call end() before incrementToken() returns false.
  analyzer.setEnableChecks(false);
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      doSearching(new TermQuery(new Term(FIELD_NAME, "meat")));
      TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, texts[0]);
      Highlighter highlighter = getHighlighter(query, FIELD_NAME,
          HighlighterTest.this);// new Highlighter(this, new
      // QueryTermScorer(query));
      highlighter.setMaxDocCharsToAnalyze(30);

      highlighter.getBestFragment(tokenStream, texts[0]);
      assertTrue("Setting MaxDocBytesToAnalyze should have prevented "
          + "us from finding matches for this record: " + numHighlights + " found",
          numHighlights == 0);
    }
  };

  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testMaxSizeEndHighlight() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {
    @Override
    public void run() throws Exception {
      CharacterRunAutomaton stopWords = new CharacterRunAutomaton(new RegExp("i[nt]").toAutomaton());
      TermQuery query = new TermQuery(new Term("text", "searchterm"));

      String text = "this is a text with searchterm in it";
      SimpleHTMLFormatter fm = new SimpleHTMLFormatter();
      Highlighter hg = getHighlighter(query, "text", fm);
      hg.setTextFragmenter(new NullFragmenter());
      hg.setMaxDocCharsToAnalyze(36);
      String match = hg.getBestFragment(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, stopWords), "text", text);
      assertTrue(
          "Matched text should contain remainder of text after highlighted query ",
          match.endsWith("in it"));
    }
  };
  helper.start();
}
项目:search    文件:HighlighterTest.java   
public void testNoFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      doSearching(new TermQuery(new Term(FIELD_NAME, "aninvalidquerywhichshouldyieldnoresults")));

      for (String text : texts) {
        TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text);
        Highlighter highlighter = getHighlighter(query, FIELD_NAME,
            HighlighterTest.this);
        String result = highlighter.getBestFragment(tokenStream, text);
        assertNull("The highlight result should be null for text with no query terms", result);
      }
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testNearSpanSimpleQuery() throws Exception {
  doSearching(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "beginning")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false));

  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();

  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 2);
}
项目:NYBC    文件:HighlighterTest.java   
public void testSpanHighlighting() throws Exception {
  Query query1 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordx")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")) }, 1, false);
  Query query2 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordc")) }, 1, false);
  BooleanQuery bquery = new BooleanQuery();
  bquery.add(query1, Occur.SHOULD);
  bquery.add(query2, Occur.SHOULD);
  doSearching(bquery);
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 7);
}
项目:NYBC    文件:HighlighterTest.java   
public void testNotSpanSimpleQuery() throws Exception {
  doSearching(new SpanNotQuery(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "shot")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false), new SpanTermQuery(
      new Term(FIELD_NAME, "john"))));
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 4);
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsConstantScore() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      if (random().nextBoolean()) {
        BooleanQuery bq = new BooleanQuery();
        bq.add(new ConstantScoreQuery(new QueryWrapperFilter(new TermQuery(
            new Term(FIELD_NAME, "kennedy")))), Occur.MUST);
        bq.add(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME, "kennedy"))), Occur.MUST);
        doSearching(bq);
      } else {
        doSearching(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME,
            "kennedy"))));
      }
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetFuzzyFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term(FIELD_NAME, "kinnedy"), 2);
      fuzzyQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(fuzzyQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this, true);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetWildCardFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      WildcardQuery wildcardQuery = new WildcardQuery(new Term(FIELD_NAME, "k?nnedy"));
      wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(wildcardQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetMidWildCardFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      WildcardQuery wildcardQuery = new WildcardQuery(new Term(FIELD_NAME, "k*dy"));
      wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      doSearching(wildcardQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsPhrase() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      PhraseQuery phraseQuery = new PhraseQuery();
      phraseQuery.add(new Term(FIELD_NAME, "john"));
      phraseQuery.add(new Term(FIELD_NAME, "kennedy"));
      doSearching(phraseQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsQueryScorer() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")),
          new SpanTermQuery(new Term("contents", "kennedy")), };

      SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
      doSearching(snq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testOffByOne() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      TermQuery query = new TermQuery(new Term("data", "help"));
      Highlighter hg = new Highlighter(new SimpleHTMLFormatter(), new QueryTermScorer(query));
      hg.setTextFragmenter(new NullFragmenter());

      String match = hg.getBestFragment(analyzer, "data", "help me [54-65]");
      assertEquals("<B>help</B> me [54-65]", match);

    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsFilteredQuery() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      TermRangeFilter rf = TermRangeFilter.newStringRange("contents", "john", "john", true, true);
      SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")),
          new SpanTermQuery(new Term("contents", "kennedy")), };
      SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
      FilteredQuery fq = new FilteredQuery(snq, rf);

      doSearching(fq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsFilteredPhraseQuery() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      TermRangeFilter rf = TermRangeFilter.newStringRange("contents", "john", "john", true, true);
      PhraseQuery pq = new PhraseQuery();
      pq.add(new Term("contents", "john"));
      pq.add(new Term("contents", "kennedy"));
      FilteredQuery fq = new FilteredQuery(pq, rf);

      doSearching(fq);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      // Currently highlights "John" and "Kennedy" separately
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 2);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsMultiTerm() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      BooleanQuery booleanQuery = new BooleanQuery();
      booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "john")), Occur.SHOULD);
      PrefixQuery prefixQuery = new PrefixQuery(new Term(FIELD_NAME, "kenn"));
      prefixQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
      booleanQuery.add(prefixQuery, Occur.SHOULD);

      doSearching(booleanQuery);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetBestFragmentsWithOr() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;

      BooleanQuery query = new BooleanQuery();
      query.add(new TermQuery(new Term(FIELD_NAME, "jfk")), Occur.SHOULD);
      query.add(new TermQuery(new Term(FIELD_NAME, "kennedy")), Occur.SHOULD);

      doSearching(query);
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 5);
    }
  };
  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testGetSimpleHighlight() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      doSearching(new TermQuery(new Term(FIELD_NAME, "kennedy")));
      // new Highlighter(HighlighterTest.this, new QueryTermScorer(query));

      for (int i = 0; i < hits.totalHits; i++) {
        String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME);
        TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text));
        Highlighter highlighter = getHighlighter(query, FIELD_NAME,
            HighlighterTest.this);
        String result = highlighter.getBestFragment(tokenStream, text);
        if (VERBOSE) System.out.println("\t" + result);
      }
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };
  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testMaxSizeHighlight() throws Exception {
  final MockAnalyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
  // we disable MockTokenizer checks because we will forcefully limit the 
  // tokenstream and call end() before incrementToken() returns false.
  analyzer.setEnableChecks(false);
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      doSearching(new TermQuery(new Term(FIELD_NAME, "meat")));
      TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(texts[0]));
      Highlighter highlighter = getHighlighter(query, FIELD_NAME,
          HighlighterTest.this);// new Highlighter(this, new
      // QueryTermScorer(query));
      highlighter.setMaxDocCharsToAnalyze(30);

      highlighter.getBestFragment(tokenStream, texts[0]);
      assertTrue("Setting MaxDocBytesToAnalyze should have prevented "
          + "us from finding matches for this record: " + numHighlights + " found",
          numHighlights == 0);
    }
  };

  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testMaxSizeEndHighlight() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {
    @Override
    public void run() throws Exception {
      CharacterRunAutomaton stopWords = new CharacterRunAutomaton(new RegExp("i[nt]").toAutomaton());
      TermQuery query = new TermQuery(new Term("text", "searchterm"));

      String text = "this is a text with searchterm in it";
      SimpleHTMLFormatter fm = new SimpleHTMLFormatter();
      Highlighter hg = getHighlighter(query, "text", fm);
      hg.setTextFragmenter(new NullFragmenter());
      hg.setMaxDocCharsToAnalyze(36);
      String match = hg.getBestFragment(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, stopWords, true), "text", text);
      assertTrue(
          "Matched text should contain remainder of text after highlighted query ",
          match.endsWith("in it"));
    }
  };
  helper.start();
}
项目:NYBC    文件:HighlighterTest.java   
public void testNoFragments() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      doSearching(new TermQuery(new Term(FIELD_NAME, "aninvalidquerywhichshouldyieldnoresults")));

      for (String text : texts) {
        TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text));
        Highlighter highlighter = getHighlighter(query, FIELD_NAME,
            HighlighterTest.this);
        String result = highlighter.getBestFragment(tokenStream, text);
        assertNull("The highlight result should be null for text with no query terms", result);
      }
    }
  };

  helper.start();
}
项目:Maskana-Gestor-de-Conocimiento    文件:HighlighterTest.java   
public void testNearSpanSimpleQuery() throws Exception {
  doSearching(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "beginning")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false));

  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();

  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 2);
}
项目:Maskana-Gestor-de-Conocimiento    文件:HighlighterTest.java   
public void testSpanHighlighting() throws Exception {
  Query query1 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordx")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")) }, 1, false);
  Query query2 = new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "wordy")),
      new SpanTermQuery(new Term(FIELD_NAME, "wordc")) }, 1, false);
  BooleanQuery bquery = new BooleanQuery();
  bquery.add(query1, Occur.SHOULD);
  bquery.add(query2, Occur.SHOULD);
  doSearching(bquery);
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 7);
}
项目:Maskana-Gestor-de-Conocimiento    文件:HighlighterTest.java   
public void testNotSpanSimpleQuery() throws Exception {
  doSearching(new SpanNotQuery(new SpanNearQuery(new SpanQuery[] {
      new SpanTermQuery(new Term(FIELD_NAME, "shot")),
      new SpanTermQuery(new Term(FIELD_NAME, "kennedy")) }, 3, false), new SpanTermQuery(
      new Term(FIELD_NAME, "john"))));
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      mode = QUERY;
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
    }
  };

  helper.run();
  assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
      numHighlights == 4);
}
项目:Maskana-Gestor-de-Conocimiento    文件:HighlighterTest.java   
public void testGetBestFragmentsConstantScore() throws Exception {
  TestHighlightRunner helper = new TestHighlightRunner() {

    @Override
    public void run() throws Exception {
      numHighlights = 0;
      if (random().nextBoolean()) {
        BooleanQuery bq = new BooleanQuery();
        bq.add(new ConstantScoreQuery(new QueryWrapperFilter(new TermQuery(
            new Term(FIELD_NAME, "kennedy")))), Occur.MUST);
        bq.add(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME, "kennedy"))), Occur.MUST);
        doSearching(bq);
      } else {
        doSearching(new ConstantScoreQuery(new TermQuery(new Term(FIELD_NAME,
            "kennedy"))));
      }
      doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
      assertTrue("Failed to find correct number of highlights " + numHighlights + " found",
          numHighlights == 4);
    }
  };

  helper.start();
}