我正在使用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