LUCENE-2626: FastVectorHighlighter: enable FragListBuilder and FragmentsBuilder to be set per-field override

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@990301 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2010-08-27 23:42:07 +00:00
parent a3e8c0b873
commit beb35ff50c
3 changed files with 34 additions and 21 deletions

View File

@ -134,6 +134,9 @@ API Changes
char that is used when concatenating multiValued data. Default is a space char that is used when concatenating multiValued data. Default is a space
(' '). It is applied on ANALYZED field only. (Koji Sekiguchi) (' '). It is applied on ANALYZED field only. (Koji Sekiguchi)
* LUCENE-2626: FastVectorHighlighter: enable FragListBuilder and FragmentsBuilder
to be set per-field override. (Koji Sekiguchi)
New features New features
* LUCENE-2306: Add NumericRangeFilter and NumericRangeQuery support to XMLQueryParser. * LUCENE-2306: Add NumericRangeFilter and NumericRangeQuery support to XMLQueryParser.

View File

@ -92,7 +92,8 @@ public class FastVectorHighlighter {
*/ */
public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId, public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize ) throws IOException { String fieldName, int fragCharSize ) throws IOException {
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize ); FieldFragList fieldFragList =
getFieldFragList( fragListBuilder, fieldQuery, reader, docId, fieldName, fragCharSize );
return fragmentsBuilder.createFragment( reader, docId, fieldName, fieldFragList ); return fragmentsBuilder.createFragment( reader, docId, fieldName, fieldFragList );
} }
@ -111,7 +112,8 @@ public class FastVectorHighlighter {
*/ */
public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId, public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize, int maxNumFragments ) throws IOException { String fieldName, int fragCharSize, int maxNumFragments ) throws IOException {
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize ); FieldFragList fieldFragList =
getFieldFragList( fragListBuilder, fieldQuery, reader, docId, fieldName, fragCharSize );
return fragmentsBuilder.createFragments( reader, docId, fieldName, fieldFragList, maxNumFragments ); return fragmentsBuilder.createFragments( reader, docId, fieldName, fieldFragList, maxNumFragments );
} }
@ -123,6 +125,8 @@ public class FastVectorHighlighter {
* @param docId document id to be highlighted * @param docId document id to be highlighted
* @param fieldName field of the document to be highlighted * @param fieldName field of the document to be highlighted
* @param fragCharSize the length (number of chars) of a fragment * @param fragCharSize the length (number of chars) of a fragment
* @param fragListBuilder {@link FragListBuilder} object
* @param fragmentsBuilder {@link FragmentsBuilder} object
* @param preTags pre-tags to be used to highlight terms * @param preTags pre-tags to be used to highlight terms
* @param postTags post-tags to be used to highlight terms * @param postTags post-tags to be used to highlight terms
* @param encoder an encoder that generates encoded text * @param encoder an encoder that generates encoded text
@ -130,9 +134,10 @@ public class FastVectorHighlighter {
* @throws IOException * @throws IOException
*/ */
public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId, public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize, String[] preTags, String[] postTags, String fieldName, int fragCharSize,
Encoder encoder ) throws IOException { FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder,
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize ); String[] preTags, String[] postTags, Encoder encoder ) throws IOException {
FieldFragList fieldFragList = getFieldFragList( fragListBuilder, fieldQuery, reader, docId, fieldName, fragCharSize );
return fragmentsBuilder.createFragment( reader, docId, fieldName, fieldFragList, preTags, postTags, encoder ); return fragmentsBuilder.createFragment( reader, docId, fieldName, fieldFragList, preTags, postTags, encoder );
} }
@ -145,6 +150,8 @@ public class FastVectorHighlighter {
* @param fieldName field of the document to be highlighted * @param fieldName field of the document to be highlighted
* @param fragCharSize the length (number of chars) of a fragment * @param fragCharSize the length (number of chars) of a fragment
* @param maxNumFragments maximum number of fragments * @param maxNumFragments maximum number of fragments
* @param fragListBuilder {@link FragListBuilder} object
* @param fragmentsBuilder {@link FragmentsBuilder} object
* @param preTags pre-tags to be used to highlight terms * @param preTags pre-tags to be used to highlight terms
* @param postTags post-tags to be used to highlight terms * @param postTags post-tags to be used to highlight terms
* @param encoder an encoder that generates encoded text * @param encoder an encoder that generates encoded text
@ -153,14 +160,17 @@ public class FastVectorHighlighter {
* @throws IOException * @throws IOException
*/ */
public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId, public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize, int maxNumFragments, String[] preTags, String[] postTags, String fieldName, int fragCharSize, int maxNumFragments,
Encoder encoder ) throws IOException { FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder,
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize ); String[] preTags, String[] postTags, Encoder encoder ) throws IOException {
FieldFragList fieldFragList =
getFieldFragList( fragListBuilder, fieldQuery, reader, docId, fieldName, fragCharSize );
return fragmentsBuilder.createFragments( reader, docId, fieldName, fieldFragList, maxNumFragments, return fragmentsBuilder.createFragments( reader, docId, fieldName, fieldFragList, maxNumFragments,
preTags, postTags, encoder ); preTags, postTags, encoder );
} }
private FieldFragList getFieldFragList( final FieldQuery fieldQuery, IndexReader reader, int docId, private FieldFragList getFieldFragList( FragListBuilder fragListBuilder,
final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize ) throws IOException { String fieldName, int fragCharSize ) throws IOException {
FieldTermStack fieldTermStack = new FieldTermStack( reader, docId, fieldName, fieldQuery ); FieldTermStack fieldTermStack = new FieldTermStack( reader, docId, fieldName, fieldQuery );
FieldPhraseList fieldPhraseList = new FieldPhraseList( fieldTermStack, fieldQuery ); FieldPhraseList fieldPhraseList = new FieldPhraseList( fieldTermStack, fieldQuery );

View File

@ -301,8 +301,8 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
return frag.getFragmenter( fieldName, params ); return frag.getFragmenter( fieldName, params );
} }
protected FragListBuilder getFragListBuilder( SolrParams params ){ protected FragListBuilder getFragListBuilder( String fieldName, SolrParams params ){
String flb = params.get( HighlightParams.FRAG_LIST_BUILDER ); String flb = params.getFieldParam( fieldName, HighlightParams.FRAG_LIST_BUILDER );
SolrFragListBuilder solrFlb = fragListBuilders.get( flb ); SolrFragListBuilder solrFlb = fragListBuilders.get( flb );
if( solrFlb == null ){ if( solrFlb == null ){
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown fragListBuilder: " + flb ); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown fragListBuilder: " + flb );
@ -310,12 +310,12 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
return solrFlb.getFragListBuilder( params ); return solrFlb.getFragListBuilder( params );
} }
protected FragmentsBuilder getFragmentsBuilder( SolrParams params ){ protected FragmentsBuilder getFragmentsBuilder( String fieldName, SolrParams params ){
return getSolrFragmentsBuilder( params ).getFragmentsBuilder( params ); return getSolrFragmentsBuilder( fieldName, params ).getFragmentsBuilder( params );
} }
private SolrFragmentsBuilder getSolrFragmentsBuilder( SolrParams params ){ private SolrFragmentsBuilder getSolrFragmentsBuilder( String fieldName, SolrParams params ){
String fb = params.get( HighlightParams.FRAGMENTS_BUILDER ); String fb = params.getFieldParam( fieldName, HighlightParams.FRAGMENTS_BUILDER );
SolrFragmentsBuilder solrFb = fragmentsBuilders.get( fb ); SolrFragmentsBuilder solrFb = fragmentsBuilders.get( fb );
if( solrFb == null ){ if( solrFb == null ){
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown fragmentsBuilder: " + fb ); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown fragmentsBuilder: " + fb );
@ -361,11 +361,8 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
// FVH cannot process hl.usePhraseHighlighter parameter per-field basis // FVH cannot process hl.usePhraseHighlighter parameter per-field basis
params.getBool( HighlightParams.USE_PHRASE_HIGHLIGHTER, true ), params.getBool( HighlightParams.USE_PHRASE_HIGHLIGHTER, true ),
// FVH cannot process hl.requireFieldMatch parameter per-field basis // FVH cannot process hl.requireFieldMatch parameter per-field basis
params.getBool( HighlightParams.FIELD_MATCH, false ), params.getBool( HighlightParams.FIELD_MATCH, false ) );
getFragListBuilder( params ),
getFragmentsBuilder( params ) );
FieldQuery fieldQuery = fvh.getFieldQuery( query ); FieldQuery fieldQuery = fvh.getFieldQuery( query );
SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder( params );
// Highlight each document // Highlight each document
DocIterator iterator = docs.iterator(); DocIterator iterator = docs.iterator();
@ -376,7 +373,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
for (String fieldName : fieldNames) { for (String fieldName : fieldNames) {
fieldName = fieldName.trim(); fieldName = fieldName.trim();
if( useFastVectorHighlighter( params, schema, fieldName ) ) if( useFastVectorHighlighter( params, schema, fieldName ) )
doHighlightingByFastVectorHighlighter( fvh, fieldQuery, solrFb, req, docSummaries, docId, doc, fieldName ); doHighlightingByFastVectorHighlighter( fvh, fieldQuery, req, docSummaries, docId, doc, fieldName );
else else
doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName ); doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
} }
@ -504,12 +501,15 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
} }
private void doHighlightingByFastVectorHighlighter( FastVectorHighlighter highlighter, FieldQuery fieldQuery, private void doHighlightingByFastVectorHighlighter( FastVectorHighlighter highlighter, FieldQuery fieldQuery,
SolrFragmentsBuilder solrFb, SolrQueryRequest req, NamedList docSummaries, int docId, Document doc, SolrQueryRequest req, NamedList docSummaries, int docId, Document doc,
String fieldName ) throws IOException { String fieldName ) throws IOException {
SolrParams params = req.getParams(); SolrParams params = req.getParams();
SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder( fieldName, params );
String[] snippets = highlighter.getBestFragments( fieldQuery, req.getSearcher().getReader(), docId, fieldName, String[] snippets = highlighter.getBestFragments( fieldQuery, req.getSearcher().getReader(), docId, fieldName,
params.getFieldInt( fieldName, HighlightParams.FRAGSIZE, 100 ), params.getFieldInt( fieldName, HighlightParams.FRAGSIZE, 100 ),
params.getFieldInt( fieldName, HighlightParams.SNIPPETS, 1 ), params.getFieldInt( fieldName, HighlightParams.SNIPPETS, 1 ),
getFragListBuilder( fieldName, params ),
getFragmentsBuilder( fieldName, params ),
solrFb.getPreTags( params, fieldName ), solrFb.getPreTags( params, fieldName ),
solrFb.getPostTags( params, fieldName ), solrFb.getPostTags( params, fieldName ),
getEncoder( fieldName, params ) ); getEncoder( fieldName, params ) );