[英]MySQL/PHP fulltext search 1 word similarity
我有一個客戶想要管理網站中任何頁面的SEO標題/描述,因此我考慮制作一個模塊,供他輸入URL / TITLE / DESCRIPTION,然后網站將檢查該頁面是否有條目,如果有,請顯示。
我已經試過了:
$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$q_seo = $conexio->query('SELECT modulseo.titol, modulseo.descripcio, MATCH(modulseo.url) AGAINST("'.$url.'") AS score FROM modulseo WHERE MATCH(modulseo.url) AGAINST("'.$url.'") ORDER BY score DESC LIMIT 0,1');
if(mysql_num_rows($q_seo)>0)
{
$d_seo = mysql_fetch_array($q_seo);
$titol = $d_seo['titol'];
$descripcio = $d_seo['descripcio'];
}
else
{
$titol = 'default title';
$descripcio = 'default description';
}
這顯然是行不通的,因為我相信全文搜索只能使用匹配的不同單詞,而不是1個單詞與另一個單詞之間的相似性,因為客戶端可以在后端URL中輸入以下內容:
http://www.domain.com/index.php
http://domain.com/index.php
http://www.domain.com/index.php?language=fr
http://domain.com/index.php?language=fr
然后網站的用戶可以訪問這些網址中的任何一個,因此必須有一種方法可以將任何網址與客戶端在客戶端中設置的任何網址進行匹配。
有關如何執行此操作的任何線索?
使用LIKE %varible%
進行搜索這是一個較慢的查詢,但可以使用。
您的表引擎必須是MyISAM,或者如果您的MySQL -v 5.6+,則可以將InnoDB與全文索引一起使用
mysql> select * from test;
+------+------+------------------------------+
| ids | name | last_name |
+------+------+------------------------------+
| 0 | 0 | http://domain.com/index.php |
| 1 | 0 | http://domain2.com/index.php |
| 2 | 0 | http://domain3.com/index.php |
+------+------+------------------------------+
3 rows in set (0.00 sec)
mysql> select * from test where last_name like '%http://domain.com/index.php%';
+------+------+-----------------------------+
| ids | name | last_name |
+------+------+-----------------------------+
| 0 | 0 | http://domain.com/index.php |
+------+------+-----------------------------+
1 row in set (0.00 sec)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.