From 4f89f82e7014c5259274a4a8513ec6624ac07a5b Mon Sep 17 00:00:00 2001 From: Adam Constabaris Date: Tue, 13 Sep 2022 15:52:41 -0400 Subject: [PATCH] Build against Lucene 9 Mostly package renames in solr/lucene, but also added a class that appears to be missing from upstream. --- pom.xml | 18 +++--- .../umich/lib/converters/ISBNNormalizer.java | 2 +- .../converters/LCCallNumberNormalizer.java | 2 +- .../AnchoredSearchFilterFactory.java | 2 +- .../ISBNNormalizerFilterFactory.java | 2 +- .../KeywordAwareICUFoldingFilterFactory.java | 2 +- .../LCCNNormalizerFilterFactory.java | 2 +- .../LCCallNumberNormalizerFilterFactory.java | 2 +- .../LCCallNumberShelfKeyFilterFactory.java | 2 +- .../LeftAnchoredSearchFilter.java | 58 +++++++++++++++++++ .../LeftAnchoredSearchFilterFactory.java | 2 +- 11 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilter.java diff --git a/pom.xml b/pom.xml index 431bcd2..98f5055 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ 2.0 - 8.2.0 - 62.1 + 9.0.0 + 68.2 @@ -31,7 +31,7 @@ org.apache.lucene - lucene-analyzers-icu + lucene-analysis-icu ${solr.version} compile @@ -52,15 +52,15 @@ org.slf4j - slf4j-simple - 1.7.26 - test + slf4j-api + 1.7.28 + provided org.slf4j slf4j-api - 1.7.26 + 1.7.28 @@ -74,8 +74,8 @@ maven-compiler-plugin 3.5.1 - 1.8 - 1.8 + 11 + 11 diff --git a/src/java/edu/umich/lib/converters/ISBNNormalizer.java b/src/java/edu/umich/lib/converters/ISBNNormalizer.java index c0641aa..bc4aa59 100644 --- a/src/java/edu/umich/lib/converters/ISBNNormalizer.java +++ b/src/java/edu/umich/lib/converters/ISBNNormalizer.java @@ -86,7 +86,7 @@ public static String isbn10_to_13(String isbn10) { int[] digits = new int[12]; for (int i = 0; i < 12; i++) { - digits[i] = new Integer(longisbn.substring(i, i + 1)); + digits[i] = Integer.valueOf(longisbn.substring(i, i + 1)); } Integer sum = 0; diff --git a/src/java/edu/umich/lib/converters/LCCallNumberNormalizer.java b/src/java/edu/umich/lib/converters/LCCallNumberNormalizer.java index 852aaab..d483eec 100644 --- a/src/java/edu/umich/lib/converters/LCCallNumberNormalizer.java +++ b/src/java/edu/umich/lib/converters/LCCallNumberNormalizer.java @@ -16,7 +16,7 @@ */ public class LCCallNumberNormalizer { - public static final Long MINNUM = new Long(Long.MIN_VALUE); + public static final Long MINNUM = Long.MIN_VALUE; public static final String JOIN = ""; public static final String TOPALPHA = "@@@@"; public static final String TOPSPACES = "@@@@@@@@@@"; diff --git a/src/java/edu/umich/lib/solr_filters/AnchoredSearchFilterFactory.java b/src/java/edu/umich/lib/solr_filters/AnchoredSearchFilterFactory.java index 343ec48..b61c086 100644 --- a/src/java/edu/umich/lib/solr_filters/AnchoredSearchFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/AnchoredSearchFilterFactory.java @@ -1,6 +1,6 @@ package edu.umich.lib.solr_filters; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import org.apache.lucene.analysis.TokenStream; import edu.umich.lib.solr_filters.AnchoredSearchFilter; diff --git a/src/java/edu/umich/lib/solr_filters/ISBNNormalizerFilterFactory.java b/src/java/edu/umich/lib/solr_filters/ISBNNormalizerFilterFactory.java index c3a18c5..4fbad7e 100644 --- a/src/java/edu/umich/lib/solr_filters/ISBNNormalizerFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/ISBNNormalizerFilterFactory.java @@ -1,7 +1,7 @@ package edu.umich.lib.solr_filters; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import java.util.Map; diff --git a/src/java/edu/umich/lib/solr_filters/KeywordAwareICUFoldingFilterFactory.java b/src/java/edu/umich/lib/solr_filters/KeywordAwareICUFoldingFilterFactory.java index bee6ab2..0961670 100644 --- a/src/java/edu/umich/lib/solr_filters/KeywordAwareICUFoldingFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/KeywordAwareICUFoldingFilterFactory.java @@ -2,7 +2,7 @@ import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.icu.ICUFoldingFilterFactory; -import org.apache.lucene.analysis.util.AbstractAnalysisFactory; +import org.apache.lucene.analysis.AbstractAnalysisFactory; import java.util.Map; /** diff --git a/src/java/edu/umich/lib/solr_filters/LCCNNormalizerFilterFactory.java b/src/java/edu/umich/lib/solr_filters/LCCNNormalizerFilterFactory.java index 3f3ad3a..7d834c8 100644 --- a/src/java/edu/umich/lib/solr_filters/LCCNNormalizerFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/LCCNNormalizerFilterFactory.java @@ -1,7 +1,7 @@ package edu.umich.lib.solr_filters; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import java.util.Map; diff --git a/src/java/edu/umich/lib/solr_filters/LCCallNumberNormalizerFilterFactory.java b/src/java/edu/umich/lib/solr_filters/LCCallNumberNormalizerFilterFactory.java index 1534b32..2f5239a 100644 --- a/src/java/edu/umich/lib/solr_filters/LCCallNumberNormalizerFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/LCCallNumberNormalizerFilterFactory.java @@ -5,7 +5,7 @@ package edu.umich.lib.solr_filters; import java.util.Map; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import org.apache.lucene.analysis.TokenStream; /** diff --git a/src/java/edu/umich/lib/solr_filters/LCCallNumberShelfKeyFilterFactory.java b/src/java/edu/umich/lib/solr_filters/LCCallNumberShelfKeyFilterFactory.java index dd4f1d6..ef41036 100644 --- a/src/java/edu/umich/lib/solr_filters/LCCallNumberShelfKeyFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/LCCallNumberShelfKeyFilterFactory.java @@ -1,7 +1,7 @@ package edu.umich.lib.solr_filters; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import java.util.Map; diff --git a/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilter.java b/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilter.java new file mode 100644 index 0000000..225ca4a --- /dev/null +++ b/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilter.java @@ -0,0 +1,58 @@ +package edu.umich.lib.solr_filters; + +import org.apache.lucene.analysis.TokenFilter; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; +import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; +import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; +import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class LeftAnchoredSearchFilter extends TokenFilter { + + private Integer current_position = 0; + private final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class); + private final CharTermAttribute myTermAttribute = addAttribute(CharTermAttribute.class); + private final OffsetAttribute offsetAttr = addAttribute(OffsetAttribute.class); + private final PositionLengthAttribute posLengthAttr = addAttribute(PositionLengthAttribute.class); + + protected LeftAnchoredSearchFilter(TokenStream input) { + super(input); + } + + + + private void reset_class_variables() { + current_position = 0; + } + + /** + * Takes a set of tokens and returns them with their position appended + * to the term (so [bill, dueber] becomes [bill1, dueber2]. When used + * with a phrase query, will only allow matches that are left-anchored + *

+ * We deal with the positionIncrementAttribute so tokens that occupy + * the same position ([[Bill,bill], [Dueber,dueber]) will have the + * correct number appended. + * + * @return boolean + * @throws IOException + */ + @Override + public final boolean incrementToken() throws IOException { + if (!input.incrementToken()) { + reset_class_variables(); + return false; + } + + String t = myTermAttribute.toString(); + current_position += posIncrAtt.getPositionIncrement(); + + String newtok = t + current_position.toString(); + myTermAttribute.setEmpty().append(newtok); + return true; + } +} diff --git a/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilterFactory.java b/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilterFactory.java index ab7f018..938112f 100644 --- a/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilterFactory.java +++ b/src/java/edu/umich/lib/solr_filters/LeftAnchoredSearchFilterFactory.java @@ -1,7 +1,7 @@ package edu.umich.lib.solr_filters; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.apache.lucene.analysis.TokenFilterFactory; import java.util.Map;