diff --git a/duke-lucene/pom.xml b/duke-lucene/pom.xml index 1af4ec80..a0806c3f 100644 --- a/duke-lucene/pom.xml +++ b/duke-lucene/pom.xml @@ -1,50 +1,53 @@ - 4.0.0 - - no.priv.garshol.duke - duke - 1.3-SNAPSHOT - ../ - - duke-lucene - jar - - - - - no.priv.garshol.duke - duke-core - - - no.priv.garshol.duke - duke-core - test-jar - test - - - - org.apache.lucene - lucene-core - 4.0.0 - - - - - org.apache.lucene - lucene-analyzers-common - 4.0.0 - - - - - org.apache.lucene - lucene-spatial - 4.0.0 - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + no.priv.garshol.duke + duke + 1.3-SNAPSHOT + ../ + + duke-lucene + jar + + + 5.2.1 + + + + + + no.priv.garshol.duke + duke-core + + + no.priv.garshol.duke + duke-core + test-jar + test + + + + org.apache.lucene + lucene-core + ${lucene.version} + + + + + org.apache.lucene + lucene-analyzers-common + ${lucene.version} + + + + + org.apache.lucene + lucene-spatial + ${lucene.version} + + + diff --git a/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java b/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java index 1aafeaf3..b72b54df 100644 --- a/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java +++ b/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java @@ -1,23 +1,13 @@ package no.priv.garshol.duke.databases; -import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.nio.file.FileSystems; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import no.priv.garshol.duke.Comparator; -import no.priv.garshol.duke.Configuration; -import no.priv.garshol.duke.Database; -import no.priv.garshol.duke.DukeConfigException; -import no.priv.garshol.duke.DukeException; -import no.priv.garshol.duke.Property; -import no.priv.garshol.duke.Record; -import no.priv.garshol.duke.comparators.GeopositionComparator; -import no.priv.garshol.duke.utils.Utils; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.core.KeywordAnalyzer; @@ -45,7 +35,16 @@ import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.NIOFSDirectory; import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; + +import no.priv.garshol.duke.Comparator; +import no.priv.garshol.duke.Configuration; +import no.priv.garshol.duke.Database; +import no.priv.garshol.duke.DukeConfigException; +import no.priv.garshol.duke.DukeException; +import no.priv.garshol.duke.Property; +import no.priv.garshol.duke.Record; +import no.priv.garshol.duke.comparators.GeopositionComparator; +import no.priv.garshol.duke.utils.Utils; /** * Represents the Lucene index, and implements record linkage services @@ -74,7 +73,7 @@ public class LuceneDatabase implements Database { private GeoProperty geoprop; public LuceneDatabase() { - this.analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); + this.analyzer = new StandardAnalyzer(); this.maintracker = new EstimateResultTracker(); this.max_search_hits = 1000000; this.fuzzy_search = true; // on by default @@ -329,13 +328,13 @@ private void openIndexes(boolean overwrite) { // as per http://wiki.apache.org/lucene-java/ImproveSearchingSpeed // we use NIOFSDirectory, provided we're not on Windows if (Utils.isWindowsOS()) - directory = FSDirectory.open(new File(path)); + directory = FSDirectory.open(FileSystems.getDefault().getPath(path)); else - directory = NIOFSDirectory.open(new File(path)); + directory = NIOFSDirectory.open(FileSystems.getDefault().getPath(path)); } IndexWriterConfig cfg = - new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer); + new IndexWriterConfig(analyzer); cfg.setOpenMode(overwrite ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND); iwriter = new IndexWriter(directory, cfg); @@ -371,8 +370,9 @@ private Query parseTokens(String fieldName, String value) { if (value != null) { Analyzer analyzer = new KeywordAnalyzer(); + TokenStream tokenStream = null; try { - TokenStream tokenStream = + tokenStream = analyzer.tokenStream(fieldName, new StringReader(value)); tokenStream.reset(); CharTermAttribute attr = @@ -387,6 +387,16 @@ private Query parseTokens(String fieldName, String value) { throw new DukeException("Error parsing input string '" + value + "' " + "in field " + fieldName); } + finally { + if (null != tokenStream) { + try { + tokenStream.close(); + } + catch (IOException e) { + throw new DukeException("Error closing token stream"); + } + } + } } return searchQuery; @@ -402,8 +412,9 @@ private void parseTokens(BooleanQuery parent, String fieldName, if (value.length() == 0) return; + TokenStream tokenStream = null; try { - TokenStream tokenStream = + tokenStream = analyzer.tokenStream(fieldName, new StringReader(value)); tokenStream.reset(); CharTermAttribute attr = @@ -427,6 +438,16 @@ private void parseTokens(BooleanQuery parent, String fieldName, throw new DukeException("Error parsing input string '"+value+"' "+ "in field " + fieldName); } + finally { + if (null != tokenStream) { + try { + tokenStream.close(); + } + catch (IOException e) { + throw new DukeException("Error closing token stream"); + } + } + } } private boolean isFuzzy(String fieldName) {