mirror of https://github.com/apache/lucene.git
SOLR-516: add hl.maxAlternateFieldLength
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@646926 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dc9bb60c4a
commit
e1aa232a51
|
@ -111,11 +111,11 @@ New Features
|
||||||
13. SOLR-225: Enable pluggable highlighting classes. Allow configurable
|
13. SOLR-225: Enable pluggable highlighting classes. Allow configurable
|
||||||
highlighting formatters and Fragmenters. (ryan)
|
highlighting formatters and Fragmenters. (ryan)
|
||||||
|
|
||||||
14. SOLR-273/376/452: Added hl.maxAnalyzedChars highlighting parameter, defaulting
|
14. SOLR-273/376/452/516: Added hl.maxAnalyzedChars highlighting parameter, defaulting
|
||||||
to 50k, hl.alternateField, which allows the specification of a backup
|
to 50k, hl.alternateField, which allows the specification of a backup
|
||||||
field to use as summary if no keywords are matched, and hl.mergeContiguous,
|
field to use as summary if no keywords are matched, and hl.mergeContiguous,
|
||||||
which combines fragments if they are adjacent in the source document.
|
which combines fragments if they are adjacent in the source document.
|
||||||
(klaas, Grant Ingersoll via klaas)
|
(klaas, Grant Ingersoll, Koji Sekiguchi via klaas)
|
||||||
|
|
||||||
15. SOLR-291: Control maximum number of documents to cache for any entry
|
15. SOLR-291: Control maximum number of documents to cache for any entry
|
||||||
in the queryResultCache via queryResultMaxDocsCached solrconfig.xml
|
in the queryResultCache via queryResultMaxDocsCached solrconfig.xml
|
||||||
|
|
|
@ -32,6 +32,7 @@ public interface HighlightParams {
|
||||||
public static final String FRAGMENTER = HIGHLIGHT+".fragmenter";
|
public static final String FRAGMENTER = HIGHLIGHT+".fragmenter";
|
||||||
public static final String FIELD_MATCH = HIGHLIGHT+".requireFieldMatch";
|
public static final String FIELD_MATCH = HIGHLIGHT+".requireFieldMatch";
|
||||||
public static final String ALTERNATE_FIELD = HIGHLIGHT+".alternateField";
|
public static final String ALTERNATE_FIELD = HIGHLIGHT+".alternateField";
|
||||||
|
public static final String ALTERNATE_FIELD_LENGTH = HIGHLIGHT+".maxAlternateFieldLength";
|
||||||
|
|
||||||
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
||||||
// Formatter
|
// Formatter
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -273,9 +274,24 @@ public class DefaultSolrHighlighter extends SolrHighlighter
|
||||||
if (summaries == null || summaries.length == 0) {
|
if (summaries == null || summaries.length == 0) {
|
||||||
String alternateField = req.getParams().getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD);
|
String alternateField = req.getParams().getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD);
|
||||||
if (alternateField != null && alternateField.length() > 0) {
|
if (alternateField != null && alternateField.length() > 0) {
|
||||||
String[] altTexts = doc.getValues(alternateField);
|
String[] altTexts = doc.getValues(alternateField);
|
||||||
if (altTexts != null && altTexts.length > 0)
|
if (altTexts != null && altTexts.length > 0){
|
||||||
docSummaries.add(fieldName, altTexts);
|
int alternateFieldLen = req.getParams().getFieldInt(fieldName, HighlightParams.ALTERNATE_FIELD_LENGTH,0);
|
||||||
|
if( alternateFieldLen <= 0 ){
|
||||||
|
docSummaries.add(fieldName, altTexts);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
List<String> altList = new ArrayList<String>();
|
||||||
|
int len = 0;
|
||||||
|
for( String altText: altTexts ){
|
||||||
|
altList.add( len + altText.length() > alternateFieldLen ?
|
||||||
|
altText.substring( 0, alternateFieldLen - len ) : altText );
|
||||||
|
len += altText.length();
|
||||||
|
if( len >= alternateFieldLen ) break;
|
||||||
|
}
|
||||||
|
docSummaries.add(fieldName, altList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,5 +470,15 @@ public class HighlighterTest extends AbstractSolrTestCase {
|
||||||
"//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
|
"//lst[@name='highlighting']/lst[@name='1' and count(*)=1]",
|
||||||
"//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='1']"
|
"//lst[@name='highlighting']/lst[@name='1']/arr[@name='t_text']/str[.='1']"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// with an alternate + max length
|
||||||
|
args.put("hl.alternateField", "t_text");
|
||||||
|
args.put("hl.maxAlternateFieldLength", "15");
|
||||||
|
sumLRF = h.getRequestFactory("standard", 0, 200, args);
|
||||||
|
assertQ("Alternate summarization",
|
||||||
|
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[.='a piece of text']"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue