Skip to content

Commit

Permalink
Fixed Bug in OLuceneResultSet#fetchMore.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jun 15, 2017
1 parent c7dee40 commit 36332e5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ public void change(final Object iCurrentValue, final Object iNewValue) {

QUERY_LIVE_SUPPORT("query.live.support", "Enable/Disable the support of live query. (Use false to disable)", Boolean.class, true),

LUCENE_QUERY_PAGE_SIZE("lucene.query.pageSize",
"Size of the page when fetching data from a lucene index", Long.class, 10000,true),

STATEMENT_CACHE_SIZE("statement.cacheSize", "Number of parsed SQL statements kept in cache", Integer.class, 100),

// GRAPH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.orientechnologies.lucene.engine.OLuceneIndexEngineAbstract;
import com.orientechnologies.lucene.query.OLuceneQueryContext;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopDocs;
Expand All @@ -36,7 +37,7 @@
*/
public abstract class OLuceneAbstractResultSet implements Set<OIdentifiable> {

protected static Integer PAGE_SIZE = 10000;
protected Integer pageSize = 10000;
protected final String indexName;
protected final Query query;
protected final OLuceneIndexEngine engine;
Expand All @@ -47,7 +48,7 @@ public OLuceneAbstractResultSet(OLuceneIndexEngine engine, OLuceneQueryContext q
this.engine = engine;
this.queryContext = queryContext;
this.query = enhanceQuery(queryContext.query);

pageSize= OGlobalConfiguration.LUCENE_QUERY_PAGE_SIZE.getValue();
indexName = engine.indexName();
fetchFirstBatch();
}
Expand All @@ -62,23 +63,25 @@ protected void fetchFirstBatch() {
switch (queryContext.cfg) {

case NO_FILTER_NO_SORT:
topDocs = queryContext.getSearcher().search(query, PAGE_SIZE);
topDocs = queryContext.getSearcher().search(query, pageSize);
break;
case FILTER_SORT:
topDocs = queryContext.getSearcher().search(query, queryContext.filter, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().search(query, queryContext.filter, pageSize, queryContext.sort);
break;
case FILTER:
topDocs = queryContext.getSearcher().search(query, queryContext.filter, PAGE_SIZE);
topDocs = queryContext.getSearcher().search(query, queryContext.filter, pageSize);
break;
case SORT:
topDocs = queryContext.getSearcher().search(query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().search(query, pageSize, queryContext.sort);
break;
}
} catch (IOException e) {
OLogManager.instance().error(this, "Error on fetching document by query '%s' to Lucene index", e, query);
}
}



@Override
public boolean isEmpty() {
return size() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ private void fetchMoreResult() {
switch (queryContext.cfg) {

case NO_FILTER_NO_SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, pageSize);
break;
case FILTER_SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query,queryContext.filter, pageSize, queryContext.sort);
break;
case FILTER:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query,queryContext.filter, pageSize);
break;
case SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, pageSize, queryContext.sort);
break;
}
array = topDocs.scoreDocs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,17 @@ private void fetchMoreResult() {
switch (queryContext.cfg) {

case NO_FILTER_NO_SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, pageSize);
break;
case FILTER_SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher()
.searchAfter(array[array.length - 1], query, queryContext.filter, pageSize, queryContext.sort);
break;
case FILTER:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, queryContext.filter, pageSize);
break;
case SORT:
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
topDocs = queryContext.getSearcher().searchAfter(array[array.length - 1], query, pageSize, queryContext.sort);
break;
}
array = topDocs.scoreDocs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ public void setUp() throws Exception {

List<String> names = Arrays.asList("John", "Robert", "Jane", "andrew", "Scott", "luke", "Enriquez", "Luis", "Gabriel", "Sara");
for (int i = 0; i < 10; i++) {
db.save(new ODocument("Person")
.field("name", names.get(i))
.field("surname", "Reese")
db.save(new ODocument("Person").field("name", names.get(i)).field("surname", "Reese")
//from today back one day a time
.field("date", System.currentTimeMillis() - (i * 3600 * 24 * 1000))
.field("age", i));
.field("date", System.currentTimeMillis() - (i * 3600 * 24 * 1000)).field("age", i));
}

}
Expand All @@ -50,16 +47,12 @@ public void shouldUseRangeQueryOnSingleIntegerField() throws Exception {
assertThat(db.getMetadata().getIndexManager().getIndex("Person.age").getSize()).isEqualTo(10);

//range
Collection<ODocument> results = db.command(
new OCommandSQL("SELECT FROM Person WHERE age LUCENE 'age:[5 TO 6]'"))
.execute();
Collection<ODocument> results = db.command(new OCommandSQL("SELECT FROM Person WHERE age LUCENE 'age:[5 TO 6]'")).execute();

assertThat(results).hasSize(2);

//single value
results = db.command(
new OCommandSQL("SELECT FROM Person WHERE age LUCENE 'age:5'"))
.execute();
results = db.command(new OCommandSQL("SELECT FROM Person WHERE age LUCENE 'age:5'")).execute();

assertThat(results).hasSize(1);
}
Expand All @@ -77,9 +70,8 @@ public void shouldUseRangeQueryOnSingleDateField() throws Exception {
String fiveDaysAgo = DateTools.timeToString(System.currentTimeMillis() - (5 * 3600 * 24 * 1000), DateTools.Resolution.MINUTE);

//range
Collection<ODocument> results = db.command(
new OCommandSQL("SELECT FROM Person WHERE date LUCENE 'date:[" + fiveDaysAgo + " TO " + today + "]'"))
.execute();
Collection<ODocument> results = db
.command(new OCommandSQL("SELECT FROM Person WHERE date LUCENE 'date:[" + fiveDaysAgo + " TO " + today + "]'")).execute();

assertThat(results).hasSize(5);

Expand Down Expand Up @@ -112,10 +104,8 @@ public void shouldUseRangeQueryMultipleField() throws Exception {
assertThat(results).hasSize(5);

//age and date range with MUST
results = db.command(
new OCommandSQL(
"SELECT FROM Person WHERE [name,surname,date,age] LUCENE '+age:[4 TO 7] +date:[" + fiveDaysAgo + " TO " + today
+ "]'"))
results = db.command(new OCommandSQL(
"SELECT FROM Person WHERE [name,surname,date,age] LUCENE '+age:[4 TO 7] +date:[" + fiveDaysAgo + " TO " + today + "]'"))
.execute();

assertThat(results).hasSize(2);
Expand All @@ -134,25 +124,21 @@ public void shouldUseRangeQueryMultipleFieldWithDirectIndexAccess() throws Excep
String fiveDaysAgo = DateTools.timeToString(System.currentTimeMillis() - (5 * 3600 * 24 * 1000), DateTools.Resolution.MINUTE);

//anme and age range
Collection<ODocument> results = db.command(
new OCommandSQL("SELECT * FROM index:Person.composite WHERE key ='name:luke age:[5 TO 6]'"))
.execute();
Collection<ODocument> results = db
.command(new OCommandSQL("SELECT * FROM index:Person.composite WHERE key ='name:luke age:[5 TO 6]'")).execute();

assertThat(results).hasSize(2);

//date range
results = db.command(
new OCommandSQL("SELECT FROM index:Person.composite WHERE key = 'date:[" + fiveDaysAgo + " TO " + today + "]'"))
results = db
.command(new OCommandSQL("SELECT FROM index:Person.composite WHERE key = 'date:[" + fiveDaysAgo + " TO " + today + "]'"))
.execute();

assertThat(results).hasSize(5);

//age and date range with MUST
results = db.command(
new OCommandSQL(
"SELECT FROM index:Person.composite WHERE key = '+age:[4 TO 7] +date:[" + fiveDaysAgo + " TO " + today
+ "]'"))
.execute();
results = db.command(new OCommandSQL(
"SELECT FROM index:Person.composite WHERE key = '+age:[4 TO 7] +date:[" + fiveDaysAgo + " TO " + today + "]'")).execute();

assertThat(results).hasSize(2);

Expand All @@ -165,15 +151,18 @@ public void shouldFetchOnlyFromACluster() throws Exception {

assertThat(db.getMetadata().getIndexManager().getIndex("Person.name").getSize()).isEqualTo(10);

int cluster = db.getMetadata().getSchema().getClass("Person").getClusterIds()[1];
OClass person = db.getMetadata().getSchema().getClass("Person");


int cluster = person.getClusterIds()[1];

Long count = db.countClusterElements(cluster);

db.commit();

Collection<ODocument> results = db.command(
new OCommandSQL(
"SELECT FROM Person WHERE name LUCENE '+_CLUSTER:" + cluster + "'"))
.execute();
Collection<ODocument> results = db.command(new OCommandSQL("SELECT FROM Person WHERE name LUCENE '+_CLUSTER:" + cluster + "'")).execute();

assertThat(results).hasSize(2);
assertThat(results).hasSize(count.intValue());

}
}

0 comments on commit 36332e5

Please sign in to comment.