bootstrap-ajax-typeahead - partial search mod« Wróć do listy pytań

how to improve search?
Wysłane przez mrmucha
Zadane przez 06/07/2018 11:03
0
 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;
Wysłane przez mrmucha
Odpowiedziane 06/07/2018 11:14