Skip to content

Commit

Permalink
started transaction refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 16, 2015
1 parent 227355e commit 674a082
Show file tree
Hide file tree
Showing 21 changed files with 637 additions and 459 deletions.
Expand Up @@ -18,6 +18,7 @@

package com.orientechnologies.lucene.builder;

import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.apache.lucene.document.Document;
Expand All @@ -27,5 +28,5 @@
*/
public interface DocBuilder {

public Document build(OIndexDefinition definition,Object key,ODocument metadata);
public Document build(OIndexDefinition definition,Object key,OIdentifiable value,ODocument metadata);
}
57 changes: 32 additions & 25 deletions src/main/java/com/orientechnologies/lucene/builder/ODocBuilder.java
Expand Up @@ -19,6 +19,8 @@
package com.orientechnologies.lucene.builder;

import com.orientechnologies.lucene.OLuceneIndexType;
import com.orientechnologies.lucene.manager.OLuceneIndexManagerAbstract;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.index.OCompositeKey;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -32,35 +34,40 @@
* Created by Enrico Risa on 02/09/15.
*/
public class ODocBuilder implements DocBuilder {
@Override
public Document build(OIndexDefinition definition, Object key, ODocument metadata) {
Document doc = new Document();
int i = 0;
List<Object> formattedKey = formatKeys(definition, key);
for (String f : definition.getFields()) {
Object val = formattedKey.get(i);
i++;
doc.add(OLuceneIndexType.createField(f, val, Field.Store.NO, Field.Index.ANALYZED));
}
return doc;
@Override
public Document build(OIndexDefinition definition, Object key, OIdentifiable value, ODocument metadata) {
Document doc = new Document();
int i = 0;

if (value != null) {
doc.add(OLuceneIndexType.createField(OLuceneIndexManagerAbstract.RID, value.getIdentity().toString(), Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
}
List<Object> formattedKey = formatKeys(definition, key);
for (String f : definition.getFields()) {
Object val = formattedKey.get(i);
i++;
doc.add(OLuceneIndexType.createField(f, val, Field.Store.NO, Field.Index.ANALYZED));
}
return doc;
}

private List<Object> formatKeys(OIndexDefinition definition, Object key) {
List<Object> keys;
private List<Object> formatKeys(OIndexDefinition definition, Object key) {
List<Object> keys;

if (key instanceof OCompositeKey) {
keys = ((OCompositeKey) key).getKeys();
if (key instanceof OCompositeKey) {
keys = ((OCompositeKey) key).getKeys();

} else if (key instanceof List) {
keys = ((List) key);
} else {
keys = new ArrayList<Object>();
keys.add(key);
}
} else if (key instanceof List) {
keys = ((List) key);
} else {
keys = new ArrayList<Object>();
keys.add(key);
}

for (int i = keys.size(); i < definition.getFields().size(); i++) {
keys.add("");
}
return keys;
for (int i = keys.size(); i < definition.getFields().size(); i++) {
keys.add("");
}
return keys;
}
}
Expand Up @@ -65,9 +65,9 @@ private void fetchFacet() {
String[] path = queryContext.getDrillDownQuery().split(":");
pathFacet = path[1].split("/");
drillDownQuery.add(path[0], pathFacet);
FacetsCollector.search(queryContext.searcher, drillDownQuery, PAGE_SIZE, facetsCollector);
FacetsCollector.search(queryContext.getSearcher(), drillDownQuery, PAGE_SIZE, facetsCollector);
} else {
FacetsCollector.search(queryContext.searcher, query, PAGE_SIZE, facetsCollector);
FacetsCollector.search(queryContext.getSearcher(), query, PAGE_SIZE, facetsCollector);
}

Facets facets = new FastTaxonomyFacetCounts(queryContext.reader, queryContext.getFacetConfig(), facetsCollector);
Expand Down Expand Up @@ -119,16 +119,16 @@ private void fetchFirstBatch() {
switch (queryContext.cfg) {

case NO_FILTER_NO_SORT:
topDocs = queryContext.searcher.search(query, PAGE_SIZE);
topDocs = queryContext.getSearcher().search(query, PAGE_SIZE);
break;
case FILTER_SORT:
topDocs = queryContext.searcher.search(query, queryContext.filter, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().search(query, queryContext.filter, PAGE_SIZE, queryContext.sort);
break;
case FILTER:
topDocs = queryContext.searcher.search(query, queryContext.filter, PAGE_SIZE);
topDocs = queryContext.getSearcher().search(query, queryContext.filter, PAGE_SIZE);
break;
case SORT:
topDocs = queryContext.searcher.search(query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().search(query, PAGE_SIZE, queryContext.sort);
break;
}
} catch (IOException e) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public OIdentifiable next() {
Document ret = null;
OContextualRecordId res = null;
try {
ret = queryContext.searcher.doc(score.doc);
ret = queryContext.getSearcher().doc(score.doc);
String rId = ret.get(OLuceneIndexManagerAbstract.RID);
res = new OContextualRecordId(rId);
manager.onRecordAddedToResultSet(queryContext, res, ret, score);
Expand All @@ -245,17 +245,17 @@ private void fetchMoreResult() {
switch (queryContext.cfg) {

case NO_FILTER_NO_SORT:
topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE);
break;
case FILTER_SORT:
topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE,
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE,
queryContext.sort);
break;
case FILTER:
topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE);
break;
case SORT:
topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
break;
}
array = topDocs.scoreDocs;
Expand Down
Expand Up @@ -18,6 +18,7 @@

package com.orientechnologies.lucene.engine;

import com.orientechnologies.lucene.tx.OLuceneTxChanges;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
Expand All @@ -38,7 +39,7 @@ public interface OLuceneIndexEngine extends OIndexEngine {
public void initIndex(String indexName, String indexType, OIndexDefinition indexDefinition, boolean isAutomatic,
ODocument metadata);

public Document buildDocument(Object key);
public Document buildDocument(Object key, OIdentifiable value);

public Query buildQuery(Object query);

Expand All @@ -48,4 +49,11 @@ public void initIndex(String indexName, String indexType, OIndexDefinition index

public IndexSearcher searcher() throws IOException;

public Object getInTx(Object key, OLuceneTxChanges changes);

public long sizeInTx(OLuceneTxChanges changes);

public OLuceneTxChanges buildTxChanges() throws IOException;

public Query deleteQuery(Object key, OIdentifiable value);
}
Expand Up @@ -23,6 +23,7 @@
import com.orientechnologies.lucene.builder.OQueryBuilderImpl;
import com.orientechnologies.lucene.manager.OLuceneFullTextIndexManager;
import com.orientechnologies.lucene.manager.OLuceneGeoSpatialIndexManager;
import com.orientechnologies.lucene.tx.OLuceneTxChanges;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.index.OIndexCursor;
import com.orientechnologies.orient.core.index.OIndexDefinition;
Expand Down Expand Up @@ -199,8 +200,8 @@ public void initIndex(String indexName, String indexType, OIndexDefinition index
}

@Override
public Document buildDocument(Object key) {
return delegate.buildDocument(key);
public Document buildDocument(Object key, OIdentifiable value) {
return delegate.buildDocument(key, value);
}

@Override
Expand All @@ -222,4 +223,24 @@ public boolean remove(Object key, OIdentifiable value) {
public IndexSearcher searcher() throws IOException {
return delegate.searcher();
}

@Override
public Object getInTx(Object key, OLuceneTxChanges changes) {
return delegate.getInTx(key, changes);
}

@Override
public long sizeInTx(OLuceneTxChanges changes) {
return delegate.sizeInTx(changes);
}

@Override
public OLuceneTxChanges buildTxChanges() throws IOException {
return delegate.buildTxChanges();
}

@Override
public Query deleteQuery(Object key, OIdentifiable value) {
return delegate.deleteQuery(key, value);
}
}
Expand Up @@ -40,7 +40,7 @@ public Document buildDocument(final Object key) {
@Override
public Document callEngine(OIndexEngine engine) {
OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
return indexEngine.buildDocument(key);
return indexEngine.buildDocument(key, null);
}
});
}
Expand Down

0 comments on commit 674a082

Please sign in to comment.