You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2017/01/14 18:52:17 UTC
lucene-solr:branch_6_4: Fix compile warning in Lucene Core;
make Eclipse happy by moving Java-1-like-side-by-side class to
separate file
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6_4 ddca27a7c -> d4b31f909
Fix compile warning in Lucene Core; make Eclipse happy by moving Java-1-like-side-by-side class to separate file
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d4b31f90
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d4b31f90
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d4b31f90
Branch: refs/heads/branch_6_4
Commit: d4b31f90995dd4a8f461b5d6725cfba4062d92b8
Parents: ddca27a
Author: Uwe Schindler <us...@apache.org>
Authored: Sat Jan 14 19:46:59 2017 +0100
Committer: Uwe Schindler <us...@apache.org>
Committed: Sat Jan 14 19:51:55 2017 +0100
----------------------------------------------------------------------
.../lucene/search/MultiCollectorManager.java | 6 +-
.../solr/highlight/LuceneRegexFragmenter.java | 217 +++++++++++++++++++
.../apache/solr/highlight/RegexFragmenter.java | 196 -----------------
3 files changed, 221 insertions(+), 198 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d4b31f90/lucene/core/src/java/org/apache/lucene/search/MultiCollectorManager.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiCollectorManager.java b/lucene/core/src/java/org/apache/lucene/search/MultiCollectorManager.java
index 9549cde..a8c6d1c 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MultiCollectorManager.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MultiCollectorManager.java
@@ -31,8 +31,10 @@ public class MultiCollectorManager implements CollectorManager<MultiCollectorMan
final private CollectorManager<Collector, ?>[] collectorManagers;
- public MultiCollectorManager(final CollectorManager... collectorManagers) {
- this.collectorManagers = collectorManagers;
+ @SafeVarargs
+ @SuppressWarnings({"varargs", "unchecked"})
+ public MultiCollectorManager(final CollectorManager<? extends Collector, ?>... collectorManagers) {
+ this.collectorManagers = (CollectorManager[]) collectorManagers;
}
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d4b31f90/solr/core/src/java/org/apache/solr/highlight/LuceneRegexFragmenter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/highlight/LuceneRegexFragmenter.java b/solr/core/src/java/org/apache/solr/highlight/LuceneRegexFragmenter.java
new file mode 100644
index 0000000..0dc3340
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/highlight/LuceneRegexFragmenter.java
@@ -0,0 +1,217 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
+import org.apache.lucene.search.highlight.Fragmenter;
+
+/**
+ * Fragmenter that tries to produce snippets that "look" like a regular
+ * expression.
+ *
+ * NOTE: the default for <code>maxAnalyzedChars</code> is much lower for this
+ * fragmenter. After this limit is exhausted, fragments are produced in the
+ * same way as <code>GapFragmenter</code>
+ */
+class LuceneRegexFragmenter implements Fragmenter
+{
+ // ** defaults
+ public static final int DEFAULT_FRAGMENT_SIZE = 70;
+ public static final int DEFAULT_INCREMENT_GAP = 50;
+ public static final float DEFAULT_SLOP = 0.6f;
+ public static final int DEFAULT_MAX_ANALYZED_CHARS = 10000;
+
+ // ** settings
+
+ // desired length of fragments, in characters
+ protected int targetFragChars;
+ // increment gap which indicates a new fragment should occur
+ // (often due to multi-valued fields)
+ protected int incrementGapThreshold;
+ // factor by which we are allowed to bend the frag size (larger or smaller)
+ protected float slop;
+ // analysis limit (ensures we don't waste too much time on long fields)
+ protected int maxAnalyzedChars;
+ // default desirable pattern for text fragments.
+ protected Pattern textRE;
+
+
+ // ** state
+ protected int currentNumFrags;
+ protected int currentOffset;
+ protected int targetOffset;
+ protected int[] hotspots;
+
+ private PositionIncrementAttribute posIncAtt;
+ private OffsetAttribute offsetAtt;
+
+ // ** other
+ // note: could dynamically change size of sentences extracted to match
+ // target frag size
+ public static final String
+ DEFAULT_PATTERN_RAW = "[-\\w ,\\n\"']{20,200}";
+ public static final Pattern
+ DEFAULT_PATTERN = Pattern.compile(DEFAULT_PATTERN_RAW);
+
+
+ public LuceneRegexFragmenter() {
+ this(DEFAULT_FRAGMENT_SIZE,
+ DEFAULT_INCREMENT_GAP,
+ DEFAULT_SLOP,
+ DEFAULT_MAX_ANALYZED_CHARS);
+ }
+ public LuceneRegexFragmenter(int targetFragChars) {
+ this(targetFragChars,
+ DEFAULT_INCREMENT_GAP,
+ DEFAULT_SLOP,
+ DEFAULT_MAX_ANALYZED_CHARS);
+ }
+
+ public LuceneRegexFragmenter(int targetFragChars,
+ int incrementGapThreshold,
+ float slop,
+ int maxAnalyzedChars ) {
+ this(targetFragChars, incrementGapThreshold, slop, maxAnalyzedChars,
+ DEFAULT_PATTERN);
+
+ }
+
+ public LuceneRegexFragmenter(int targetFragChars,
+ int incrementGapThreshold,
+ float slop,
+ int maxAnalyzedChars,
+ Pattern targetPattern) {
+ this.targetFragChars = targetFragChars;
+ this.incrementGapThreshold = incrementGapThreshold;
+ this.slop = slop;
+ this.maxAnalyzedChars = maxAnalyzedChars;
+ this.textRE = targetPattern;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.lucene.search.highlight.TextFragmenter#start(java.lang.String)
+ */
+ @Override
+ public void start(String originalText, TokenStream tokenStream) {
+ currentNumFrags = 1;
+ currentOffset = 0;
+ addHotSpots(originalText);
+ posIncAtt = tokenStream.getAttribute(PositionIncrementAttribute.class);
+ offsetAtt = tokenStream.getAttribute(OffsetAttribute.class);
+ }
+
+ ////////////////////////////////////
+ // pre-analysis
+ ////////////////////////////////////
+
+ protected void addHotSpots(String text) {
+ //System.out.println("hot spotting");
+ ArrayList<Integer> temphs = new ArrayList<>(
+ text.length() / targetFragChars);
+ Matcher match = textRE.matcher(text);
+ int cur = 0;
+ while(match.find() && cur < maxAnalyzedChars) {
+ int start=match.start(), end=match.end();
+ temphs.add(start);
+ temphs.add(end);
+ cur = end;
+ //System.out.println("Matched " + match.group());
+ }
+ hotspots = new int[temphs.size()];
+ for(int i = 0; i < temphs.size(); i++) {
+ hotspots[i] = temphs.get(i);
+ }
+ // perhaps not necessary--I don't know if re matches are non-overlapping
+ Arrays.sort(hotspots);
+ }
+
+ ////////////////////////////////////
+ // fragmenting
+ ////////////////////////////////////
+
+ /* (non-Javadoc)
+ * @see org.apache.lucene.search.highlight.TextFragmenter#isNewFragment(org.apache.lucene.analysis.Token)
+ */
+ @Override
+ public boolean isNewFragment()
+ {
+ boolean isNewFrag = false;
+ int minFragLen = (int)((1.0f - slop)*targetFragChars);
+ int endOffset = offsetAtt.endOffset();
+
+ // ** determin isNewFrag
+ if(posIncAtt.getPositionIncrement() > incrementGapThreshold) {
+ // large position gaps always imply new fragments
+ isNewFrag = true;
+
+ } else if(endOffset - currentOffset < minFragLen) {
+ // we're not in our range of flexibility
+ isNewFrag = false;
+
+ } else if(targetOffset > 0) {
+ // we've already decided on a target
+ isNewFrag = endOffset > targetOffset;
+
+ } else {
+ // we might be able to do something
+ int minOffset = currentOffset + minFragLen;
+ int maxOffset = (int)(currentOffset + (1.0f + slop)*targetFragChars);
+ int hotIndex;
+
+ // look for a close hotspot
+ hotIndex = Arrays.binarySearch(hotspots, endOffset);
+ if(hotIndex < 0) hotIndex = -hotIndex;
+ if(hotIndex >= hotspots.length) {
+ // no more hotspots in this input stream
+ targetOffset = currentOffset + targetFragChars;
+
+ } else if(hotspots[hotIndex] > maxOffset) {
+ // no hotspots within slop
+ targetOffset = currentOffset + targetFragChars;
+
+ } else {
+ // try to find hotspot in slop
+ int goal = hotspots[hotIndex];
+ while(goal < minOffset && hotIndex < hotspots.length) {
+ hotIndex++;
+ goal = hotspots[hotIndex];
+ }
+ targetOffset = goal <= maxOffset ? goal : currentOffset + targetFragChars;
+ }
+
+ isNewFrag = endOffset > targetOffset;
+ }
+
+ // ** operate on isNewFrag
+ if(isNewFrag) {
+ currentNumFrags++;
+ currentOffset = endOffset;
+ targetOffset = -1;
+ }
+ return isNewFrag;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d4b31f90/solr/core/src/java/org/apache/solr/highlight/RegexFragmenter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/highlight/RegexFragmenter.java b/solr/core/src/java/org/apache/solr/highlight/RegexFragmenter.java
index a80141e..b755b2d 100644
--- a/solr/core/src/java/org/apache/solr/highlight/RegexFragmenter.java
+++ b/solr/core/src/java/org/apache/solr/highlight/RegexFragmenter.java
@@ -16,14 +16,8 @@
*/
package org.apache.solr.highlight;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
-import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.search.highlight.Fragmenter;
import org.apache.lucene.search.highlight.NullFragmenter;
import org.apache.solr.common.params.HighlightParams;
@@ -94,193 +88,3 @@ public class RegexFragmenter extends HighlightingPluginBase implements SolrFragm
return "RegexFragmenter (" + defaultPatternRaw + ")";
}
}
-
-
-/**
- * Fragmenter that tries to produce snippets that "look" like a regular
- * expression.
- *
- * NOTE: the default for <code>maxAnalyzedChars</code> is much lower for this
- * fragmenter. After this limit is exhausted, fragments are produced in the
- * same way as <code>GapFragmenter</code>
- */
-class LuceneRegexFragmenter implements Fragmenter
-{
- // ** defaults
- public static final int DEFAULT_FRAGMENT_SIZE = 70;
- public static final int DEFAULT_INCREMENT_GAP = 50;
- public static final float DEFAULT_SLOP = 0.6f;
- public static final int DEFAULT_MAX_ANALYZED_CHARS = 10000;
-
- // ** settings
-
- // desired length of fragments, in characters
- protected int targetFragChars;
- // increment gap which indicates a new fragment should occur
- // (often due to multi-valued fields)
- protected int incrementGapThreshold;
- // factor by which we are allowed to bend the frag size (larger or smaller)
- protected float slop;
- // analysis limit (ensures we don't waste too much time on long fields)
- protected int maxAnalyzedChars;
- // default desirable pattern for text fragments.
- protected Pattern textRE;
-
-
- // ** state
- protected int currentNumFrags;
- protected int currentOffset;
- protected int targetOffset;
- protected int[] hotspots;
-
- private PositionIncrementAttribute posIncAtt;
- private OffsetAttribute offsetAtt;
-
- // ** other
- // note: could dynamically change size of sentences extracted to match
- // target frag size
- public static final String
- DEFAULT_PATTERN_RAW = "[-\\w ,\\n\"']{20,200}";
- public static final Pattern
- DEFAULT_PATTERN = Pattern.compile(DEFAULT_PATTERN_RAW);
-
-
- public LuceneRegexFragmenter() {
- this(DEFAULT_FRAGMENT_SIZE,
- DEFAULT_INCREMENT_GAP,
- DEFAULT_SLOP,
- DEFAULT_MAX_ANALYZED_CHARS);
- }
- public LuceneRegexFragmenter(int targetFragChars) {
- this(targetFragChars,
- DEFAULT_INCREMENT_GAP,
- DEFAULT_SLOP,
- DEFAULT_MAX_ANALYZED_CHARS);
- }
-
- public LuceneRegexFragmenter(int targetFragChars,
- int incrementGapThreshold,
- float slop,
- int maxAnalyzedChars ) {
- this(targetFragChars, incrementGapThreshold, slop, maxAnalyzedChars,
- DEFAULT_PATTERN);
-
- }
-
- public LuceneRegexFragmenter(int targetFragChars,
- int incrementGapThreshold,
- float slop,
- int maxAnalyzedChars,
- Pattern targetPattern) {
- this.targetFragChars = targetFragChars;
- this.incrementGapThreshold = incrementGapThreshold;
- this.slop = slop;
- this.maxAnalyzedChars = maxAnalyzedChars;
- this.textRE = targetPattern;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.lucene.search.highlight.TextFragmenter#start(java.lang.String)
- */
- @Override
- public void start(String originalText, TokenStream tokenStream) {
- currentNumFrags = 1;
- currentOffset = 0;
- addHotSpots(originalText);
- posIncAtt = tokenStream.getAttribute(PositionIncrementAttribute.class);
- offsetAtt = tokenStream.getAttribute(OffsetAttribute.class);
- }
-
- ////////////////////////////////////
- // pre-analysis
- ////////////////////////////////////
-
- protected void addHotSpots(String text) {
- //System.out.println("hot spotting");
- ArrayList<Integer> temphs = new ArrayList<>(
- text.length() / targetFragChars);
- Matcher match = textRE.matcher(text);
- int cur = 0;
- while(match.find() && cur < maxAnalyzedChars) {
- int start=match.start(), end=match.end();
- temphs.add(start);
- temphs.add(end);
- cur = end;
- //System.out.println("Matched " + match.group());
- }
- hotspots = new int[temphs.size()];
- for(int i = 0; i < temphs.size(); i++) {
- hotspots[i] = temphs.get(i);
- }
- // perhaps not necessary--I don't know if re matches are non-overlapping
- Arrays.sort(hotspots);
- }
-
- ////////////////////////////////////
- // fragmenting
- ////////////////////////////////////
-
- /* (non-Javadoc)
- * @see org.apache.lucene.search.highlight.TextFragmenter#isNewFragment(org.apache.lucene.analysis.Token)
- */
- @Override
- public boolean isNewFragment()
- {
- boolean isNewFrag = false;
- int minFragLen = (int)((1.0f - slop)*targetFragChars);
- int endOffset = offsetAtt.endOffset();
-
- // ** determin isNewFrag
- if(posIncAtt.getPositionIncrement() > incrementGapThreshold) {
- // large position gaps always imply new fragments
- isNewFrag = true;
-
- } else if(endOffset - currentOffset < minFragLen) {
- // we're not in our range of flexibility
- isNewFrag = false;
-
- } else if(targetOffset > 0) {
- // we've already decided on a target
- isNewFrag = endOffset > targetOffset;
-
- } else {
- // we might be able to do something
- int minOffset = currentOffset + minFragLen;
- int maxOffset = (int)(currentOffset + (1.0f + slop)*targetFragChars);
- int hotIndex;
-
- // look for a close hotspot
- hotIndex = Arrays.binarySearch(hotspots, endOffset);
- if(hotIndex < 0) hotIndex = -hotIndex;
- if(hotIndex >= hotspots.length) {
- // no more hotspots in this input stream
- targetOffset = currentOffset + targetFragChars;
-
- } else if(hotspots[hotIndex] > maxOffset) {
- // no hotspots within slop
- targetOffset = currentOffset + targetFragChars;
-
- } else {
- // try to find hotspot in slop
- int goal = hotspots[hotIndex];
- while(goal < minOffset && hotIndex < hotspots.length) {
- hotIndex++;
- goal = hotspots[hotIndex];
- }
- targetOffset = goal <= maxOffset ? goal : currentOffset + targetFragChars;
- }
-
- isNewFrag = endOffset > targetOffset;
- }
-
- // ** operate on isNewFrag
- if(isNewFrag) {
- currentNumFrags++;
- currentOffset = endOffset;
- targetOffset = -1;
- }
- return isNewFrag;
- }
-
-}