Remove XSimpleFragmentsBuilder and XScoreOrderFragmentsBuilder since the only difference

to the lucene version is that `discreteMultiValueHighlighting` does default to `true`. Yet
we set this anyway in the HighlightingPhase such that the classes are obsolet.
This commit is contained in:
Simon Willnauer 2013-04-26 20:04:38 +02:00
parent 355f80adc9
commit 8a7f81104f
6 changed files with 10 additions and 158 deletions

View File

@ -21,7 +21,6 @@ package org.apache.lucene.search.vectorhighlight;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
import org.apache.lucene.queries.FilterClause;
import org.apache.lucene.search.*;
import org.apache.lucene.search.spans.SpanTermQuery;

View File

@ -1,82 +0,0 @@
package org.apache.lucene.search.vectorhighlight;
/**
* 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.
*/
import org.apache.lucene.search.vectorhighlight.FieldFragList.WeightedFragInfo;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* An implementation of FragmentsBuilder that outputs score-order fragments.
*/
public class XScoreOrderFragmentsBuilder extends BaseFragmentsBuilder {
/**
* a constructor.
*/
public XScoreOrderFragmentsBuilder() {
super();
setDiscreteMultiValueHighlighting(true);
}
/**
* a constructor.
*
* @param preTags array of pre-tags for markup terms.
* @param postTags array of post-tags for markup terms.
*/
public XScoreOrderFragmentsBuilder(String[] preTags, String[] postTags) {
super(preTags, postTags);
setDiscreteMultiValueHighlighting(true);
}
public XScoreOrderFragmentsBuilder(BoundaryScanner bs) {
super(bs);
setDiscreteMultiValueHighlighting(true);
}
public XScoreOrderFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs) {
super(preTags, postTags, bs);
setDiscreteMultiValueHighlighting(true);
}
/**
* Sort by score the list of WeightedFragInfo
*/
@Override
public List<WeightedFragInfo> getWeightedFragInfoList(List<WeightedFragInfo> src) {
Collections.sort(src, new ScoreComparator());
return src;
}
public static class ScoreComparator implements Comparator<WeightedFragInfo> {
public int compare(WeightedFragInfo o1, WeightedFragInfo o2) {
if (o1.getTotalBoost() > o2.getTotalBoost()) return -1;
else if (o1.getTotalBoost() < o2.getTotalBoost()) return 1;
// if same score then check startOffset
else {
if (o1.getStartOffset() < o2.getStartOffset()) return -1;
else if (o1.getStartOffset() > o2.getStartOffset()) return 1;
}
return 0;
}
}
}

View File

@ -1,65 +0,0 @@
package org.apache.lucene.search.vectorhighlight;
/**
* 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.
*/
import org.apache.lucene.search.vectorhighlight.FieldFragList.WeightedFragInfo;
import java.util.List;
/**
* A simple implementation of FragmentsBuilder.
*/
public class XSimpleFragmentsBuilder extends BaseFragmentsBuilder {
/**
* a constructor.
*/
public XSimpleFragmentsBuilder() {
super();
setDiscreteMultiValueHighlighting(true);
}
/**
* a constructor.
*
* @param preTags array of pre-tags for markup terms.
* @param postTags array of post-tags for markup terms.
*/
public XSimpleFragmentsBuilder(String[] preTags, String[] postTags) {
super(preTags, postTags);
setDiscreteMultiValueHighlighting(true);
}
public XSimpleFragmentsBuilder(BoundaryScanner bs) {
super(bs);
setDiscreteMultiValueHighlighting(true);
}
public XSimpleFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs) {
super(preTags, postTags, bs);
setDiscreteMultiValueHighlighting(true);
}
/**
* do nothing. return the source list.
*/
@Override
public List<WeightedFragInfo> getWeightedFragInfoList(List<WeightedFragInfo> src) {
return src;
}
}

View File

@ -120,7 +120,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
for (String fieldName : fieldNamesToHighlight) {
FieldMapper mapper = documentMapper.mappers().smartNameFieldMapper(fieldName);
FieldMapper<?> mapper = documentMapper.mappers().smartNameFieldMapper(fieldName);
if (mapper == null) {
MapperService.SmartNameFieldMappers fullMapper = context.mapperService().smartName(fieldName);
if (fullMapper == null || !fullMapper.hasDocMapper()) {
@ -262,7 +262,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
fragListBuilder = new SingleFragListBuilder();
if (mapper.fieldType().stored()) {
fragmentsBuilder = new XSimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
fragmentsBuilder = new SimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
} else {
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner);
}
@ -270,13 +270,13 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
fragListBuilder = field.fragmentOffset() == -1 ? new XSimpleFragListBuilder() : new XSimpleFragListBuilder(field.fragmentOffset());
if (field.scoreOrdered()) {
if (mapper.fieldType().stored()) {
fragmentsBuilder = new XScoreOrderFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
fragmentsBuilder = new ScoreOrderFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
} else {
fragmentsBuilder = new SourceScoreOrderFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner);
}
} else {
if (mapper.fieldType().stored()) {
fragmentsBuilder = new XSimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
fragmentsBuilder = new SimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner);
} else {
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner);
}

View File

@ -24,7 +24,7 @@ import org.apache.lucene.document.TextField;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.vectorhighlight.BoundaryScanner;
import org.apache.lucene.search.vectorhighlight.XScoreOrderFragmentsBuilder;
import org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.lookup.SearchLookup;
@ -35,7 +35,7 @@ import java.util.List;
/**
*
*/
public class SourceScoreOrderFragmentsBuilder extends XScoreOrderFragmentsBuilder {
public class SourceScoreOrderFragmentsBuilder extends ScoreOrderFragmentsBuilder {
private final FieldMapper mapper;

View File

@ -24,7 +24,7 @@ import org.apache.lucene.document.TextField;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.vectorhighlight.BoundaryScanner;
import org.apache.lucene.search.vectorhighlight.XSimpleFragmentsBuilder;
import org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.lookup.SearchLookup;
@ -35,13 +35,13 @@ import java.util.List;
/**
*
*/
public class SourceSimpleFragmentsBuilder extends XSimpleFragmentsBuilder {
public class SourceSimpleFragmentsBuilder extends SimpleFragmentsBuilder {
private final FieldMapper mapper;
private final FieldMapper<?> mapper;
private final SearchContext searchContext;
public SourceSimpleFragmentsBuilder(FieldMapper mapper, SearchContext searchContext,
public SourceSimpleFragmentsBuilder(FieldMapper<?> mapper, SearchContext searchContext,
String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) {
super(preTags, postTags, boundaryScanner);
this.mapper = mapper;