use of edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatchingType in project textdb by TextDB.
the class DictionaryMatcherSourceOperator method getNextTuple.
/**
* @about Gets the next matched tuple. <br>
* Returns the tuple with results in spanList. <br>
*
* Performs SCAN, KEYWORD_BASIC, or KEYWORD_PHRASE depends on the
* dictionary predicate. <br>
*
* DictionaryOperatorType.SCAN: <br>
* Scan the tuples using ScanSourceOperator. <br>
* For each tuple, loop through the dictionary and find results. <br>
* We assume the dictionary is smaller than the data at the source
* operator, we treat the data source as the outer relation to reduce
* the number of disk IOs. <br>
*
* DictionaryOperatorType.KEYWORD_BASIC, KEYWORD_PHRASE: <br>
* Use KeywordMatcher to find results. <br>
*
* KEYWORD_BASIC corresponds to KeywordOperatorType.BASIC, which
* performs keyword search on the document. The input query is
* tokenized. The order of the tokens doesn't matter. <br>
*
* KEYWORD_PHRASE corresponds to KeywordOperatorType.PHRASE, which
* performs phrase search on the document. The input query is
* tokenized. The order of the tokens does matter. Stopwords are
* treated as placeholders to indicate an arbitary token. <br>
*
*/
@Override
public Tuple getNextTuple() throws TextDBException {
if (resultCursor >= limit + offset - 1) {
return null;
}
if (predicate.getKeywordMatchingType() == KeywordMatchingType.PHRASE_INDEXBASED || predicate.getKeywordMatchingType() == KeywordMatchingType.CONJUNCTION_INDEXBASED) {
while (true) {
// If there's result from current keywordMatcher, return it.
if ((sourceTuple = keywordSource.getNextTuple()) != null) {
resultCursor++;
if (resultCursor >= offset) {
return sourceTuple;
}
continue;
}
// return null if reach the end of dictionary.
if ((currentDictionaryEntry = predicate.getDictionary().getNextEntry()) == null) {
return null;
}
// Construct a new KeywordMatcher with the new dictionary entry.
KeywordMatchingType keywordMatchingType;
if (predicate.getKeywordMatchingType() == KeywordMatchingType.PHRASE_INDEXBASED) {
keywordMatchingType = KeywordMatchingType.PHRASE_INDEXBASED;
} else {
keywordMatchingType = KeywordMatchingType.CONJUNCTION_INDEXBASED;
}
keywordSource.close();
KeywordSourcePredicate keywordSourcePredicate = new KeywordSourcePredicate(currentDictionaryEntry, predicate.getAttributeNames(), predicate.getAnalyzerString(), keywordMatchingType, predicate.getTableName(), predicate.getSpanListName());
keywordSource = new KeywordMatcherSourceOperator(keywordSourcePredicate);
keywordSource.open();
}
} else // Substring matching (based on scan)
{
Tuple sourceTuple;
Tuple resultTuple = null;
while ((sourceTuple = indexSource.getNextTuple()) != null) {
sourceTuple = DataflowUtils.getSpanTuple(sourceTuple.getFields(), new ArrayList<Span>(), outputSchema);
resultTuple = computeMatchingResult(currentDictionaryEntry, sourceTuple);
if (resultTuple != null) {
resultCursor++;
}
if (resultTuple != null && resultCursor >= offset) {
break;
}
}
return resultTuple;
}
}
Aggregations