Java Code Examples for org.apache.solr.util.TestHarness#LocalRequestFactory

The following examples show how to use org.apache.solr.util.TestHarness#LocalRequestFactory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastVectorHighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_text");
  args.put("hl.snippets", "2");
  args.put("hl.tag.pre", "<fvpre>"); //... and let post default to </em>. This is just a test.
  if (random().nextBoolean()) {
    args.put("hl.useFastVectorHighlighter", "true"); // old way
  } else {
    args.put("hl.method", "fastVector"); // the new way
  }
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "",0,200,args);
  
  assertU(adoc("tv_text", "basic fast vector highlighter test", 
               "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("tv_text:vector"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='tv_text']/str[.='basic fast <fvpre>vector</em> highlighter test']"
          );
}
 
Example 2
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongFragment() {

  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_text");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  

  String text = 
    "junit: [mkdir] Created dir: /home/klaas/worio/backend/trunk/build-src/solr-nightly/build/test-results [junit] Running org.apache.solr.BasicFunctionalityTest [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 5.36 sec [junit] Running org.apache.solr.ConvertedLegacyTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 8.268 sec [junit] Running org.apache.solr.DisMaxRequestHandlerTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.56 sec [junit] Running org.apache.solr.HighlighterTest [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 4.979 sec [junit] Running org.apache.solr.OutputWriterTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.797 sec [junit] Running org.apache.solr.SampleTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 1.021 sec [junit] Running org.apache.solr.analysis.TestBufferedTokenStream [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.05 sec [junit] Running org.apache.solr.analysis.TestRemoveDuplicatesTokenFilter [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.054 sec [junit] Running org.apache.solr.analysis.TestSynonymFilter [junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.081 sec [junit] Running org.apache.solr.analysis.TestWordDelimiterFilter [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.714 sec [junit] Running org.apache.solr.search.TestDocSet [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.788 sec [junit] Running org.apache.solr.util.SolrPluginUtilsTest [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 3.519 sec [junit] Running org.apache.solr.util.TestOpenBitSet [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.533 sec";
  assertU(adoc("tv_text", text, "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("tv_text:dir"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='tv_text']/str"
          );
}
 
Example 3
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultFieldNonPrefixWildcardHighlight() {

  // do summarization using re-analysis of the field
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("df", "t_text");
  args.put("hl.fl", "");
  args.put("hl.usePhraseHighlighter", "true");
  args.put("hl.highlightMultiTerm", "true");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  
  assertU(adoc("t_text", "a long day's night", "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("l*g"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='t_text']/str"
          );

}
 
Example 4
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoFieldHighlight() {

  // do summarization using re-analysis of the field
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "t_text tv_text");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  
  assertU(adoc("t_text", "a long day's night", "id", "1",
               "tv_text", "a long night's day"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("t_text:long"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='t_text']/str",
          "//lst[@name='1']/arr[@name='tv_text']/str"
          );
}
 
Example 5
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testHighlightDisabled() {

  // ensure highlighting can be explicitly disabled
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "false");
  args.put("hl.fl", "t_text");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  
  assertU(adoc("t_text", "a long day's night", "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("t_text:long"), "not(//lst[@name='highlighting'])");

}
 
Example 6
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiValueBestFragmentHighlight() {
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "textgap");
  args.put("df", "textgap");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
      "", 0, 200, args);
  
  assertU(adoc("textgap", "first entry has one word foo", 
      "textgap", "second entry has both words foo bar",
      "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Best fragment summarization",
      sumLRF.makeRequest("foo bar"),
      "//lst[@name='highlighting']/lst[@name='1']",
      "//lst[@name='1']/arr[@name='textgap']/str[.=\'second entry has both words <em>foo</em> <em>bar</em>\']"
  );
}
 
Example 7
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiValueAnalysisHighlight() {

  // do summarization using re-analysis of the field
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "textgap");
  args.put("df", "textgap");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  
  assertU(adoc("textgap", "first entry hasnt queryword",
      "textgap", "second entry has queryword long",
      "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("long"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='textgap']/str"
          );

}
 
Example 8
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testTermVecMultiValuedHighlight2() throws Exception {

  // do summarization using term vectors on multivalued field
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_mv_text");
  args.put("hl.snippets", "2");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "",0,200,args);

  String shortText = "short";
  assertU(adoc("tv_mv_text", shortText,
               "tv_mv_text", LONG_TEXT,
               "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("tv_mv_text:long"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='tv_mv_text']/str[.='a <em>long</em> days night this should be a piece of text which']",
          "//arr[@name='tv_mv_text']/str[.=' <em>long</em> fragments.']"
          );
}
 
Example 9
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testTermVecMultiValuedHighlight() throws Exception {

  // do summarization using term vectors on multivalued field
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_mv_text");
  args.put("hl.snippets", "2");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "",0,200,args);
  
  assertU(adoc("tv_mv_text", LONG_TEXT, 
               "tv_mv_text", LONG_TEXT, 
               "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("tv_mv_text:long"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='tv_mv_text']/str[.='a <em>long</em> days night this should be a piece of text which']",
          "//arr[@name='tv_mv_text']/str[.=' <em>long</em> fragments.']"
          );
}
 
Example 10
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testTermVectorWithoutOffsetsHighlight() {

  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_no_off_text");

  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory("", 0, 200, args);

  assertU(adoc("tv_no_off_text", "Crackerjack Cameron", "id", "1"));
  assertU(commit());
  assertU(optimize());

  assertQ("Fields with term vectors switched on but no offsets should be correctly highlighted",
          sumLRF.makeRequest("tv_no_off_text:cameron"),
          "//arr[@name='tv_no_off_text']/str[.='Crackerjack <em>Cameron</em>']");

}
 
Example 11
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testTermVecHighlight() {

  // do summarization using term vectors
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_text");
  args.put("hl.snippets", "2");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "",0,200,args);
  
  assertU(adoc("tv_text", LONG_TEXT, 
               "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("tv_text:long"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[@name='tv_text']/str[.='a <em>long</em> days night this should be a piece of text which']",
          "//arr[@name='tv_text']/str[.=' <em>long</em> fragments.']"
          );
}
 
Example 12
Source File: HighlighterConfigTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testConfig()
{
        SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
  log.info( "highlighter" );

  assertTrue( highlighter instanceof DummyHighlighter );

  // check to see that doHighlight is called from the DummyHighlighter
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("df", "t_text");
  args.put("hl.fl", "");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);

  assertU(adoc("t_text", "a long day's night", "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
          sumLRF.makeRequest("long"),
          "//lst[@name='highlighting']/str[@name='dummy']"
          );
  }
 
Example 13
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisMaxHighlight() {

  // same test run through dismax handler
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "tv_text");
  args.put("qf", "tv_text");
  args.put("q.alt", "*:*");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "/dismax",0,200,args);
  
  assertU(adoc("tv_text", "a long day's night", "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("Basic summarization",
      sumLRF.makeRequest("long"),
      "//lst[@name='highlighting']/lst[@name='1']",
      "//lst[@name='1']/arr[@name='tv_text']/str"
  );
  
  // try the same thing without a q param
  assertQ("Should not explode...", // q.alt should return everything
      sumLRF.makeRequest( new String[] { null } ), // empty query
      "//result[@numFound='1']"
      );
}
 
Example 14
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testVariableFragsize() {
   assertU(adoc("tv_text", "a long days night this should be a piece of text which is is is is is is is is is is is is is is is is is is is is is is is is isis is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is sufficiently lengthly to produce multiple fragments which are not concatenated at all", 
         "id", "1"));
   assertU(commit());
   assertU(optimize());

   // default length
   HashMap<String,String> args = new HashMap<>();
   args.put("hl", "true");
   args.put("hl.fl", "tv_text");
   TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
     "", 0, 200, args);
   assertQ("Basic summarization",
         sumLRF.makeRequest("tv_text:long"),
         "//lst[@name='highlighting']/lst[@name='1']",
         "//lst[@name='1']/arr[@name='tv_text']/str[.='a <em>long</em> days night this should be a piece of text which']"
         );
   
   // 25
   args.put("hl.fragsize","25");
   sumLRF = h.getRequestFactory(
         "", 0, 200, args);
   assertQ("Basic summarization",
         sumLRF.makeRequest("tv_text:long"),
         "//lst[@name='highlighting']/lst[@name='1']",
         "//lst[@name='1']/arr[@name='tv_text']/str[.='a <em>long</em> days night']"
         );
   
   // 0 - NullFragmenter
   args.put("hl.fragsize","0");
   sumLRF = h.getRequestFactory(
         "", 0, 200, args);
   assertQ("Basic summarization",
         sumLRF.makeRequest("tv_text:long"),
         "//lst[@name='highlighting']/lst[@name='1']",
         "//lst[@name='1']/arr[@name='tv_text']/str[.='a <em>long</em> days night this should be a piece of text which is is is is is is is is is is is is is is is is is is is is is is is is isis is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is is sufficiently lengthly to produce multiple fragments which are not concatenated at all']"
         );
}
 
Example 15
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegexFragmenter() {
  HashMap<String,String> args = new HashMap<>();
  args.put("fl", "id score");
  args.put("hl", "true");
  args.put("hl.snippets", "10");
  args.put("hl.fl", "t_text");
  args.put("hl.fragmenter", "regex");
  args.put("hl.regex.pattern", "[-\\w ,\"']{20,200}");
  args.put("hl.regex.slop", ".9");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  
  String t = "This is an example of a sentence. Another example \"sentence\" with " +
    "special characters\nand a line-break! Miscellaneous character like ^ are " +
    "unknowns and end up being bad example s of sentences? I wonder how " +
    "slashes/other punctuation fare in these examples?";
  assertU(adoc("t_text", t, "id", "1"));
  assertU(commit());
  assertU(optimize());
  assertQ("regex fragmenter",
          sumLRF.makeRequest("t_text:example"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//arr/str[.='This is an <em>example</em> of a sentence']",
          "//arr/str[.='. Another <em>example</em> \"sentence\" with special characters\nand a line-break']",
          "//arr/str[.=' ^ are unknowns and end up being bad <em>example</em> s of sentences']",
          "//arr/str[.='/other punctuation fare in these <em>examples</em>?']"
          );
  // try with some punctuation included
  args.put("hl.regex.pattern", "[-\\w ,^/\\n\"']{20,200}");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("regex fragmenter 2",
          sumLRF.makeRequest("t_text:example"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//arr/str[.='This is an <em>example</em> of a sentence']",
          "//arr/str[.='. Another <em>example</em> \"sentence\" with special characters\nand a line-break']",
          "//arr/str[.='! Miscellaneous character like ^ are unknowns and end up being bad <em>example</em> s of sentences']",
          "//arr/str[.='? I wonder how slashes/other punctuation fare in these <em>examples</em>?']"
          );
}
 
Example 16
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaxChars() {
  HashMap<String,String> args = new HashMap<>();
  args.put("fl", "id score");
  args.put("hl", "true");
  args.put("hl.snippets", "10");
  final String field = random().nextBoolean() ? "t_text" : "tv_text";
  args.put("hl.fl", field);
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  

  assertU(adoc(field, LONG_TEXT, "id", "1"));
  assertU(commit());

  assertQ("token at start of text",
          sumLRF.makeRequest(field + ":disjoint"),
          "//lst[@name='highlighting']/lst[@name='1']",
          "//lst[@name='1']/arr[count(str)=1]"
          );
  args.put("hl.maxAnalyzedChars", "20");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("token at end of text",
      sumLRF.makeRequest(field + ":disjoint"),
      "//lst[@name='highlighting']/lst[@name='1']",
      "//lst[@name='1'][not(*)]"
  );
  args.put("hl.maxAnalyzedChars", "-1");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("token at start of text",
      sumLRF.makeRequest(field + ":disjoint"),
      "//lst[@name='highlighting']/lst[@name='1']",
      "//lst[@name='1']/arr[count(str)=1]"
  );

}
 
Example 17
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetHighlightFields() {
  HashMap<String, String> args = new HashMap<>();
  args.put("fl", "id score");
  args.put("hl", "true");
  args.put("hl.fl", "t*");

  assertU(adoc("id", "0", "title", "test", // static stored
      "text", "test", // static not stored
      "foo_s", "test", // dynamic stored
      "foo_sI", "test", // dynamic not stored
      "bar_s", "test", // dynamic stored
      "bar_sI", "test", // dynamic not stored
      "weight", "1.0")); // stored but not text
  assertU(commit());
  assertU(optimize());

  TestHarness.LocalRequestFactory lrf = h.getRequestFactory("", 0,
      10, args);

  SolrQueryRequest request = lrf.makeRequest("test");
  SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
  List<String> highlightFieldNames = Arrays.asList(highlighter
      .getHighlightFields(null, request, new String[] {}));
  assertTrue("Expected to highlight on field \"title\"", highlightFieldNames
      .contains("title"));
  assertFalse("Expected to not highlight on field \"text\"",
      highlightFieldNames.contains("text"));
  assertFalse("Expected to not highlight on field \"weight\"",
      highlightFieldNames.contains("weight"));
  request.close();

  args.put("hl.fl", "foo_*");
  lrf = h.getRequestFactory("", 0, 10, args);
  request = lrf.makeRequest("test");
  highlighter = HighlightComponent.getHighlighter(h.getCore());
  highlightFieldNames = Arrays.asList(highlighter.getHighlightFields(null,
      request, new String[] {}));
  assertEquals("Expected one field to highlight on", 1, highlightFieldNames
      .size());
  assertEquals("Expected to highlight on field \"foo_s\"", "foo_s",
      highlightFieldNames.get(0));
  request.close();

  // SOLR-5127
  args.put("hl.fl", (random().nextBoolean() ? "foo_*,bar_*" : "bar_*,foo_*"));
  lrf = h.getRequestFactory("", 0, 10, args);
  // hl.fl ordering need not be preserved in output
  final Set<String> highlightedSetExpected = new HashSet<String>();
  highlightedSetExpected.add("foo_s");
  highlightedSetExpected.add("bar_s");
  try (LocalSolrQueryRequest localRequest = lrf.makeRequest("test")) {
    highlighter = HighlightComponent.getHighlighter(h.getCore());
    final Set<String> highlightedSetActual = new HashSet<String>(
        Arrays.asList(highlighter.getHighlightFields(null,
            localRequest, new String[] {})));
    assertEquals(highlightedSetExpected, highlightedSetActual);
  }

  // SOLR-11334
  args.put("hl.fl", "title, text"); // comma then space
  lrf = h.getRequestFactory("", 0, 10, args);
  request = lrf.makeRequest("test");
  highlighter = HighlightComponent.getHighlighter(h.getCore());
  highlightFieldNames = Arrays.asList(highlighter.getHighlightFields(null,
      request, new String[] {}));
  assertEquals("Expected one field to highlight on", 2, highlightFieldNames
      .size());
  assertTrue("Expected to highlight on field \"title\"",
      highlightFieldNames.contains("title"));
  assertTrue("Expected to highlight on field \"text\"",
      highlightFieldNames.contains("text"));
  assertFalse("Expected to not highlight on field \"\"",
      highlightFieldNames.contains(""));

  request.close();
}
 
Example 18
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testAlternateSummaryWithHighlighting() {
   //long document
   assertU(adoc("tv_text", "keyword is only here, tv_text alternate field",
                "t_text", "a piece of text to be substituted",
                "other_t", "keyword",
                "id", "1",
                "foo_t","hi"));
   assertU(commit());
   assertU(optimize());

  // Prove that hl.highlightAlternate is default true and respects maxAlternateFieldLength
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fragsize","0");
  args.put("hl.fl", "t_text");
  args.put("hl.simple.pre", "<simplepre>");
  args.put("hl.simple.post", "</simplepost>");
  args.put("hl.alternateField", "tv_text");
  args.put("hl.maxAlternateFieldLength", "39");
  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  assertQ("Alternate summarization with highlighting",
          sumLRF.makeRequest("tv_text:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='<simplepre>keyword</simplepost> is only here, tv_text']"
          );

  // Query on other field than hl or alternate. Still we get the hightlighted snippet from alternate
  assertQ("Alternate summarization with highlighting, query other field",
          sumLRF.makeRequest("other_t:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='<simplepre>keyword</simplepost> is only here, tv_text']"
          );

  // With hl.requireFieldMatch, will not highlight but fall back to plain-text alternate
  args.put("hl.requireFieldMatch", "true");
  sumLRF = h.getRequestFactory(
    "", 0, 200, args);
  assertQ("Alternate summarization with highlighting, requireFieldMatch",
          sumLRF.makeRequest("other_t:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='keyword is only here, tv_text alternate']"
          );
  args.put("hl.requireFieldMatch", "false");


  // Works with field specific params, overriding maxAlternateFieldLength to return everything
  args.remove("hl.alternateField");
  args.put("f.t_text.hl.alternateField", "tv_text");
  args.put("f.t_text.hl.maxAlternateFieldLength", "0");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("Alternate summarization with highlighting",
          sumLRF.makeRequest("tv_text:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='<simplepre>keyword</simplepost> is only here, tv_text alternate field']"
          );

  // Prove fallback highlighting works also with FVH
  args.put("hl.method", "fastVector");
  args.put("hl.tag.pre", "<fvhpre>");
  args.put("hl.tag.post", "</fvhpost>");
  args.put("f.t_text.hl.maxAlternateFieldLength", "18");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("Alternate summarization with highlighting using FVH",
          sumLRF.makeRequest("tv_text:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
      "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='<fvhpre>keyword</fvhpost> is only here']"
          );

  // Prove it is possible to turn off highlighting of alternate field
  args.put("hl.highlightAlternate", "false");
  sumLRF = h.getRequestFactory("", 0, 200, args);
  assertQ("Alternate summarization without highlighting",
          sumLRF.makeRequest("tv_text:keyword"),
          "//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
          "//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='keyword is only he']"
          );
}
 
Example 19
Source File: TestComplexPhraseQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
  HashMap<String, String> args = new HashMap<String, String>();

  args.put(QueryParsing.DEFTYPE, ComplexPhraseQParserPlugin.NAME);
  args.put(CommonParams.FL, "id");

  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
          "", 0, 200, args);

  assertU(adoc("name", "john smith", "id", "1"));
  assertU(adoc("name", "johathon smith", "id", "2"));
  assertU(adoc("name", "john percival smith", "id", "3"));
  assertU(commit());
  assertU(optimize());

  assertQ("Simple multi-term still works",
          sumLRF.makeRequest("name:\"john smith\""),
          "//doc[./str[@name='id']='1']",
          "//result[@numFound='1']"
  );

  assertQ(req("q", "{!complexphrase} name:\"john smith\""),
          "//doc[./str[@name='id']='1']",
          "//result[@numFound='1']"
  );


  assertQ("wildcards and fuzzies are OK in phrases",
          sumLRF.makeRequest("name:\"j* smyth~\""),
          "//doc[./str[@name='id']='1']",
          "//doc[./str[@name='id']='2']",
          "//result[@numFound='2']"
  );

  assertQ("boolean logic works",
          sumLRF.makeRequest("name:\"(jo* -john) smith\""),
          "//doc[./str[@name='id']='2']",
          "//result[@numFound='1']"
  );

  assertQ("position logic works",
          sumLRF.makeRequest("name:\"jo*  smith\"~2"),
          "//doc[./str[@name='id']='1']",
          "//doc[./str[@name='id']='2']",
          "//doc[./str[@name='id']='3']",
          "//result[@numFound='3']"
  );

  assertQ("range queries supported",
          sumLRF.makeRequest("name:\"jo* [sma TO smz]\""),
          "//doc[./str[@name='id']='1']",
          "//doc[./str[@name='id']='2']",
          "//result[@numFound='2']"
  );

  assertQ("Simple single-term still works",
          sumLRF.makeRequest("name:\"john\""),
          "//doc[./str[@name='id']='1']",
          "//doc[./str[@name='id']='3']",
          "//result[@numFound='2']"
  );

  assertQ("OR inside phrase works",
          sumLRF.makeRequest("name:\"(john johathon) smith\""),
          "//doc[./str[@name='id']='1']",
          "//doc[./str[@name='id']='2']",
          "//result[@numFound='2']"
  );

  assertQEx("don't parse subqueries",
      "SyntaxError",
      sumLRF.makeRequest("_query_:\"{!prefix f=name v=smi}\""), SolrException.ErrorCode.BAD_REQUEST
  );
  assertQEx("don't parse subqueries",
      "SyntaxError",
      sumLRF.makeRequest("{!prefix f=name v=smi}"), SolrException.ErrorCode.BAD_REQUEST
  );

}
 
Example 20
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testPhraseHighlighter() {
  HashMap<String,String> args = new HashMap<>();
  args.put("hl", "true");
  args.put("hl.fl", "t_text");
  args.put("hl.fragsize", "40");
  args.put("hl.snippets", "10");
  args.put("hl.usePhraseHighlighter", "false");

  TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
    "", 0, 200, args);

  // String borrowed from Lucene's HighlighterTest
  String t = "This piece of text refers to Kennedy at the beginning then has a longer piece of text that is very long in the middle and finally ends with another reference to Kennedy";
  
  assertU(adoc("t_text", t, "id", "1"));
  assertU(commit());
  assertU(optimize());
  
  String oldHighlight1 = "//lst[@name='1']/arr[@name='t_text']/str[.='This piece of <em>text</em> <em>refers</em> to Kennedy']";
  String oldHighlight2 = "//lst[@name='1']/arr[@name='t_text']/str[.=' at the beginning then has a longer piece of <em>text</em>']";
  String oldHighlight3 = "//lst[@name='1']/arr[@name='t_text']/str[.=' with another <em>reference</em> to Kennedy']";
  String newHighlight1 = "//lst[@name='1']/arr[@name='t_text']/str[.='This piece of <em>text</em> <em>refers</em> to Kennedy']";

  // check if old functionality is still the same
  assertQ("Phrase highlighting - old",
      sumLRF.makeRequest("t_text:\"text refers\""),
      "//lst[@name='highlighting']/lst[@name='1']",
      oldHighlight1, oldHighlight2, oldHighlight3
      );

  assertQ("Phrase highlighting - old",
      sumLRF.makeRequest("t_text:text refers"),
      "//lst[@name='highlighting']/lst[@name='1']",
      oldHighlight1, oldHighlight2, oldHighlight3
      );
  
  // now check if Lucene-794 highlighting works as expected
  args.put("hl.usePhraseHighlighter", "true");

  sumLRF = h.getRequestFactory("", 0, 200, args);
  
  // check phrase highlighting
  assertQ("Phrase highlighting - Lucene-794",
      sumLRF.makeRequest("t_text:\"text refers\""),
      "//lst[@name='highlighting']/lst[@name='1']",
      newHighlight1
      );

  // non phrase queries should be highlighted as they were before this fix
  assertQ("Phrase highlighting - Lucene-794",
      sumLRF.makeRequest("t_text:text refers"),
      "//lst[@name='highlighting']/lst[@name='1']",
      oldHighlight1, oldHighlight2, oldHighlight3
      );
}