Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
maggiolo00 authored and maggiolo00 committed May 27, 2014
1 parent 4a1c236 commit f1f3fb5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-tests</artifactId>
<artifactId>orientdb-graphdb</artifactId>
<version>${orientdb.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.orientechnologies.lucene.index;

import java.util.HashSet;
import java.util.Set;

import com.orientechnologies.common.listener.OProgressListener;
Expand All @@ -31,7 +32,6 @@
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.type.tree.OMVRBTreeRIDSet;


public class OLuceneIndexNotUnique extends OIndexNotUnique implements OLuceneIndex {

public OLuceneIndexNotUnique(String typeId, String algorithm, OLuceneIndexEngine engine, String valueContainerAlgorithm) {
Expand All @@ -57,18 +57,8 @@ public OIndexMultiValues put(Object key, OIdentifiable iSingleValue) {
acquireExclusiveLock();
try {
checkForKeyType(key);
Set<OIdentifiable> values = null;
if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
values = new OIndexRIDContainer(getName());
} else {
values = new OMVRBTreeRIDSet(OGlobalConfiguration.MVRBTREE_RID_BINARY_THRESHOLD.getValueAsInteger());
((OMVRBTreeRIDSet) values).setAutoConvertToRecord(false);
}
if (!iSingleValue.getIdentity().isValid())
((ORecord<?>) iSingleValue).save();

values.add(iSingleValue.getIdentity());

Set<OIdentifiable> values = new HashSet<OIdentifiable>();
values.add(iSingleValue);
indexEngine.put(key, values);
return this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ORID getIdentity() {
public Object get(Object key) {
Query q = null;
try {
q = OLuceneIndexType.createFullQuery(index, key, indexWriter.getAnalyzer(), getVersion(metadata));
q = OLuceneIndexType.createFullQuery(index, key, mgrWriter.getIndexWriter().getAnalyzer(), getVersion(metadata));
return getResults(q);
} catch (ParseException e) {
throw new OIndexException("Error parsing lucene query ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
import java.util.Iterator;
import java.util.Map;

import com.orientechnologies.lucene.exception.OLuceneIndexException;
import com.orientechnologies.lucene.utils.OLuceneIndexUtils;
import com.orientechnologies.orient.core.index.OIndexException;
import com.sun.jna.platform.FileUtils;
import org.apache.lucene.LucenePackage;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
Expand All @@ -41,7 +37,6 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.util.Version;

Expand All @@ -67,8 +62,7 @@ public abstract class OLuceneIndexManagerAbstract<V> extends OSharedResourceAdap
public static final Version LUCENE_VERSION = Version.LUCENE_47;

public static final String OLUCENE_BASE_DIR = "luceneIndexes";
protected IndexWriter indexWriter = null;
protected SearcherManager manager;
protected SearcherManager searcherManager;
protected OIndexDefinition index;
protected TrackingIndexWriter mgrWriter;
protected String indexName;
Expand Down Expand Up @@ -123,13 +117,14 @@ private void reOpen(ODocument metadata) throws IOException {
final OStorageLocalAbstract storageLocalAbstract = (OStorageLocalAbstract) database.getStorage().getUnderlying();
String pathname = getIndexPath(storageLocalAbstract);
Directory dir = NIOFSDirectory.open(new File(pathname));
indexWriter = createIndexWriter(dir, metadata);
IndexWriter indexWriter = createIndexWriter(dir, metadata);
mgrWriter = new TrackingIndexWriter(indexWriter);
manager = new SearcherManager(indexWriter, true, null);
searcherManager = new SearcherManager(indexWriter, true, null);
if (nrt != null) {
nrt.close();
}
nrt = new ControlledRealTimeReopenThread(mgrWriter, manager, 60.00, 0.1);
nrt = new ControlledRealTimeReopenThread(mgrWriter, searcherManager, 60.00, 0.1);
nrt.setDaemon(true);
nrt.start();
}

Expand All @@ -143,7 +138,7 @@ protected IndexSearcher getSearcher() throws IOException {
} catch (InterruptedException e) {
e.printStackTrace();
}
return manager.acquire();
return searcherManager.acquire();
}

private ODatabaseRecord getDatabase() {
Expand Down Expand Up @@ -171,28 +166,22 @@ public void deleteDocument(Query query) {
}

public boolean remove(Object key, OIdentifiable value) {

deleteDocument(OLuceneIndexType.createQueryId(value));
return true;
}

public void commit() {
try {
indexWriter.commit();
mgrWriter.getIndexWriter().commit();
} catch (IOException e) {
e.printStackTrace();
}
}

public void delete() {
try {
if (indexWriter != null) {
indexWriter.deleteAll();

nrt.interrupt();
nrt.close();

indexWriter.close();
if (mgrWriter.getIndexWriter() != null) {
closeIndex();
}
ODatabaseRecord database = getDatabase();
final OStorageLocalAbstract storageLocalAbstract = (OStorageLocalAbstract) database.getStorage().getUnderlying();
Expand All @@ -218,7 +207,7 @@ public Iterator<Map.Entry<Object, V>> iterator() {

public void clear() {
try {
indexWriter.deleteAll();
mgrWriter.getIndexWriter().deleteAll();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -257,7 +246,7 @@ public void beforeTxBegin() {
@Override
public void flush() {
try {
indexWriter.commit();
mgrWriter.getIndexWriter().commit();
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -266,27 +255,32 @@ public void flush() {
@Override
public void close() {
try {
nrt.interrupt();
nrt.close();
indexWriter.commit();
indexWriter.close();
closeIndex();
} catch (IOException e) {
e.printStackTrace();
}
}

protected void closeIndex() throws IOException {
nrt.interrupt();
nrt.close();
searcherManager.close();
mgrWriter.getIndexWriter().commit();
mgrWriter.getIndexWriter().close();
}

@Override
public void unload() {
try {
indexWriter.commit();
mgrWriter.getIndexWriter().commit();
} catch (IOException e) {
e.printStackTrace();
}
}

public void rollback() {
try {
indexWriter.rollback();
mgrWriter.getIndexWriter().rollback();
reOpen(metadata);
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -331,6 +325,7 @@ public Analyzer getAnalyzer(ODocument metadata) {
String analyzerString = metadata.field("analyzer");
if (analyzerString != null) {
try {

Class classAnalyzer = Class.forName(analyzerString);
Constructor constructor = classAnalyzer.getConstructor(Version.class);

Expand Down Expand Up @@ -367,4 +362,5 @@ public Version getVersion(ODocument metadata) {
}
return version;
}

}

0 comments on commit f1f3fb5

Please sign in to comment.