当前位置: 首页>>代码示例>>PHP>>正文


PHP Solarium_Client::suggester方法代码示例

本文整理汇总了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');
 }
开发者ID:FreeLawFounders,项目名称:statedecoded,代码行数:51,代码来源:class.APISuggestController.inc.php

示例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();
开发者ID:Bine0511,项目名称:RDF-Demo,代码行数:31,代码来源:2.6-suggester-query.php


注:本文中的Solarium_Client::suggester方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。