Archived
1
0

Bug fixes for search chaining scheme

This commit is contained in:
Christopher Ramey 2012-04-06 15:21:55 +00:00 committed by cdramey
parent bb85b1e73a
commit f6aafa3659

23
tidx.js
View File

@ -63,11 +63,11 @@ var Tidx = function()
// Conducts a global index scan for a string (value), iterating // Conducts a global index scan for a string (value), iterating
// through all fields. // through all fields. Returns the number of terms it scanned for.
this.global_scan = function(value, result) this.global_scan = function(value, result)
{ {
// Refuse empty searches // Refuse empty searches
if(value.length === 0){ return []; } if(value.length === 0){ return 0; }
var v = value.toLowerCase(); var v = value.toLowerCase();
@ -83,25 +83,28 @@ var Tidx = function()
} }
} }
} }
return 1;
}; };
// Conducts a field specific scan for a string (value) // Conducts a field specific scan for a string (value), returns
// the number of terms it scanned for.
this.field_scan = function(field, value, result) this.field_scan = function(field, value, result)
{ {
var f; var f;
switch(typeof field){ switch(typeof field){
// Don't allow undefined fields // Don't allow undefined fields
case 'undefined': return; case 'undefined': return 0;
case 'string': f = field.toLowerCase(); break; case 'string': f = field.toLowerCase(); break;
default: f = String(field); default: f = String(field);
} }
if(value.length === 0){ return []; } if(value.length === 0){ return 0; }
var v = value.toLowerCase(); var v = value.toLowerCase();
if(this._index[f] === undefined || this._index[f][v] === undefined){ if(this._index[f] === undefined || this._index[f][v] === undefined){
return []; return 1;
} }
for(var i in this._index[f][v]){ for(var i in this._index[f][v]){
@ -109,6 +112,8 @@ var Tidx = function()
result[i]['w'] += this._index[f][v][i]; result[i]['w'] += this._index[f][v][i];
result[i]['c']++; result[i]['c']++;
} }
return 1;
}; };
@ -129,13 +134,11 @@ var Tidx = function()
// Field specific scan for term // Field specific scan for term
if(field !== undefined && field.length !== 0){ if(field !== undefined && field.length !== 0){
this.field_scan(field, value, result); tc += this.field_scan(field, value, result);
// Global scan for term // Global scan for term
} else { } else {
this.global_scan(value, result); tc += this.global_scan(value, result);
} }
tc++;
} }
return tc; return tc;