Forum

bootstrap-ajax-type...
 
Notifications
Clear all

bootstrap-ajax-typeahead - partial search mod

1 Posty
1 Users
0 Likes
1,198 Widok
0
Topic starter

how to improve search?

1 Answer
0
Topic starter
    var partial_highlighter = function (item) {
var search_query = this.query;
var query_contains_space = this.query.toLowerCase().indexOf(" ");

if (query_contains_space <= 0) {
var query = search_query.replace(/[-[]{}()*+?.,\^$|#s]/g, '\$&');
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '' + match + '';
});
} else {
var splited = search_query.toLowerCase().split(" ");
$.each( splited, function( index, value ){
var query = value.replace(/[-[]{}()*+?.,\^$|#s]/g, '\$&');
item = item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '' + match + '';
});
});
return item;
}
};

var partial_matcher = function (item) {
var search_query = this.query;
var query_contains_space = this.query.toLowerCase().indexOf(" ");

if (query_contains_space <= 0) {
var query = search_query.replace(/[-[]{}()*+?.,\^$|#s]/g, '\$&');
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '' + match + '';
});
} else {
var splited = search_query.toLowerCase().split(" ");
$.each( splited, function( index, value ){
var query = value.replace(/[-[]{}()*+?.,\^$|#s]/g, '\$&');
item = item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '' + match + '';
});
});
return item;
}
};

$.fn.typeahead.Constructor.prototype.highlighter = partial_highlighter;
$.fn.typeahead.Constructor.prototype.matcher = partial_matcher;

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: