SOLR-3897: return a snippet for every value when preserveMulti=true

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1396317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-10-09 21:03:28 +00:00
parent eeb64dca34
commit 09a14bb6e3
2 changed files with 13 additions and 21 deletions

View File

@ -446,6 +446,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
listFields.add(field.stringValue());
}
// preserve order of values in a multiValued list
boolean preserveMulti = params.getFieldBool(fieldName, HighlightParams.PRESERVE_MULTI, false);
String[] docTexts = (String[]) listFields.toArray(new String[listFields.size()]);
@ -551,7 +552,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
}
}
if (fragTexts.size() >= numFragments) break;
if (fragTexts.size() >= numFragments && !preserveMulti) break;
}
summaries = fragTexts.toArray(new String[0]);
if (summaries.length > 0)

View File

@ -299,31 +299,22 @@ public class HighlighterTest extends SolrTestCaseJ4 {
);
}
@Test
public void testPreserveMulti() {
HashMap<String,String> args = new HashMap<String,String>();
args.put("hl", "true");
args.put("hl.fl", "cat");
args.put("hl.snippets", "2");
args.put("f.cat.hl.preserveMulti", "true");
TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
"standard", 0, 200, args);
assertU(adoc("cat", "electronics",
"cat", "monitor",
"id", "1"));
@Test
public void testPreserveMulti() throws Exception {
assertU(adoc("id","1", "cat", "electronics", "cat", "monitor"));
assertU(commit());
assertU(optimize());
assertQ("Preserve multi",
sumLRF.makeRequest("cat:monitor"),
"//lst[@name='highlighting']/lst[@name='1']",
"//lst[@name='1']/arr[@name='cat']/str[.=\'electronics\']",
"//lst[@name='1']/arr[@name='cat']/str[.=\'<em>monitor</em>\']"
assertJQ(req("q", "cat:monitor", "hl", "true", "hl.fl", "cat", "hl.snippets", "2", "f.cat.hl.preserveMulti", "true"),
"/highlighting/1/cat==['electronics','<em>monitor</em>']"
);
// No match still lists all snippets?
assertJQ(req("q", "id:1 OR cat:duuuude", "hl", "true", "hl.fl", "cat", "hl.snippets", "2", "f.cat.hl.preserveMulti", "true"),
"/highlighting/1/cat==['electronics','monitor']"
);
}
@Test
public void testDefaultFieldHighlight() {