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

@ -133,6 +133,9 @@ API Changes
* LUCENE-2603: Add setMultiValuedSeparator(char) method to set an arbitrary
char that is used when concatenating multiValued data. Default is a space
(' '). 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

View File

@ -92,7 +92,8 @@ public class FastVectorHighlighter {
*/
public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId,
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 );
}
@ -111,7 +112,8 @@ public class FastVectorHighlighter {
*/
public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId,
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 );
}
@ -123,6 +125,8 @@ public class FastVectorHighlighter {
* @param docId document id to be highlighted
* @param fieldName field of the document to be highlighted
* @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 postTags post-tags to be used to highlight terms
* @param encoder an encoder that generates encoded text
@ -130,9 +134,10 @@ public class FastVectorHighlighter {
* @throws IOException
*/
public final String getBestFragment( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize, String[] preTags, String[] postTags,
Encoder encoder ) throws IOException {
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize );
String fieldName, int fragCharSize,
FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder,
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 );
}
@ -145,6 +150,8 @@ public class FastVectorHighlighter {
* @param fieldName field of the document to be highlighted
* @param fragCharSize the length (number of chars) of a fragment
* @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 postTags post-tags to be used to highlight terms
* @param encoder an encoder that generates encoded text
@ -153,14 +160,17 @@ public class FastVectorHighlighter {
* @throws IOException
*/
public final String[] getBestFragments( final FieldQuery fieldQuery, IndexReader reader, int docId,
String fieldName, int fragCharSize, int maxNumFragments, String[] preTags, String[] postTags,
Encoder encoder ) throws IOException {
FieldFragList fieldFragList = getFieldFragList( fieldQuery, reader, docId, fieldName, fragCharSize );
String fieldName, int fragCharSize, int maxNumFragments,
FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder,
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,
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 {
FieldTermStack fieldTermStack = new FieldTermStack( reader, docId, fieldName, 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 );
}
protected FragListBuilder getFragListBuilder( SolrParams params ){
String flb = params.get( HighlightParams.FRAG_LIST_BUILDER );
protected FragListBuilder getFragListBuilder( String fieldName, SolrParams params ){
String flb = params.getFieldParam( fieldName, HighlightParams.FRAG_LIST_BUILDER );
SolrFragListBuilder solrFlb = fragListBuilders.get( flb );
if( solrFlb == null ){
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 );
}
protected FragmentsBuilder getFragmentsBuilder( SolrParams params ){
return getSolrFragmentsBuilder( params ).getFragmentsBuilder( params );
protected FragmentsBuilder getFragmentsBuilder( String fieldName, SolrParams params ){
return getSolrFragmentsBuilder( fieldName, params ).getFragmentsBuilder( params );
}
private SolrFragmentsBuilder getSolrFragmentsBuilder( SolrParams params ){
String fb = params.get( HighlightParams.FRAGMENTS_BUILDER );
private SolrFragmentsBuilder getSolrFragmentsBuilder( String fieldName, SolrParams params ){
String fb = params.getFieldParam( fieldName, HighlightParams.FRAGMENTS_BUILDER );
SolrFragmentsBuilder solrFb = fragmentsBuilders.get( fb );
if( solrFb == null ){
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
params.getBool( HighlightParams.USE_PHRASE_HIGHLIGHTER, true ),
// FVH cannot process hl.requireFieldMatch parameter per-field basis
params.getBool( HighlightParams.FIELD_MATCH, false ),
getFragListBuilder( params ),
getFragmentsBuilder( params ) );
params.getBool( HighlightParams.FIELD_MATCH, false ) );
FieldQuery fieldQuery = fvh.getFieldQuery( query );
SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder( params );
// Highlight each document
DocIterator iterator = docs.iterator();
@ -376,7 +373,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
for (String fieldName : fieldNames) {
fieldName = fieldName.trim();
if( useFastVectorHighlighter( params, schema, fieldName ) )
doHighlightingByFastVectorHighlighter( fvh, fieldQuery, solrFb, req, docSummaries, docId, doc, fieldName );
doHighlightingByFastVectorHighlighter( fvh, fieldQuery, req, docSummaries, docId, doc, fieldName );
else
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,
SolrFragmentsBuilder solrFb, SolrQueryRequest req, NamedList docSummaries, int docId, Document doc,
SolrQueryRequest req, NamedList docSummaries, int docId, Document doc,
String fieldName ) throws IOException {
SolrParams params = req.getParams();
SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder( fieldName, params );
String[] snippets = highlighter.getBestFragments( fieldQuery, req.getSearcher().getReader(), docId, fieldName,
params.getFieldInt( fieldName, HighlightParams.FRAGSIZE, 100 ),
params.getFieldInt( fieldName, HighlightParams.SNIPPETS, 1 ),
getFragListBuilder( fieldName, params ),
getFragmentsBuilder( fieldName, params ),
solrFb.getPreTags( params, fieldName ),
solrFb.getPostTags( params, fieldName ),
getEncoder( fieldName, params ) );