Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimum code revision to use Lucene 5. #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 50 additions & 47 deletions duke-lucene/pom.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke</artifactId>
<version>1.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>duke-lucene</artifactId>
<packaging>jar</packaging>

<dependencies>

<dependency>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke-core</artifactId>
</dependency>
<dependency>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>4.0.0</version>
</dependency>

<!-- necessary to get KeywordAnalyzer and StandardAnalyzer -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>4.0.0</version>
</dependency>

<!-- necessary for spatial searches
NOTE: the code is written so that Duke will work without it,
as long as you don't use spatial searches -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-spatial</artifactId>
<version>4.0.0</version>
</dependency>

</dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke</artifactId>
<version>1.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>duke-lucene</artifactId>
<packaging>jar</packaging>

<properties>
<lucene.version>5.2.1</lucene.version>
</properties>

<dependencies>

<dependency>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke-core</artifactId>
</dependency>
<dependency>
<groupId>no.priv.garshol.duke</groupId>
<artifactId>duke-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>

<!-- necessary to get KeywordAnalyzer and StandardAnalyzer -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>

<!-- necessary for spatial searches NOTE: the code is written so that Duke
will work without it, as long as you don't use spatial searches -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-spatial</artifactId>
<version>${lucene.version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
Expand All @@ -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 =
Expand All @@ -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) {
Expand Down