如何使用jquery、javascript或php优化字符串搜索功能

如何使用jquery、javascript或php优化字符串搜索功能,javascript,php,jquery,mysql,search,Javascript,Php,Jquery,Mysql,Search,如何可以忽略常见的英语单词,只返回关键字,然后在MySQL数据库中进行搜索。例如,如果用户键入“我在哪里可以找到冰淇淋”,它应该返回“冰淇淋”之类的关键字,我可以在MySQL上查询它。您正在查找StopWords: $stopwords = array(“a”, “about”, “above”, “above”, “across”, “after”, “afterwards”, “again”, “against”, “all”, “almost”, “alone”, “along”, “al

如何可以忽略常见的英语单词,只返回关键字,然后在MySQL数据库中进行搜索。例如,如果用户键入“我在哪里可以找到冰淇淋”,它应该返回“冰淇淋”之类的关键字,我可以在MySQL上查询它。

您正在查找StopWords:

$stopwords = array(“a”, “about”, “above”, “above”, “across”, “after”, “afterwards”, “again”, “against”, “all”, “almost”, “alone”, “along”, “already”, “also”,”although”,”always”,”am”,”among”, “amongst”, “amoungst”, “amount”,  “an”, “and”, “another”, “any”,”anyhow”,”anyone”,”anything”,”anyway”, “anywhere”, “are”, “around”, “as”,  “at”, “back”,”be”,”became”, “because”,”become”,”becomes”, “becoming”, “been”, “before”, “beforehand”, “behind”, “being”, “below”, “beside”, “besides”, “between”, “beyond”, “bill”, “both”, “bottom”,”but”, “by”, “call”, “can”, “cannot”, “cant”, “co”, “con”, “could”, “couldnt”, “cry”, “de”, “describe”, “detail”, “do”, “done”, “down”, “due”, “during”, “each”, “eg”, “eight”, “either”, “eleven”,”else”, “elsewhere”, “empty”, “enough”, “etc”, “even”, “ever”, “every”, “everyone”, “everything”, “everywhere”, “except”, “few”, “fifteen”, “fify”, “fill”, “find”, “fire”, “first”, “five”, “for”, “former”, “formerly”, “forty”, “found”, “four”, “from”, “front”, “full”, “further”, “get”, “give”, “go”, “had”, “has”, “hasnt”, “have”, “he”, “hence”, “her”, “here”, “hereafter”, “hereby”, “herein”, “hereupon”, “hers”, “herself”, “him”, “himself”, “his”, “how”, “however”, “hundred”, “ie”, “if”, “in”, “inc”, “indeed”, “interest”, “into”, “is”, “it”, “its”, “itself”, “keep”, “last”, “latter”, “latterly”, “least”, “less”, “ltd”, “made”, “many”, “may”, “me”, “meanwhile”, “might”, “mill”, “mine”, “more”, “moreover”, “most”, “mostly”, “move”, “much”, “must”, “my”, “myself”, “name”, “namely”, “neither”, “never”, “nevertheless”, “next”, “nine”, “no”, “nobody”, “none”, “noone”, “nor”, “not”, “nothing”, “now”, “nowhere”, “of”, “off”, “often”, “on”, “once”, “one”, “only”, “onto”, “or”, “other”, “others”, “otherwise”, “our”, “ours”, “ourselves”, “out”, “over”, “own”,”part”, “per”, “perhaps”, “please”, “put”, “rather”, “re”, “same”, “see”, “seem”, “seemed”, “seeming”, “seems”, “serious”, “several”, “she”, “should”, “show”, “side”, “since”, “sincere”, “six”, “sixty”, “so”, “some”, “somehow”, “someone”, “something”, “sometime”, “sometimes”, “somewhere”, “still”, “such”, “system”, “take”, “ten”, “than”, “that”, “the”, “their”, “them”, “themselves”, “then”, “thence”, “there”, “thereafter”, “thereby”, “therefore”, “therein”, “thereupon”, “these”, “they”, “thickv”, “thin”, “third”, “this”, “those”, “though”, “three”, “through”, “throughout”, “thru”, “thus”, “to”, “together”, “too”, “top”, “toward”, “towards”, “twelve”, “twenty”, “two”, “un”, “under”, “until”, “up”, “upon”, “us”, “very”, “via”, “was”, “we”, “well”, “were”, “what”, “whatever”, “when”, “whence”, “whenever”, “where”, “whereafter”, “whereas”, “whereby”, “wherein”, “whereupon”, “wherever”, “whether”, “which”, “while”, “whither”, “who”, “whoever”, “whole”, “whom”, “whose”, “why”, “will”, “with”, “within”, “without”, “would”, “yet”, “you”, “your”, “yours”, “yourself”, “yourselves”, “the”);

没有完整的停止词词典,但您可以搜索停止词并改进此词典。

这就是您要查找的吗

String.prototype.replaceArray = function(find, replace) {
var replaceString = this;
var regex;
for (var i = 0; i < find.length; i++) {
 regex = new RegExp(find[i], "g");
 replaceString = replaceString.replace(regex, replace[i]);
}
 return replaceString;
};

//usage
stop_words = ['silly','these','words', '  '];
//create an empty array as long as the first one
replace_them = ['','','',''];

var test = 'Some parts of this silly sentence will these words be replaced?'.replaceArray(stop_words,  replace_them);
console.log( test );
String.prototype.replaceArray=函数(查找、替换){
var replaceString=this;
var regex;
for(var i=0;i

多亏了

没有现成的常用英语单词数据库,你知道它们是什么,但你也应该为系统编程,让系统知道。当然,有这样的单词列表。用全文搜索的说法,它们被称为“停止词”。这是MySQL的列表:。在PHP中,网络上可能有一个要下载的列表,你可以在执行搜索时使用一些逻辑并剪切你不需要的列表,比如“Where”“I”“Can”“What”“What”“How”“Do”等,并将它们放入数组中。PHP是服务器端,所以它是lightning fastnice,我不想贬低JQ,做得很好,但是如果你想替换10000字,性能不是问题。我从来没有尝试过诚实,所以我不知道我会在后台做这件事。:)但这里给出的列表很小,足以做客户端的工作。