简体   繁体   English

PHP搜索脚本中的多个单词

[英]PHP search script for multiple words

I have the following issue: 我有以下问题:

I can't search multiple words. 我无法搜索多个单词。

I have a search engine who search just the full string: 我有一个搜索引擎,它只搜索完整的字符串:

PHP Code: PHP代码:


function ft_search_sidebar() {
  $sidebar[] = array(
    "id" => "search_1",
    "content" => '<div class="section">
        <h2>'.t('Search files &amp; folders').'</h2>
        <form action="" method="post" id="searchform">
            <div>
                <input type="text" name="q" id="q" size="16" value="'.$_REQUEST['q'].'" />
                <input type="button" id="dosearch" value="'.t('Search').'" />
            </div>
            <div id="searchoptions">
                <input type="checkbox" name="type" id="type" checked="checked" /> <label for="type">'.t('Search only this folder and below').'</label>
            </div>
            <div id="searchresults"></div>
        </form>
    </div>'
  );
  return $sidebar;
}


function ft_search_ajax($act) {
  if ($act = '%search%') {
    $new = array();
    $ret = "";
    $q = $_POST['q'];
    $type = $_POST['type'];
    if (!empty($q)) {
        if ($type == "true") {
            $list = _ft_search_find_files(ft_get_dir(), $q);
        } else {
            $list = _ft_search_find_files(ft_get_root(), $q);
        }

Can someone help me? 有人能帮我吗?

Grtz 格茨

You will need to either develop a search engine which is capable of multi keyword search or simply extract out all the keywords from the search string and then use the search engine multiple times for each keyword. 您将需要开发一个能够进行多关键字搜索的搜索引擎,或者简单地从搜索字符串中提取所有关键字,然后对每个关键字多次使用搜索引擎。 Like this: 像这样:

$q = $_POST['q'];
$type = $_POST['type'];
if (!empty($q)) {
    if(strpos(trim($q),' ') > 0)
    {
         $array = explode(' ',trim($q));
         foreach($array as $key=>$value)
         {
             //process search multiple times for different values of $value
         }
    }
    else
    {
         if ($type == "true")
         {
             $list = _ft_search_find_files(ft_get_dir(), $q);
         }
         else
         {
             $list = _ft_search_find_files(ft_get_root(), $q);
         }
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM