Added raw searching function, useful for appending multiple searches
together. Clarified a few comments, changed the names of a few internal functions.
This commit is contained in:
parent
45508e74d6
commit
bb85b1e73a
40
tidx.js
40
tidx.js
@ -62,9 +62,9 @@ var Tidx = function()
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Conducts a global search for a string (value) globally,
|
// Conducts a global index scan for a string (value), iterating
|
||||||
// iterating through all fields.
|
// through all fields.
|
||||||
this.gsearch = 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 []; }
|
||||||
@ -86,8 +86,8 @@ var Tidx = function()
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Conducts a field specific search for a string (value)
|
// Conducts a field specific scan for a string (value)
|
||||||
this.fsearch = function(field, value, result)
|
this.field_scan = function(field, value, result)
|
||||||
{
|
{
|
||||||
var f;
|
var f;
|
||||||
switch(typeof field){
|
switch(typeof field){
|
||||||
@ -112,14 +112,9 @@ var Tidx = function()
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Multi-term searching function. This is what you should use
|
// Raw searching function useful for chaining seaches
|
||||||
// to search with. If and_query is true, returned results
|
this.raw_search = function(search, result)
|
||||||
// must match every term. Otherwise, any ID matching any
|
|
||||||
// term is returned.
|
|
||||||
this.search = function(and_query, search)
|
|
||||||
{
|
{
|
||||||
var r = {};
|
|
||||||
|
|
||||||
var re, tc=0;
|
var re, tc=0;
|
||||||
while((re = this.s_rx.exec(search)) !== null){
|
while((re = this.s_rx.exec(search)) !== null){
|
||||||
var field = re[2];
|
var field = re[2];
|
||||||
@ -132,15 +127,30 @@ var Tidx = function()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global term
|
// Field specific scan for term
|
||||||
if(field !== undefined && field.length !== 0){
|
if(field !== undefined && field.length !== 0){
|
||||||
this.fsearch(field, value, r);
|
this.field_scan(field, value, result);
|
||||||
|
// Global scan for term
|
||||||
} else {
|
} else {
|
||||||
this.gsearch(value, r);
|
this.global_scan(value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
tc++;
|
tc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Multi-term searching function. This is what you should use
|
||||||
|
// to search with in most cases. If and_query is true, returned
|
||||||
|
// results must match every term. Otherwise, any ID matching any
|
||||||
|
// term is returned.
|
||||||
|
this.search = function(and_query, search)
|
||||||
|
{
|
||||||
|
var r = {};
|
||||||
|
var tc = this.raw_search(search, r);
|
||||||
|
|
||||||
return this.order(r, (and_query ? tc : 0));
|
return this.order(r, (and_query ? tc : 0));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user