dpojoxa5613 2012-05-24 17:36
浏览 18
已采纳

如何创建语义搜索

I want to create a search box where instead of using a WHERE cluse in the query to match the exact phrase within a field, I want the search box to be able to perform a semantic search so that when the user enters in part of a phrase, it displays suitable results where it is able to match the meaning of a phrase. Exactly how Google works when you try and search through Google. Is this possible to achieve and does anyone have any ideas?

Below is the code I am currently using to be able to use the database to see if a row matches the exact phrase entered within the search box:

  <?php


    //connected to DB

          foreach (array('questioncontent') as $varname) {
            $questioncontent = (isset($_POST[$varname])) ? $_POST[$varname] : '';
          }

    ?>


    <p>Search for a previous question by entering in a phrase in the search box below and submitting the phrase</p>

    <form action="previousquestions.php" method="post" id="modalform">
          <p>Search: <input type="text" name="questioncontent" value="<?php echo $questioncontent; ?>" /></p>
          <p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
          </form>


    <?php 
                if (isset($_POST['searchQuestion'])) {

                  $questionquery = "SELECT QuestionContent FROM Question
              WHERE(QuestionContent = '".mysql_real_escape_string($questioncontent)."')";

          $questionnum = mysql_num_rows($questionresult = mysql_query($questionquery));

          if($questionnum !=0){

          $output = "";

            while ($questionrow = mysql_fetch_array($questionresult)) {

    $output .= "
          <table>
          <tr>
          <td>{$questionrow['QuestionContent']}</td>
          </tr>";
            }
            $output .= "        </table>";

            echo $output;

      }

    }
  • 写回答

2条回答 默认 最新

  • dtz33344 2012-05-24 17:51
    关注

    If you are looking for a PHP search engine tutorial, take a look at this YouTube video - it might help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python