use of com.apple.foundationdb.record.IndexScanType in project fdb-record-layer by FoundationDB.
the class LuceneIndexQueryPlan method executePlan.
/**
* Override here to have specific logic to build the {@link QueryResult} for lucene auto complete suggestion result.
*/
@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
final RecordMetaData metaData = store.getRecordMetaData();
final Index index = metaData.getIndex(indexName);
final Collection<RecordType> recordTypes = metaData.recordTypesForIndex(index);
if (recordTypes.size() != 1) {
throw new RecordCoreException("No lucene index should span multiple record types");
}
final IndexScanType scanType = getScanType();
if (scanType == IndexScanType.BY_LUCENE_AUTO_COMPLETE || scanType == IndexScanType.BY_LUCENE_SPELLCHECK) {
final RecordType recordType = recordTypes.iterator().next();
final RecordCursor<IndexEntry> entryRecordCursor = executeEntries(store, context, continuation, executeProperties);
return entryRecordCursor.map(QueryPlanUtils.getCoveringIndexEntryToPartialRecordFunction(store, recordType.getName(), indexName, getToPartialRecord(index, recordType, scanType), scanType)).map(QueryResult::of);
}
return super.executePlan(store, context, continuation, executeProperties);
}
use of com.apple.foundationdb.record.IndexScanType in project fdb-record-layer by FoundationDB.
the class LuceneIndexQueryPlan method merge.
public static LuceneIndexQueryPlan merge(LuceneIndexQueryPlan plan1, LuceneIndexQueryPlan plan2, String type) {
verify(plan1.indexName.equals(plan2.indexName));
verify(plan1.sort == null || plan2.sort == null || plan1.sort.equals(plan2.sort));
KeyExpression newSort = plan1.sort != null ? plan1.sort : plan2.sort;
String newQuery = String.format("(%s) %s (%s)", plan1.getLuceneQueryString(), type, plan2.getLuceneQueryString());
Comparisons.LuceneComparison comparison = new Comparisons.LuceneComparison(newQuery);
boolean newReverse = plan1.isReverse() ? plan1.isReverse() : plan2.isReverse();
IndexScanType scanType = IndexScanType.BY_LUCENE;
if (plan1.getScanType() == IndexScanType.BY_LUCENE_FULL_TEXT || plan2.getScanType() == IndexScanType.BY_LUCENE_FULL_TEXT) {
scanType = IndexScanType.BY_LUCENE_FULL_TEXT;
}
ScanComparisons newGrouping = plan1.groupingComparisons == null ? ScanComparisons.EMPTY : plan1.groupingComparisons;
if (newGrouping.isEmpty()) {
newGrouping = plan2.groupingComparisons;
} else if (plan2.groupingComparisons != null) {
newGrouping = newGrouping.merge(plan2.groupingComparisons);
}
LuceneIndexQueryPlan plan = new LuceneIndexQueryPlan(plan1.indexName, scanType, comparison, newReverse, newSort, newGrouping);
if (plan1.createsDuplicates() || plan2.createsDuplicates()) {
plan.setCreatesDuplicates();
}
return plan;
}
use of com.apple.foundationdb.record.IndexScanType in project fdb-record-layer by FoundationDB.
the class QueryPlanUtils method getCoveringIndexEntryToPartialRecordFunction.
/**
* The method to get a function from an {@link IndexEntry} to a {@link FDBQueriedRecord} representing a partial record.
*/
@SuppressWarnings("unchecked")
public static <M extends Message> Function<IndexEntry, FDBQueriedRecord<M>> getCoveringIndexEntryToPartialRecordFunction(@Nonnull final FDBRecordStoreBase<M> store, @Nonnull final String recordTypeName, @Nonnull final String indexName, @Nonnull final IndexKeyValueToPartialRecord toRecord, @Nonnull final IndexScanType scanType) {
final RecordMetaData metaData = store.getRecordMetaData();
final RecordType recordType = metaData.getRecordType(recordTypeName);
final Index index = metaData.getIndex(indexName);
final Descriptors.Descriptor recordDescriptor = recordType.getDescriptor();
boolean hasPrimaryKey = scanType != IndexScanType.BY_GROUP && scanType != IndexScanType.BY_LUCENE_AUTO_COMPLETE && scanType != IndexScanType.BY_LUCENE_SPELLCHECK;
return indexEntry -> store.coveredIndexQueriedRecord(index, indexEntry, recordType, (M) toRecord.toRecord(recordDescriptor, indexEntry), hasPrimaryKey);
}
Aggregations