現在的位置: 首頁 > 搜索技術 > 正文

提高sphinx(coreseek)搜索精度的方法和步驟

2020年02月12日 搜索技術 ⁄ 共 1473字 ⁄ 字型大小 評論關閉

  由於coreseek帶的mmseg默認詞庫只有1w多個字詞,搜索出來的結果準確度不是很理想。花了半天找了下搜索引擎相關的資料,現在記錄下一些提高搜索精度的方法和步驟。

  提高coreseek的搜索精度的方法:

  1. 基礎詞庫要足夠豐富,因為只有基礎詞庫豐富了,才能談權重設置。

  2. 增加相關業務領域的辭彙,進一步提升詞庫量,如果不是做綜合搜索,一般都只需要提高自身業務領域的辭彙。

  3. 記錄與收集用戶搜索,把搜索記錄高的作為新增辭彙加入到詞庫中(前提是詞庫中不存在這個詞)。

  所以第一件事就是豐富基礎詞庫,詞庫可以去搜狗拼音,QQ拼音官網下載。下下來後,統一把辭彙進行處理,添加到一個辭彙數據表 unigram,這個表只需包含id, word兩列,id為自增欄位,word為key欄位,以保證這個詞是獨一無二的。

  然後寫個php腳本,把這個 unigram 表的數據轉成 unigram.txt(mmseg要求的字典格式),下面是這個腳本的簡單步驟:

  < ?php

  set_time_limit(0);

  define(IN_SITE, true);

  require 'config.php';

  require 'db_class.php';

  $db = new dbstuff();

  $db->connect($dbhost, $dbuser, $dbpw, $dbname);

  $max_id = $db->result_first('SELECT MAX(id) FROM unigram2');

  $limit = 2000;

  $start_page = isset($_GET['id']) ? (int)$_GET['id'] : 0;

  $start_id = $limit * $start_page;

  if ($start_id > $max_id) exit('ok');

  $sql = "SELECT word FROM unigram2 limit {$start_id}, {$limit}";

  $query = $db->query($sql);

  while ($arr = $db->fetch_array($query)) {

  $str .= $arr['word'] . "\t1\r\nx:1\r\n";

  }

  $file = './unigram3.txt';

  $h = fopen($file, 'a');

  fwrite($h, $str);

  $start_page++;

  $url_forward = 'import.php?id='.$start_page;

  echo '< script>window.location.href = "'.$url_forward.';;< /script>';

  ?>

  得到新增的txt後,把這個txt里的所有內容複製到默認詞典的底部。合併原有的的詞庫。

  然後是用mmseg合併詞典。

  cd /usr/local/mmseg3/

  bin/mmseg -u etc/unigram.txt

  執行上面的命令後,會生成 unigram.uni 文件,把它重命名為uni.lib(原來也有一個,可以對舊的改名)。

  此時詞庫生成,但還需要重新生成一次索引,

  cd /usr/local/coreseek

  bin/indexer -c etc/xxx.conf --all

  重啟searchd:

  bin/searchd -c etc/xxx.conf --stop

  bin/searchd -c etc/xxx.conf

  至此,擴充詞庫並應用到索引的過程就完成了!

抱歉!評論已關閉.