php - 使用 Solarium php 的建议查询中的 HTTP 错误问题
问题描述
我正在使用日光浴室在 php codeigiter 中实现建议查询。但同时连接到createSuggester
查询。它显示以下错误行。
An uncaught Exception was encountered
Type: Solarium\Exception\HttpException
Message: Solr HTTP error: OK (404)
HTTP ERROR 404
Problem accessing /solr/../suggest. Reason:
Not Found
Filename: C:\wamp\www\solariumphp\vendor\solarium\solarium\src\Core\Query\Result\Result.php
Line Number: 59
Backtrace:
File: C:\wamp\www\solariumphp\vendor\solarium\solarium\src\Core\Client\Client.php
Line: 751
Function: __construct
File: C:\wamp\www\solariumphp\vendor\solarium\solarium\src\Core\Client\Client.php
Line: 783
Function: createResult
File: C:\wamp\www\solariumphp\vendor\solarium\solarium\src\Core\Client\Client.php
Line: 978
Function: execute
File: C:\wamp\www\solariumphp\application\controllers\Example.php
Line: 30
Function: suggester
File: C:\wamp\www\solariumphp\index.php
Line: 315
Function: require_once
我的示例代码在这里,
$query = $this->client->createSuggester();
$query->setQuery('ap ip v'); //multiple terms
$query->setDictionary('suggester');
// $query->setOnlyMorePopular(true);
$query->setCount(10);
// $query->setCollate(true);
// this executes the query and returns the result
$resultset = $this->client->suggester($query);
echo '<b>Query:</b> '.$query->getQuery().'<hr/>';
// display results for each term
foreach ($resultset as $term => $termResult) {
echo '<h3>' . $term . '</h3>';
echo 'NumFound: '.$termResult->getNumFound().'<br/>';
echo 'StartOffset: '.$termResult->getStartOffset().'<br/>';
echo 'EndOffset: '.$termResult->getEndOffset().'<br/>';
echo 'Suggestions:<br/>';
foreach ($termResult as $result) {
echo '- '.$result.'<br/>';
}
echo '<hr/>';
}
// display collation
echo 'Collation: '.$resultset->getCollation();
我试图在许多资源中找到解决方案。但解决方案不存在。请解释一下这个问题是什么/为什么会发生?
解决方案
您可以像这样在“solrconfig.xml”中设置默认字典:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FreeTextLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">content</str>
<str name="suggestFreeTextAnalyzerFieldType">suggestTypeLc</str>
<str name="buildOnStartup">true</str>
<str name="buildOnCommit">false</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">10</str>
<str name="suggest.dictionary">mySuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
并从您的代码中删除这一行:
$query->setDictionary('suggester');
推荐阅读
- sql - 如何编写一个 SQL 查询来显示与特定产品在同一购物车中销售的前 5 件商品?
- react-native - react-native-webrtc 无法创建 RTCPeerConnection
- ruby-on-rails - 在 rspec 的上下文中循环不会正确设置 let 变量
- vb.net - 控制在其位置不断变化时闪烁
- haskell - 我可以编译这个模棱两可的类型函数吗?
- java - 处理 Firestore 数据库对象
- ios - 用字典分割表视图
- css - 如何使页面中的图像全宽
- javascript - Javascript-无法在“MutationObserver”上执行“观察”
- c++ - 编译器生成具有 constexpr 混淆行为的默认构造函数