From 641c3041282746aff280b685424d55926bab93b2 Mon Sep 17 00:00:00 2001 From: Sunguck Lee Date: Tue, 30 May 2017 12:02:52 +0900 Subject: [PATCH] Support prefix match for full-text search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add range search feature on full text search (original version has only exact match) >> Match range of original fulltext search * '한글' <= match_range < '한글' * '테스트' <= match_range < '테스트' * '이성' <= match_range < '이성' * '한' <= match_range < '한' >> Match range of patched fulltext search * '한글' <= match_range < '한긁' * '테스트' <= match_range < '테스특' * '이성' <= match_range < '이섲' * '한' <= match_range < '핝' --- src/mongo/db/exec/text.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mongo/db/exec/text.cpp b/src/mongo/db/exec/text.cpp index f698dbd0dc82e..297fc5b8a2846 100644 --- a/src/mongo/db/exec/text.cpp +++ b/src/mongo/db/exec/text.cpp @@ -103,12 +103,16 @@ unique_ptr TextStage::buildTextTree(OperationContext* opCtx, ixparams.bounds.startKey = FTSIndexFormat::getIndexKey( MAX_WEIGHT, term, _params.indexPrefix, _params.spec.getTextIndexVersion()); + + string term_end = term; + term_end[term_end.size() - 1]++; // increment last character key code of search term for End-Key ixparams.bounds.endKey = FTSIndexFormat::getIndexKey( - 0, term, _params.indexPrefix, _params.spec.getTextIndexVersion()); - ixparams.bounds.boundInclusion = BoundInclusion::kIncludeBothStartAndEndKeys; + MAX_WEIGHT, term_end, _params.indexPrefix, _params.spec.getTextIndexVersion()); + ixparams.bounds.endKeyInclusive = false; // End key is not inclusive (endKey is artificially generated) + ixparams.bounds.isSimpleRange = true; ixparams.descriptor = _params.index; - ixparams.direction = -1; + ixparams.direction = 1; textScorer->addChild(make_unique(opCtx, ixparams, ws, nullptr)); }