Skip to content

Commit

Permalink
Version bump, minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Nov 22, 2015
1 parent 7343858 commit eb824c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
70 changes: 35 additions & 35 deletions lib/rankers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,23 @@ function standard( options ) {
directMatches,
partialMatches,

docExists;
currentDocument,

// Helper function to create or get a document result object
getResultObj = function (docId) {
var doc;
if ( !(doc = documentResults[docId]) ) {
doc = documentResults[docId] = {
documentId: docId,
totalWeight: 0,
partialMatches: 0,
directMatches: 0,
directMatchedExpressions: {},
matchedExpressions: {}
};
}
return doc;
};

// Find all documents
for ( var key = 0; key < resultSet.expressions.length; key++ ) {
Expand All @@ -72,49 +88,33 @@ function standard( options ) {
directMatches = currentExpression.hits.direct;
partialMatches = currentExpression.hits.partial;

// Create result object

if (directMatches !== undefined ) {
for( i = 0; i < directMatches.length; i+=3 ) {
currentMatchWeight = options.directHit * options.fields[directMatches[i+1]];
if ( docExists = documentResults[directMatches[i]] ) {
docExists.totalWeight += currentMatchWeight;
docExists.directMatches += directMatches[i+2];
docExists.directMatchedExpressions[key] = true;
docExists.matchedExpressions[key] = true;
} else {
documentResults[directMatches[i]] = {
documentId: directMatches[i],
totalWeight: currentMatchWeight,
directMatches: directMatches[i+2],
partialMatches: 0,
directMatchedExpressions: {},
matchedExpressions: {},
};
documentResults[directMatches[i]].directMatchedExpressions[key] = true;
documentResults[directMatches[i]].matchedExpressions[key] = true;
}

currentDocument = getResultObj (directMatches[i]);

currentDocument.totalWeight += options.directHit * options.fields[directMatches[i+1]];
currentDocument.directMatches += directMatches[i+2];
currentDocument.directMatchedExpressions[key] = true;
currentDocument.matchedExpressions[key] = true;

}
}

if (partialMatches !== undefined ) {
for( i = 0; i < partialMatches.length; i+=3 ) {
currentMatchWeight = options.partialHit * options.fields[partialMatches[i+1]];
if ( docExists = documentResults[partialMatches[i]] ) {
docExists.totalWeight += currentMatchWeight;
docExists.partialMatches += partialMatches[i+2];
docExists.matchedExpressions[key] = true;
} else {
documentResults[partialMatches[i]] = {
documentId: partialMatches[i],
totalWeight: currentMatchWeight,
partialMatches: partialMatches[i+2],
directMatches: 0,
directMatchedExpressions: {},
matchedExpressions: {}
};
documentResults[partialMatches[i]].matchedExpressions[key] = true;
}

currentDocument = getResultObj (partialMatches[i]);

currentDocument.totalWeight += options.partialHit * options.fields[partialMatches[i+1]];
currentDocument.partialMatches += partialMatches[i+2];
currentDocument.matchedExpressions[key] = true;

}
}

};

// Convert document results from object to array (to be sortable)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thinker-fts",
"version": "1.0.3",
"version": "1.0.4",
"description": "Javascript/Node.js in-memory full text search engine.",
"author": "Hexagon <github.com/hexagon>",
"contributors": [{
Expand Down

0 comments on commit eb824c3

Please sign in to comment.