Search in sources :

Example 1 with IPartitionedInvertedIndex

use of org.apache.hyracks.storage.am.lsm.invertedindex.api.IPartitionedInvertedIndex in project asterixdb by apache.

the class PartitionedTOccurrenceSearcher method search.

@Override
public void search(OnDiskInvertedIndexSearchCursor resultCursor, InvertedIndexSearchPredicate searchPred, IIndexOperationContext ictx) throws HyracksDataException {
    IPartitionedInvertedIndex partInvIndex = (IPartitionedInvertedIndex) invIndex;
    searchResult.reset();
    if (partInvIndex.isEmpty()) {
        return;
    }
    tokenizeQuery(searchPred);
    short numQueryTokens = (short) queryTokenAppender.getTupleCount();
    IInvertedIndexSearchModifier searchModifier = searchPred.getSearchModifier();
    short numTokensLowerBound = searchModifier.getNumTokensLowerBound(numQueryTokens);
    short numTokensUpperBound = searchModifier.getNumTokensUpperBound(numQueryTokens);
    occurrenceThreshold = searchModifier.getOccurrenceThreshold(numQueryTokens);
    if (occurrenceThreshold <= 0) {
        throw HyracksDataException.create(ErrorCode.OCCURRENCE_THRESHOLD_PANIC_EXCEPTION);
    }
    short maxCountPossible = numQueryTokens;
    invListCursorCache.reset();
    partitions.reset(numTokensLowerBound, numTokensUpperBound);
    cursorsOrderedByTokens.clear();
    for (int i = 0; i < numQueryTokens; i++) {
        searchKey.reset(queryTokenAppender, i);
        if (!partInvIndex.openInvertedListPartitionCursors(this, ictx, numTokensLowerBound, numTokensUpperBound, partitions, cursorsOrderedByTokens)) {
            maxCountPossible--;
            // No results possible.
            if (maxCountPossible < occurrenceThreshold) {
                return;
            }
        }
    }
    ArrayList<IInvertedListCursor>[] partitionCursors = partitions.getPartitions();
    short start = partitions.getMinValidPartitionIndex();
    short end = partitions.getMaxValidPartitionIndex();
    // if we'd have to wait for a page to get evicted.
    if (!cursorsOrderedByTokens.isEmpty()) {
        for (int i = start; i <= end; i++) {
            if (partitionCursors[i] == null) {
                continue;
            }
            // Prune partition because no element in it can satisfy the occurrence threshold.
            if (partitionCursors[i].size() < occurrenceThreshold) {
                cursorsOrderedByTokens.removeAll(partitionCursors[i]);
            }
        }
        // Pin all the cursors in the order of tokens.
        int numCursors = cursorsOrderedByTokens.size();
        for (int i = 0; i < numCursors; i++) {
            cursorsOrderedByTokens.get(i).pinPages();
        }
    }
    // Process the partitions one-by-one.
    for (int i = start; i <= end; i++) {
        if (partitionCursors[i] == null) {
            continue;
        }
        // Prune partition because no element in it can satisfy the occurrence threshold.
        if (partitionCursors[i].size() < occurrenceThreshold) {
            continue;
        }
        // Merge inverted lists of current partition.
        int numPrefixLists = searchModifier.getNumPrefixLists(occurrenceThreshold, partitionCursors[i].size());
        invListMerger.reset();
        invListMerger.merge(partitionCursors[i], occurrenceThreshold, numPrefixLists, searchResult);
    }
    resultCursor.open(null, searchPred);
}
Also used : IInvertedIndexSearchModifier(org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndexSearchModifier) ArrayList(java.util.ArrayList) IPartitionedInvertedIndex(org.apache.hyracks.storage.am.lsm.invertedindex.api.IPartitionedInvertedIndex)

Aggregations

ArrayList (java.util.ArrayList)1 IInvertedIndexSearchModifier (org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndexSearchModifier)1 IPartitionedInvertedIndex (org.apache.hyracks.storage.am.lsm.invertedindex.api.IPartitionedInvertedIndex)1