Skip to content

Commit

Permalink
#65 cleanup some warnings due to api changes in Lucene 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrank committed Sep 17, 2015
1 parent 0c544aa commit be4c475
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 48 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -4,7 +4,4 @@ branches:
only:
- develop
jdk:
- oraclejdk8
before_install:
- cat ~/.m2/settings.xml
- sed -i.bak -e 's|https://nexus.codehaus.org/snapshots/|https://oss.sonatype.org/content/repositories/snapshots/|g' ~/.m2/settings.xml
- oraclejdk8
14 changes: 11 additions & 3 deletions pom.xml
Expand Up @@ -26,7 +26,7 @@
<packaging>jar</packaging>

<properties>
<surefire.version>2.17</surefire.version>
<surefire.version>2.18.1</surefire.version>
<orientdb.version>${project.version}</orientdb.version>
<lucene.version>5.3.0</lucene.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -171,7 +171,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand All @@ -181,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<version>2.5.2</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
Expand Down Expand Up @@ -229,6 +229,14 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-integration</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Expand Up @@ -45,10 +45,10 @@

public class OLuceneIndexFactory implements OIndexFactory, ODatabaseLifecycleListener {

public static final String LUCENE_ALGORITHM = "LUCENE";
private static final Set<String> TYPES;
private static final Set<String> ALGORITHMS;
public static final String LUCENE_ALGORITHM = "LUCENE";
OLuceneSpatialManager spatialManager;

static {
final Set<String> types = new HashSet<String>();
types.add(OClass.INDEX_TYPE.FULLTEXT.toString());
Expand All @@ -62,6 +62,8 @@ public class OLuceneIndexFactory implements OIndexFactory, ODatabaseLifecycleLis
ALGORITHMS = Collections.unmodifiableSet(algorithms);
}

OLuceneSpatialManager spatialManager;

public OLuceneIndexFactory() {

spatialManager = new OLuceneSpatialManager(OShapeFactory.INSTANCE);
Expand Down Expand Up @@ -91,11 +93,11 @@ public OIndexInternal<?> createIndex(String name, ODatabaseDocumentInternal data
}

@Override
public OIndexEngine createIndexEngine(String name, Boolean durableInNonTxMode, OStorage storage, int version, Map<String, String> engineProperties) {
public OIndexEngine createIndexEngine(String name, Boolean durableInNonTxMode, OStorage storage, int version,
Map<String, String> engineProperties) {
return new OLuceneIndexEngineDelegate(name, durableInNonTxMode, storage, version);
}


@Override
public PRIORITY getPriority() {
return PRIORITY.REGULAR;
Expand Down
49 changes: 22 additions & 27 deletions src/main/java/com/orientechnologies/lucene/OLuceneIndexType.java
Expand Up @@ -39,53 +39,49 @@
public class OLuceneIndexType {

public static Field createField(String fieldName, Object value, Field.Store store, Field.Index analyzed) {
Field field = null;

if (value instanceof Number) {
Number number = (Number) value;
if (value instanceof Long) {
field = new LongField(fieldName, number.longValue(), store);
} else if (value instanceof Float) {
field = new FloatField(fieldName, number.floatValue(), store);
} else if (value instanceof Double) {
field = new DoubleField(fieldName, number.doubleValue(), store);
} else {
field = new IntField(fieldName, number.intValue(), store);
}
} else if (value instanceof Date) {
field = new LongField(fieldName, ((Date) value).getTime(), store);
if (value instanceof Long)
return new LongField(fieldName, number.longValue(), store);
else if (value instanceof Float)
return new FloatField(fieldName, number.floatValue(), store);
else if (value instanceof Double)
return new DoubleField(fieldName, number.doubleValue(), store);

} else {
field = new Field(fieldName, value.toString(), store, analyzed);
return new IntField(fieldName, number.intValue(), store);

} else if (value instanceof Date) {
return new LongField(fieldName, ((Date) value).getTime(), store);
}
return field;
return new Field(fieldName, value.toString(), store, analyzed);

}

public static Query createExactQuery(OIndexDefinition index, Object key) {

Query query = null;
if (key instanceof String) {
BooleanQuery booleanQ = new BooleanQuery();
final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
if (index.getFields().size() > 0) {
for (String idx : index.getFields()) {
booleanQ.add(new TermQuery(new Term(idx, key.toString())), BooleanClause.Occur.SHOULD);
queryBuilder.add(new TermQuery(new Term(idx, key.toString())), BooleanClause.Occur.SHOULD);
}
} else {
booleanQ.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.KEY, key.toString())), BooleanClause.Occur.SHOULD);
queryBuilder.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.KEY, key.toString())), BooleanClause.Occur.SHOULD);
}
query = booleanQ;
query = queryBuilder.build();
} else if (key instanceof OCompositeKey) {
BooleanQuery booleanQ = new BooleanQuery();
final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
int i = 0;
OCompositeKey keys = (OCompositeKey) key;
for (String idx : index.getFields()) {
String val = (String) keys.getKeys().get(i);
booleanQ.add(new TermQuery(new Term(idx, val)), BooleanClause.Occur.MUST);
queryBuilder.add(new TermQuery(new Term(idx, val)), BooleanClause.Occur.MUST);
i++;

}
query = booleanQ;
query = queryBuilder.build();
}
return query;
}
Expand All @@ -96,9 +92,8 @@ public static Query createQueryId(OIdentifiable value) {

public static Query createDeleteQuery(OIdentifiable value, List<String> fields, Object key) {

BooleanQuery booleanQuery = new BooleanQuery();

booleanQuery.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.RID, value.getIdentity().toString())),
final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
queryBuilder.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.RID, value.getIdentity().toString())),
BooleanClause.Occur.MUST);

Map<String, String> values = new HashMap<String, String>();
Expand All @@ -109,9 +104,9 @@ public static Query createDeleteQuery(OIdentifiable value, List<String> fields,
values.put(fields.iterator().next(), key.toString());
}
for (String s : values.keySet()) {
booleanQuery.add(new TermQuery(new Term(s + OLuceneIndexManagerAbstract.STORED, values.get(s))), BooleanClause.Occur.MUST);
queryBuilder.add(new TermQuery(new Term(s + OLuceneIndexManagerAbstract.STORED, values.get(s))), BooleanClause.Occur.MUST);
}
return booleanQuery;
return queryBuilder.build();
}

public static Query createFullQuery(OIndexDefinition index, Object key, Analyzer analyzer) throws ParseException {
Expand Down
Expand Up @@ -58,7 +58,7 @@ public OLuceneFullTextIndexManager(String idxName, DocBuilder builder, OQueryBui
public IndexWriter createIndexWriter(Directory directory, ODocument metadata) throws IOException {

Analyzer analyzer = getAnalyzer(metadata);
IndexWriterConfig iwc = new IndexWriterConfig( analyzer);
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);

facetManager = new OLuceneFacetManager(this, metadata);
Expand Down
Expand Up @@ -71,7 +71,6 @@ public abstract class OLuceneIndexManagerAbstract<V> extends OSharedResourceAdap
public static final String OLUCENE_BASE_DIR = "luceneIndexes";

protected SearcherManager searcherManager;
private String indexType;
protected OIndexDefinition index;
protected TrackingIndexWriter mgrWriter;
protected String indexName;
Expand All @@ -80,12 +79,12 @@ public abstract class OLuceneIndexManagerAbstract<V> extends OSharedResourceAdap
protected ControlledRealTimeReopenThread nrt;
protected ODocument metadata;
protected Version version;
private boolean rebuilding;
private long reopenToken;
protected Map<String, Boolean> collectionFields = new HashMap<String, Boolean>();
protected TimerTask commitTask;

protected AtomicBoolean closed = new AtomicBoolean(true);
private String indexType;
private boolean rebuilding;
private long reopenToken;

public OLuceneIndexManagerAbstract(String indexName) {
super(OGlobalConfiguration.ENVIRONMENT_CONCURRENT.getValueAsBoolean(), OGlobalConfiguration.MVRBTREE_TIMEOUT
Expand Down Expand Up @@ -126,14 +125,13 @@ public void deleteDocument(Query query) {

public boolean remove(Object key, OIdentifiable value) {

Query query = null;
Query query;
if (isCollectionDelete()) {
query = OLuceneIndexType.createDeleteQuery(value, index.getFields(), key);
} else {
query = OLuceneIndexType.createQueryId(value);
}
if (query != null)
deleteDocument(query);
deleteDocument(query);
return true;
}

Expand Down Expand Up @@ -315,7 +313,6 @@ public Analyzer getAnalyzer(final ODocument metadata) {
return analyzer;
}


public void initIndex(String indexName, String indexType, OIndexDefinition indexDefinition, boolean isAutomatic,
ODocument metadata) {

Expand Down
Expand Up @@ -28,7 +28,7 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import junit.framework.Assert;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand Down

0 comments on commit be4c475

Please sign in to comment.