Skip to content

Commit f03c5b1

Browse files
committed
SERVER-12325 Fix FTSSpec traversal logic for subdocuments
Fixed issue where FTSSpec::scoreDocument() would stop deep traversal of a document when it encountered a weight for the FTSSpec with a non-String BSON type which also happens to be a parent component of another weight.
1 parent f49669f commit f03c5b1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/mongo/db/fts/fts_spec.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ namespace mongo {
179179
// weight that could possibly match or be a prefix of dottedName. And if this
180180
// element fails to match, then no subsequent weight can match, since the weights
181181
// are lexicographically ordered.
182-
Weights::const_iterator i = _weights.lower_bound( dottedName );
182+
Weights::const_iterator i = _weights.lower_bound( elem.type() == Object
183+
? dottedName + '.'
184+
: dottedName );
183185

184186
// possibleWeightMatch is set if the weight map contains either a match or some item
185187
// lexicographically larger than fieldName. This boolean acts as a guard on

src/mongo/db/fts/fts_spec_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ namespace mongo {
212212
ASSERT( m["book"] < m["sat"] );
213213
}
214214

215+
TEST( FTSSpec, ScoreMultipleField2 ) {
216+
// Test where one indexed field is a parent component of another indexed field.
217+
BSONObj user = BSON( "key" << BSON( "a" << "text" << "a.b" << "text" ) );
218+
219+
FTSSpec spec( FTSSpec::fixSpec( user ) );
220+
221+
TermFrequencyMap m;
222+
spec.scoreDocument( BSON( "a" << BSON( "b" << "term" ) ),
223+
FTSLanguage::makeFTSLanguage( "english" ).getValue(),
224+
"",
225+
false,
226+
&m );
227+
ASSERT_EQUALS( 1U, m.size() );
228+
}
215229

216230
TEST( FTSSpec, ScoreRepeatWord ) {
217231
BSONObj user = BSON( "key" << BSON( "title" << "text" <<

0 commit comments

Comments
 (0)