Solr Suggester“自动完成”带有 php 的组件
我使用 apache-solr-3.5.0,我想做一个类似的东西: http://www.kaufda.de/ Berlin
(短语建议)
我使用了 Suggester -(Solr 的灵活“自动完成”组件)
如本文所述:http://css.dzone.com/news/solr-and-autocomplete-part -2
这是我的 solrconfig :
<searchComponent name="suggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">name_autocomplete</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Shema.xml
<fieldType class="solr.TextField" name="text_auto">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
<field name="name" type="text" indexed="true" stored="true" multiValued="false" />
<field name="name_autocomplete" type="text_auto" indexed="true" stored="true" multiValued="false" />
<field name="description" type="text" indexed="true" stored="true" multiValued="false" />
<copyField source="name" dest="name_autocomplete" />
在我的 php 代码上:
$solr = $this->getSolr();
$response = NULL;
if (!$solr) {
return;
}
$params = array();
$params['spellcheck.build'] = 'true';
$params['spellcheck'] = 'true';
$params['qt'] = '';
$result = $solr->search( 'har', 0, 10, $params );
结果是一个没有建议的数组。
我如何将 Suggester 与 php 一起使用?
预先感谢您的帮助
干杯
I use apache-solr-3.5.0 and i want make an something like : http://www.kaufda.de/Berlin
(Phrase suggestion)
I used the Suggester - (a flexible "autocomplete" component for Solr)
Like described on this article : http://css.dzone.com/news/solr-and-autocomplete-part-2
This is my solrconfig :
<searchComponent name="suggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">name_autocomplete</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Shema.xml
<fieldType class="solr.TextField" name="text_auto">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
<field name="name" type="text" indexed="true" stored="true" multiValued="false" />
<field name="name_autocomplete" type="text_auto" indexed="true" stored="true" multiValued="false" />
<field name="description" type="text" indexed="true" stored="true" multiValued="false" />
<copyField source="name" dest="name_autocomplete" />
On my php code :
$solr = $this->getSolr();
$response = NULL;
if (!$solr) {
return;
}
$params = array();
$params['spellcheck.build'] = 'true';
$params['spellcheck'] = 'true';
$params['qt'] = '';
$result = $solr->search( 'har', 0, 10, $params );
The result is an array without suggestion.
How can i use Suggester with php ?
Thank's in advance for help
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用建议器组件本身,而不是使用拼写检查组件。
注意:AnalyzingInfixLookupFactory 还允许您搜索中缀。假设您的搜索项是 Squash 并且用户输入 uash,Squash 将作为建议提供。
即使用户犯了拼写错误,FuzzyLookupFactory也将允许您提供建议。
这些是在 solrconfig.xml 文件中进行的更改,从 php 创建实例也在本页的其他答案中得到了很好的解释。所以我跳过那部分。希望这有帮助。
编辑:如果您想将实例创建为
$result,您还必须在 Service.php 中编写一个建议服务,该服务与搜索服务非常相似= $solr->**suggest**( 'har', 0, 10, $params );
而不是$result = $solr->**search**( 'har' , 0, 10, $参数);
Instead of using the spellcheck component, you can use the suggester component itself.
Note: AnalyzingInfixLookupFactory allows you to search for infixes as well. Suppose your search item is Squash and the user types uash, Squash will be provided as a suggestion.
FuzzyLookupFactory will allow you to provide suggestion even when the user does a spelling mistake.
These are the changes to be done in the solrconfig.xml file, creating an instance from php are well explained in the other answers on this page as well. So I skip that part. Hope this helps.
EDIT: You will also have to write a suggest service in Service.php which is very similar to the search service if you want to create the instance as
$result = $solr->**suggest**( 'har', 0, 10, $params );
instead of$result = $solr->**search**( 'har', 0, 10, $params );
您是否尝试直接在 solr 上进行测试?最好看看这些值是否正确生成,然后您就可以调试 PHP 代码。
您可以通过访问以下内容查看这些值:
http://localhost:8983/solr/suggest?q=har&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
您可能需要如果您不使用默认配置,请更改端口。
Did you try to do a test directly on solr? That would be best to see if the values are generated properly and then you can debug the PHP code.
You can see the values by accessing:
http://localhost:8983/solr/suggest?q=har&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
You might need to change the port if you are not using the default configuration.
查看 http://www.cominvent.com/ 2012/01/25/super-flexible-autocomplete-with-solr/ 更灵活的建议器。
也不建议每次询问建议时都构建字典(spellcheck.build=true)。
Check out http://www.cominvent.com/2012/01/25/super-flexible-autocomplete-with-solr/ for an even more flexible suggester.
Also building dictionary (spellcheck.build=true) every time you ask for suggestion is not recommended.
经过搜索并在您的帮助下,我找到了解决方案。
参数是正确的。
网址: http://本地主机:8983/solr/suggest?q=har&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
给出良好的结果
在我的 php 代码中,我添加了带有“/suggest”值的 qt 参数
新代码
我感谢您的帮助,
干杯
After searching and with all your help, i found the solution.
The params are correct.
The url : http://localhost:8983/solr/suggest?q=har&spellcheck=true&spellcheck.collate=true&spellcheck.build=true
give the good result
On my php code i added the qt param with the '/suggest' value
The new code
I appreciate your help,
Cheers
使用搜索组件而不是拼写检查
在 solrconfig.xml 中添加此代码 在 Solarconfig.xml 中
指定建议处理程序
在 try 块内的 php 中使用以下代码
其中 $query_param 是请求。 mainSuggester 是 solrconfig.xml 文件中指定的字典名称
这里 $data 将返回整个建议的数组对象
Use the search component instead of spell check
Add this code in your solrconfig.xml
Specify a handler for suggest in solarconfig.xml
And in php inside your try block use the follwoing code
Where $query_param is the request. And mainSuggester is the dictionary name as specified in the solrconfig.xml file
Here $data will return you the entire suggested array object