mirror of https://github.com/apache/lucene.git
SOLR-2030: FVH uses SolrEncoder
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@983212 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2ad126364
commit
6fbdff181a
|
@ -222,6 +222,8 @@ New Features
|
||||||
|
|
||||||
* SOLR-2021: Add SolrEncoder plugin to Highlighter. (koji)
|
* SOLR-2021: Add SolrEncoder plugin to Highlighter. (koji)
|
||||||
|
|
||||||
|
* SOLR-2030: Make FastVectorHighlighter use of SolrEncoder. (koji)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -1018,8 +1018,21 @@
|
||||||
<!-- Configure the single fragListBuilder -->
|
<!-- Configure the single fragListBuilder -->
|
||||||
<fragListBuilder name="single" class="org.apache.solr.highlight.SingleFragListBuilder"/>
|
<fragListBuilder name="single" class="org.apache.solr.highlight.SingleFragListBuilder"/>
|
||||||
|
|
||||||
|
<!-- default tag FragmentsBuilder -->
|
||||||
|
<fragmentsBuilder name="default" class="org.apache.solr.highlight.ScoreOrderFragmentsBuilder" default="true"/>
|
||||||
|
|
||||||
<!-- multi-colored tag FragmentsBuilder -->
|
<!-- multi-colored tag FragmentsBuilder -->
|
||||||
<fragmentsBuilder name="colored" class="org.apache.solr.highlight.MultiColoredScoreOrderFragmentsBuilder" default="true"/>
|
<fragmentsBuilder name="colored" class="org.apache.solr.highlight.ScoreOrderFragmentsBuilder">
|
||||||
|
<lst name="defaults">
|
||||||
|
<str name="hl.tag.pre"><![CDATA[
|
||||||
|
<b style="background:yellow">,<b style="background:lawgreen">,
|
||||||
|
<b style="background:aquamarine">,<b style="background:magenta">,
|
||||||
|
<b style="background:palegreen">,<b style="background:coral">,
|
||||||
|
<b style="background:wheat">,<b style="background:khaki">,
|
||||||
|
<b style="background:lime">,<b style="background:deepskyblue">]]></str>
|
||||||
|
<str name="hl.tag.post"><![CDATA[</b>]]></str>
|
||||||
|
</lst>
|
||||||
|
</fragmentsBuilder>
|
||||||
</highlighting>
|
</highlighting>
|
||||||
</searchComponent>
|
</searchComponent>
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ public interface HighlightParams {
|
||||||
|
|
||||||
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
||||||
|
|
||||||
public static final String USE_FVH = HIGHLIGHT + ".useFastVectorHighlighter";
|
public static final String USE_FVH = HIGHLIGHT + ".useFastVectorHighlighter";
|
||||||
|
public static final String TAG_PRE = HIGHLIGHT + ".tag.pre";
|
||||||
|
public static final String TAG_POST = HIGHLIGHT + ".tag.post";
|
||||||
|
|
||||||
// Formatter
|
// Formatter
|
||||||
public static final String SIMPLE = "simple";
|
public static final String SIMPLE = "simple";
|
||||||
|
|
|
@ -311,12 +311,16 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FragmentsBuilder getFragmentsBuilder( SolrParams params ){
|
protected FragmentsBuilder getFragmentsBuilder( SolrParams params ){
|
||||||
|
return getSolrFragmentsBuilder( params ).getFragmentsBuilder( params );
|
||||||
|
}
|
||||||
|
|
||||||
|
private SolrFragmentsBuilder getSolrFragmentsBuilder( SolrParams params ){
|
||||||
String fb = params.get( HighlightParams.FRAGMENTS_BUILDER );
|
String fb = params.get( 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 );
|
||||||
}
|
}
|
||||||
return solrFb.getFragmentsBuilder( params );
|
return solrFb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -361,6 +365,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
||||||
getFragListBuilder( params ),
|
getFragListBuilder( params ),
|
||||||
getFragmentsBuilder( 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();
|
||||||
|
@ -371,7 +376,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, req, docSummaries, docId, doc, fieldName );
|
doHighlightingByFastVectorHighlighter( fvh, fieldQuery, solrFb, req, docSummaries, docId, doc, fieldName );
|
||||||
else
|
else
|
||||||
doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
|
doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
|
||||||
}
|
}
|
||||||
|
@ -499,11 +504,15 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doHighlightingByFastVectorHighlighter( FastVectorHighlighter highlighter, FieldQuery fieldQuery,
|
private void doHighlightingByFastVectorHighlighter( FastVectorHighlighter highlighter, FieldQuery fieldQuery,
|
||||||
SolrQueryRequest req, NamedList docSummaries, int docId, Document doc, String fieldName ) throws IOException {
|
SolrFragmentsBuilder solrFb, SolrQueryRequest req, NamedList docSummaries, int docId, Document doc,
|
||||||
|
String fieldName ) throws IOException {
|
||||||
SolrParams params = req.getParams();
|
SolrParams params = req.getParams();
|
||||||
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 ),
|
||||||
|
solrFb.getPreTags( params, fieldName ),
|
||||||
|
solrFb.getPostTags( params, fieldName ),
|
||||||
|
getEncoder( fieldName, params ) );
|
||||||
if( snippets != null && snippets.length > 0 )
|
if( snippets != null && snippets.length > 0 )
|
||||||
docSummaries.add( fieldName, snippets );
|
docSummaries.add( fieldName, snippets );
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.solr.highlight;
|
|
||||||
|
|
||||||
import org.apache.lucene.search.vectorhighlight.BaseFragmentsBuilder;
|
|
||||||
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
|
||||||
import org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder;
|
|
||||||
import org.apache.solr.common.params.DefaultSolrParams;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
|
||||||
|
|
||||||
public class MultiColoredScoreOrderFragmentsBuilder extends
|
|
||||||
HighlightingPluginBase implements SolrFragmentsBuilder {
|
|
||||||
|
|
||||||
public FragmentsBuilder getFragmentsBuilder(SolrParams params) {
|
|
||||||
numRequests++;
|
|
||||||
if( defaults != null ) {
|
|
||||||
params = new DefaultSolrParams( params, defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ScoreOrderFragmentsBuilder(
|
|
||||||
BaseFragmentsBuilder.COLORED_PRE_TAGS, BaseFragmentsBuilder.COLORED_POST_TAGS );
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////// SolrInfoMBeans methods ///////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "MultiColoredScoreOrderFragmentsBuilder";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSource() {
|
|
||||||
return "$URL$";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSourceId() {
|
|
||||||
return "$Id$";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return "$Revision$";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.solr.highlight;
|
|
||||||
|
|
||||||
import org.apache.lucene.search.vectorhighlight.BaseFragmentsBuilder;
|
|
||||||
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
|
||||||
import org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder;
|
|
||||||
import org.apache.solr.common.params.DefaultSolrParams;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
|
||||||
|
|
||||||
public class MultiColoredSimpleFragmentsBuilder extends HighlightingPluginBase
|
|
||||||
implements SolrFragmentsBuilder {
|
|
||||||
|
|
||||||
public FragmentsBuilder getFragmentsBuilder(SolrParams params) {
|
|
||||||
numRequests++;
|
|
||||||
if( defaults != null ) {
|
|
||||||
params = new DefaultSolrParams( params, defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SimpleFragmentsBuilder(
|
|
||||||
BaseFragmentsBuilder.COLORED_PRE_TAGS, BaseFragmentsBuilder.COLORED_POST_TAGS );
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////// SolrInfoMBeans methods ///////////////////////
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "MultiColoredSimpleFragmentsBuilder";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSource() {
|
|
||||||
return "$URL$";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSourceId() {
|
|
||||||
return "$Id$";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return "$Revision$";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,19 +18,13 @@
|
||||||
package org.apache.solr.highlight;
|
package org.apache.solr.highlight;
|
||||||
|
|
||||||
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
||||||
import org.apache.solr.common.params.DefaultSolrParams;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
|
||||||
|
|
||||||
public class ScoreOrderFragmentsBuilder extends HighlightingPluginBase
|
public class ScoreOrderFragmentsBuilder extends SolrFragmentsBuilder {
|
||||||
implements SolrFragmentsBuilder {
|
|
||||||
|
|
||||||
public FragmentsBuilder getFragmentsBuilder(SolrParams params) {
|
@Override
|
||||||
numRequests++;
|
protected FragmentsBuilder getFragmentsBuilder(String[] preTags,
|
||||||
if( defaults != null ) {
|
String[] postTags) {
|
||||||
params = new DefaultSolrParams( params, defaults );
|
return new org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder( preTags, postTags );
|
||||||
}
|
|
||||||
|
|
||||||
return new org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -18,21 +18,19 @@
|
||||||
package org.apache.solr.highlight;
|
package org.apache.solr.highlight;
|
||||||
|
|
||||||
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
||||||
import org.apache.solr.common.params.DefaultSolrParams;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
|
||||||
|
|
||||||
public class SimpleFragmentsBuilder extends HighlightingPluginBase implements
|
public class SimpleFragmentsBuilder extends SolrFragmentsBuilder {
|
||||||
SolrFragmentsBuilder {
|
|
||||||
|
|
||||||
public FragmentsBuilder getFragmentsBuilder(SolrParams params) {
|
@Override
|
||||||
numRequests++;
|
protected FragmentsBuilder getFragmentsBuilder(String[] preTags,
|
||||||
if( defaults != null ) {
|
String[] postTags) {
|
||||||
params = new DefaultSolrParams( params, defaults );
|
return new org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder( preTags, postTags );
|
||||||
}
|
|
||||||
|
|
||||||
return new org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////// SolrInfoMBeans methods ///////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "SimpleFragmentsBuilder";
|
return "SimpleFragmentsBuilder";
|
||||||
|
|
|
@ -18,26 +18,53 @@
|
||||||
package org.apache.solr.highlight;
|
package org.apache.solr.highlight;
|
||||||
|
|
||||||
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
import org.apache.lucene.search.vectorhighlight.FragmentsBuilder;
|
||||||
|
import org.apache.solr.common.params.DefaultSolrParams;
|
||||||
|
import org.apache.solr.common.params.HighlightParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
|
||||||
import org.apache.solr.core.SolrInfoMBean;
|
import org.apache.solr.core.SolrInfoMBean;
|
||||||
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
|
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
|
||||||
|
|
||||||
public interface SolrFragmentsBuilder extends SolrInfoMBean, NamedListInitializedPlugin {
|
public abstract class SolrFragmentsBuilder extends HighlightingPluginBase
|
||||||
|
implements SolrInfoMBean, NamedListInitializedPlugin {
|
||||||
/** <code>init</code> will be called just once, immediately after creation.
|
|
||||||
* <p>The args are user-level initialization parameters that
|
public static final String DEFAULT_PRE_TAGS = "<em>";
|
||||||
* may be specified when declaring a request handler in
|
public static final String DEFAULT_POST_TAGS = "</em>";
|
||||||
* solrconfig.xml
|
|
||||||
*/
|
|
||||||
public void init( NamedList args);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a FragmentsBuilder appropriate for this field.
|
* Return a {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder} appropriate for this field.
|
||||||
*
|
*
|
||||||
* @param fieldName The name of the field
|
* @param fieldName The name of the field
|
||||||
* @param params The params controlling Highlighting
|
* @param params The params controlling Highlighting
|
||||||
* @return An appropriate FragmentsBuilder.
|
* @return An appropriate {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder}.
|
||||||
*/
|
*/
|
||||||
public FragmentsBuilder getFragmentsBuilder( SolrParams params );
|
public FragmentsBuilder getFragmentsBuilder(SolrParams params) {
|
||||||
|
numRequests++;
|
||||||
|
return getFragmentsBuilder( getPreTags( params, null ), getPostTags( params, null ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPreTags( SolrParams params, String fieldName ){
|
||||||
|
return getTags( params, HighlightParams.TAG_PRE, fieldName, DEFAULT_PRE_TAGS );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPostTags( SolrParams params, String fieldName ){
|
||||||
|
return getTags( params, HighlightParams.TAG_POST, fieldName, DEFAULT_POST_TAGS );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getTags( SolrParams params, String paramName, String fieldName, String def ){
|
||||||
|
if( defaults != null ) {
|
||||||
|
params = new DefaultSolrParams( params, defaults );
|
||||||
|
}
|
||||||
|
String value = null;
|
||||||
|
if( fieldName == null )
|
||||||
|
value = params.get( paramName, def );
|
||||||
|
else
|
||||||
|
value = params.getFieldParam( fieldName, paramName, def );
|
||||||
|
String[] tags = value.split( "," );
|
||||||
|
for( int i = 0; i < tags.length; i++ ){
|
||||||
|
tags[i] = tags[i].trim();
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract FragmentsBuilder getFragmentsBuilder( String[] preTags, String[] postTags );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue