Skip to content

Commit

Permalink
Improved comments for changes to fieldSearch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Halle committed Apr 11, 2016
1 parent 527ea24 commit 143294a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,33 @@ elasticlunr.Index.prototype.fieldSearch = function (queryTokens, fieldName, conf
if (expand == true) {
tokens = this.index[fieldName].expandToken(token);
}
// Consider every query token in turn. If expanded, each query token
// corresponds to a set of tokens, which is all tokens in the
// index matching the pattern queryToken* .
// For the set of tokens corresponding to a query token, find and score
// all matching documents. Store those scores in queryTokenScores,
// keyed by docRef.
// Then, depending on the value of booleanType, combine the scores
// for this query token with previous scores. If booleanType is OR,
// then merge the scores by summing into the accumulated total, adding
// new document scores are required (effectively a union operator).
// If booleanType is AND, accumulate scores only if the document
// has previously been scored by another query token (an intersection
// operation0.
// Furthermore, since when booleanType is AND, additional
// query tokens can't add new documents to the result set, use the
// current document set to limit the processing of each new query
// token for efficiency (i.e., incremental intersection).

var queryTokenScores = {};
tokens.forEach(function (key) {
var docs = this.index[fieldName].getDocs(key);
var idf = this.idf(key, fieldName);

if (scores && booleanType == 'AND') {
// special case, we can rule out documents that have been
// already been filtered out because they don't contain
// required tokens.
// already been filtered out because they weren't scored
// by previous query token passes.
var filteredDocs = {};
for (var docRef in scores) {
if (docRef in docs) {
Expand All @@ -404,7 +422,6 @@ elasticlunr.Index.prototype.fieldSearch = function (queryTokens, fieldName, conf
}
docs = filteredDocs;
}

// only record appeared token for retrieved documents for the
// original token, not for expaned token.
// beause for doing coordNorm for a retrieved document, coordNorm only care how many
Expand Down

0 comments on commit 143294a

Please sign in to comment.