@@ -206,38 +206,6 @@ class TokenIndex {
206206 return tokenMatch;
207207 }
208208
209- /// Returns an {id: score} map of the documents stored in the [TokenIndex] .
210- /// The tokens in [tokenMatch] will be used to calculate a weighted sum of scores.
211- ///
212- /// When [limitToIds] is specified, the result will contain only the set of
213- /// identifiers in it.
214- Map <String , double > _scoreDocs (TokenMatch tokenMatch,
215- {double weight = 1.0 , Set <String >? limitToIds}) {
216- // Summarize the scores for the documents.
217- final scores = IndexedScore (_ids);
218- for (final token in tokenMatch.tokens) {
219- final docWeights = _inverseIds[token]! ;
220- for (final e in docWeights.entries) {
221- scores.setValueMaxOf (e.key, tokenMatch[token]! * e.value);
222- }
223- }
224-
225- if (limitToIds != null ) {
226- scores.retainWhere ((_, id) => limitToIds.contains (id));
227- }
228- final result = < String , double > {};
229- // post-process match weights
230- for (var i = 0 ; i < _length; i++ ) {
231- final w = scores._values[i];
232- if (w <= 0.0 ) {
233- continue ;
234- }
235- final id = _ids[i];
236- result[id] = scores._values[i] * weight;
237- }
238- return result;
239- }
240-
241209 /// Search the index for [text] , with a (term-match / document coverage percent)
242210 /// scoring.
243211 @visibleForTesting
@@ -247,25 +215,20 @@ class TokenIndex {
247215
248216 /// Search the index for [words] , with a (term-match / document coverage percent)
249217 /// scoring.
250- Score searchWords (List <String > words,
251- {double weight = 1.0 , Set <String >? limitToIds}) {
252- if (limitToIds != null && limitToIds.isEmpty) {
253- return Score .empty;
254- }
255- final scores = < Score > [];
218+ Score searchWords (List <String > words, {double weight = 1.0 }) {
219+ if (words.isEmpty) return Score .empty;
220+ IndexedScore ? score;
221+ weight = math.pow (weight, 1 / words.length).toDouble ();
256222 for (final w in words) {
257- final tokens = lookupTokens (w);
258- final values = _scoreDocs (
259- tokens,
260- weight: weight,
261- limitToIds: limitToIds,
262- );
263- if (values.isEmpty) {
264- return Score .empty;
223+ final s = IndexedScore (_ids);
224+ searchAndAccumulate (w, score: s, weight: weight);
225+ if (score == null ) {
226+ score = s;
227+ } else {
228+ score.multiplyAllFrom (s);
265229 }
266- scores.add (Score (values));
267230 }
268- return Score . multiply (scores) ;
231+ return score ? . toScore () ?? Score .empty ;
269232 }
270233
271234 /// Searches the index with [word] and stores the results in [score] , using
0 commit comments