我正在使用Silverstripe FullTextSearch。我的審訊是如何在自定義字段中搜索並顯示結果。有一個在index.md代碼寫:Silverstripe全文搜索自定義字段
文件:mysite的/代碼/ MyIndex.php:
<?php
class MyIndex extends SolrIndex {
function init() {
$this->addClass('MyPage');
$this->addFulltextField('Description');
}
}
在page.php文件
class Page_Controller extends ContentController {
private static $allowed_actions = array('search');
public function search($request) {
$query = new SearchQuery();
$query->search($request->getVar('q'));
return $this->renderWith('array(
'SearchResult' => singleton('MyIndex')->search($query)
));
}
}
當我試圖尋找一些話從描述字段,找不到結果...建議?
感謝您的回覆。你的搜索方法是否像部分匹配? ℅something℅?如果是這樣,它不足以搜索複雜的單詞或錯誤的單詞。我已經使自己的搜索代碼從%數據庫中直接獲取數據,我發現這對我的網站來說還不夠。 – StefGuev
不幸的是,它使用局部match。我想另一種解決方案是研究創建一個利用全文搜索的自定義過濾器,或者使用SQLQuery類手動編寫SQL(更多信息請參見https://docs.silverstripe.org/en/3.4/developer_guides/model/sql_query /) – PsychoMo
Humm ok,如果我找到解決方案,我會發布它,謝謝你試圖幫助我 – StefGuev