本文整理汇总了PHP中Solarium_Client::suggester方法的典型用法代码示例。如果您正苦于以下问题:PHP Solarium_Client::suggester方法的具体用法?PHP Solarium_Client::suggester怎么用?PHP Solarium_Client::suggester使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solarium_Client
的用法示例。
在下文中一共展示了Solarium_Client::suggester方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
function handle($args)
{
/*
* Make sure we have a search term.
*/
if (!isset($args['term']) || empty($args['term'])) {
json_error('Search term not provided.');
die;
}
/*
* Clean up the search term.
*/
$term = filter_var($args['term'], FILTER_SANITIZE_STRING);
/*
* Append an asterix to the search term, so that Solr can suggest autocomplete terms.
*/
$term .= '*';
/*
* Intialize Solarium.
*/
$client = new Solarium_Client($GLOBALS['solr_config']);
/*
* Set up our query.
*/
$query = $client->createSuggester();
$query->setHandler('suggest');
$query->setQuery($term);
$query->setOnlyMorePopular(TRUE);
$query->setCount(5);
$query->setCollate(TRUE);
/*
* Execute the query.
*/
$search_results = $client->suggester($query);
/*
* If there are no results.
*/
if (count($search_results) == 0) {
$response->terms = FALSE;
} else {
$response->terms = array();
foreach ($search_results as $term => $term_result) {
$i = 0;
foreach ($term_result as $suggestion) {
$response->terms[] = array('id' => $i, 'term' => $suggestion);
$i++;
}
}
}
$this->render($response, 'OK');
}
示例2: foreach
<?php
require 'init.php';
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a suggester query instance
$query = $client->createSuggester();
$query->setQuery('ap ip v');
//multiple terms
$query->setDictionary('suggest');
$query->setOnlyMorePopular(true);
$query->setCount(10);
$query->setCollate(true);
// this executes the query and returns the result
$resultset = $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();