From c0f9e337ce5271c5cd5ff08a381d8cd4670abc9d Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 25 Jun 2012 17:00:01 +0200 Subject: [PATCH] elasticsearch fails to start due to verification error, closes #2051. --- .../ScoreOrderFragmentsBuilder.java | 78 ------------------- .../XScoreOrderFragmentsBuilder.java | 78 +++++++++++++++++++ ...lder.java => XSimpleFragmentsBuilder.java} | 59 +++++++------- .../search/highlight/HighlightPhase.java | 6 +- .../SourceScoreOrderFragmentsBuilder.java | 4 +- .../SourceSimpleFragmentsBuilder.java | 4 +- 6 files changed, 114 insertions(+), 115 deletions(-) delete mode 100644 src/main/java/org/apache/lucene/search/vectorhighlight/ScoreOrderFragmentsBuilder.java create mode 100644 src/main/java/org/apache/lucene/search/vectorhighlight/XScoreOrderFragmentsBuilder.java rename src/main/java/org/apache/lucene/search/vectorhighlight/{SimpleFragmentsBuilder.java => XSimpleFragmentsBuilder.java} (54%) diff --git a/src/main/java/org/apache/lucene/search/vectorhighlight/ScoreOrderFragmentsBuilder.java b/src/main/java/org/apache/lucene/search/vectorhighlight/ScoreOrderFragmentsBuilder.java deleted file mode 100644 index 5e8f025dd5c..00000000000 --- a/src/main/java/org/apache/lucene/search/vectorhighlight/ScoreOrderFragmentsBuilder.java +++ /dev/null @@ -1,78 +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 ScoreOrderFragmentsBuilder extends AbstractFragmentsBuilder { - - /** - * a constructor. - */ - public ScoreOrderFragmentsBuilder(){ - super(); - } - - /** - * a constructor. - * - * @param preTags array of pre-tags for markup terms. - * @param postTags array of post-tags for markup terms. - */ - public ScoreOrderFragmentsBuilder(String[] preTags, String[] postTags){ - super( preTags, postTags ); - } - - public ScoreOrderFragmentsBuilder(BoundaryScanner bs){ - super( bs ); - } - - public ScoreOrderFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs){ - super( preTags, postTags, bs ); - } - - /** - * Sort by score the list of WeightedFragInfo - */ - @Override - public List getWeightedFragInfoList( List src ) { - Collections.sort( src, new ScoreComparator() ); - return src; - } - - public static class ScoreComparator implements Comparator { - - public int compare( WeightedFragInfo o1, WeightedFragInfo o2 ) { - if( o1.totalBoost > o2.totalBoost ) return -1; - else if( o1.totalBoost < o2.totalBoost ) return 1; - // if same score then check startOffset - else{ - if( o1.startOffset < o2.startOffset ) return -1; - else if( o1.startOffset > o2.startOffset ) return 1; - } - return 0; - } - } -} diff --git a/src/main/java/org/apache/lucene/search/vectorhighlight/XScoreOrderFragmentsBuilder.java b/src/main/java/org/apache/lucene/search/vectorhighlight/XScoreOrderFragmentsBuilder.java new file mode 100644 index 00000000000..5e01d3112ca --- /dev/null +++ b/src/main/java/org/apache/lucene/search/vectorhighlight/XScoreOrderFragmentsBuilder.java @@ -0,0 +1,78 @@ +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 AbstractFragmentsBuilder { + + /** + * a constructor. + */ + public XScoreOrderFragmentsBuilder() { + super(); + } + + /** + * 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); + } + + public XScoreOrderFragmentsBuilder(BoundaryScanner bs) { + super(bs); + } + + public XScoreOrderFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs) { + super(preTags, postTags, bs); + } + + /** + * Sort by score the list of WeightedFragInfo + */ + @Override + public List getWeightedFragInfoList(List src) { + Collections.sort(src, new ScoreComparator()); + return src; + } + + public static class ScoreComparator implements Comparator { + + public int compare(WeightedFragInfo o1, WeightedFragInfo o2) { + if (o1.totalBoost > o2.totalBoost) return -1; + else if (o1.totalBoost < o2.totalBoost) return 1; + // if same score then check startOffset + else { + if (o1.startOffset < o2.startOffset) return -1; + else if (o1.startOffset > o2.startOffset) return 1; + } + return 0; + } + } +} diff --git a/src/main/java/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilder.java b/src/main/java/org/apache/lucene/search/vectorhighlight/XSimpleFragmentsBuilder.java similarity index 54% rename from src/main/java/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilder.java rename to src/main/java/org/apache/lucene/search/vectorhighlight/XSimpleFragmentsBuilder.java index ff649f9ae67..d8f133c14ef 100644 --- a/src/main/java/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilder.java +++ b/src/main/java/org/apache/lucene/search/vectorhighlight/XSimpleFragmentsBuilder.java @@ -23,40 +23,39 @@ import java.util.List; /** * A simple implementation of FragmentsBuilder. - * */ -public class SimpleFragmentsBuilder extends AbstractFragmentsBuilder { +public class XSimpleFragmentsBuilder extends AbstractFragmentsBuilder { - /** - * a constructor. - */ - public SimpleFragmentsBuilder() { - super(); - } + /** + * a constructor. + */ + public XSimpleFragmentsBuilder() { + super(); + } - /** - * a constructor. - * - * @param preTags array of pre-tags for markup terms. - * @param postTags array of post-tags for markup terms. - */ - public SimpleFragmentsBuilder(String[] preTags, String[] postTags) { - super( preTags, postTags ); - } + /** + * 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); + } - public SimpleFragmentsBuilder(BoundaryScanner bs) { - super( bs ); - } + public XSimpleFragmentsBuilder(BoundaryScanner bs) { + super(bs); + } - public SimpleFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs) { - super( preTags, postTags, bs ); - } + public XSimpleFragmentsBuilder(String[] preTags, String[] postTags, BoundaryScanner bs) { + super(preTags, postTags, bs); + } - /** - * do nothing. return the source list. - */ - @Override - public List getWeightedFragInfoList( List src ) { - return src; - } + /** + * do nothing. return the source list. + */ + @Override + public List getWeightedFragInfoList(List src) { + return src; + } } diff --git a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index 019baa7f35f..90bb9b26d0f 100644 --- a/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -265,7 +265,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase { fragListBuilder = new SingleFragListBuilder(); if (mapper.stored()) { - fragmentsBuilder = new SimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); + fragmentsBuilder = new XSimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); } else { fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner); } @@ -277,13 +277,13 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase { if (field.scoreOrdered()) { if (mapper.stored()) { - fragmentsBuilder = new ScoreOrderFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); + fragmentsBuilder = new XScoreOrderFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); } else { fragmentsBuilder = new SourceScoreOrderFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner); } } else { if (mapper.stored()) { - fragmentsBuilder = new SimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); + fragmentsBuilder = new XSimpleFragmentsBuilder(field.preTags(), field.postTags(), boundaryScanner); } else { fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.preTags(), field.postTags(), boundaryScanner); } diff --git a/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceScoreOrderFragmentsBuilder.java b/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceScoreOrderFragmentsBuilder.java index 0443616ca05..84ec390b2e6 100644 --- a/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceScoreOrderFragmentsBuilder.java +++ b/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceScoreOrderFragmentsBuilder.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.highlight.vectorhighlight; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.vectorhighlight.BoundaryScanner; -import org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder; +import org.apache.lucene.search.vectorhighlight.XScoreOrderFragmentsBuilder; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SearchLookup; @@ -33,7 +33,7 @@ import java.util.List; /** * */ -public class SourceScoreOrderFragmentsBuilder extends ScoreOrderFragmentsBuilder { +public class SourceScoreOrderFragmentsBuilder extends XScoreOrderFragmentsBuilder { private final FieldMapper mapper; diff --git a/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceSimpleFragmentsBuilder.java b/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceSimpleFragmentsBuilder.java index 2cb35f01546..f3fd38ff1b3 100644 --- a/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceSimpleFragmentsBuilder.java +++ b/src/main/java/org/elasticsearch/search/highlight/vectorhighlight/SourceSimpleFragmentsBuilder.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.highlight.vectorhighlight; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.vectorhighlight.BoundaryScanner; -import org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder; +import org.apache.lucene.search.vectorhighlight.XSimpleFragmentsBuilder; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SearchLookup; @@ -33,7 +33,7 @@ import java.util.List; /** * */ -public class SourceSimpleFragmentsBuilder extends SimpleFragmentsBuilder { +public class SourceSimpleFragmentsBuilder extends XSimpleFragmentsBuilder { private final FieldMapper mapper;