本文整理汇总了PHP中Zend_Search_Lucene_Interface::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Interface::find方法的具体用法?PHP Zend_Search_Lucene_Interface::find怎么用?PHP Zend_Search_Lucene_Interface::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Interface
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Interface::find方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
/**
* Search into files
*
* @param string $query The query
* @return array The file list
*/
public function find($query)
{
$result = array();
$hits = $this->_data->find($query);
foreach ($hits as $hit) {
$document = $hit->getDocument();
$result[] = $document->path;
}
return $result;
}
示例2: get_similar_posts
/**
* Return a list of posts that are similar to the current post.
* This is not a very good implementation, so do not expect
* amazing results - the term vector is not available for a doc
* in ZSL, which limits how far you can go!
*
* @return array ids
*/
public function get_similar_posts($post, $max_recommended = 5)
{
Zend_Search_Lucene::setResultSetLimit($max_recommended + 1);
$title = $post->title;
$tags = $post->tags;
$tagstring = '';
foreach ($tags as $tag) {
$tagstring .= $tag . ' ';
}
$analyser = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
$tokens = $analyser->tokenize(strtolower($tagstring) . ' ' . strtolower($title));
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($tokens as $token) {
$query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()));
}
$hits = $this->_index->find($query);
$ids = array();
$counter = 0;
foreach ($hits as $hit) {
if ($hit->postid != $post->id) {
$ids[] = $hit->postid;
$counter++;
}
if ($counter == $max_recommended) {
break;
}
}
return $ids;
}
示例3: search
/**
* Execute the query
*
* @param string|Zym_Search_Lucene_IQuery $query
* @param int $resultSetLimit
* @return array
*/
public function search($query, $resultSetLimit = null)
{
if (!$resultSetLimit) {
$resultSetLimit = self::$_defaultResultSetLimit;
}
Zend_Search_Lucene::setResultSetLimit((int) $resultSetLimit);
return $this->_searchIndex->find((string) $query);
}
示例4: removeFromIndex
public static function removeFromIndex($term)
{
$websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
$searchIndexFolder = $websiteHelper->getPath() . 'cache/' . Widgets_Search_Search::INDEX_FOLDER;
if (!is_dir($searchIndexFolder)) {
return false;
}
if (!self::initIndex()) {
return false;
}
$hits = self::$_index->find(strval($term));
if (is_array($hits) && !empty($hits)) {
foreach ($hits as $hit) {
self::$_index->delete($hit->id);
}
return true;
}
return false;
}
示例5: query
/**
* Find, format, return results
*
* @param \Zend_Search_Lucene_Interface $index
* @param string $query
* @return array
*/
public function query(\Zend_Search_Lucene_Interface $index, $query)
{
$preparedQuery = $this->prepareQuery($query);
$q = Parser::parse($preparedQuery);
/* @var $hits \Zend_Search_Lucene_Search_QueryHit[] */
$hits = $index->find($q, 'type', SORT_REGULAR, SORT_DESC);
// if no hits are found with an exact phrase, fall back to token search
if (count($hits) === 0) {
$q = Parser::parse($query);
$hits = $index->find($q, 'type', SORT_REGULAR, SORT_ASC);
}
$results = array();
foreach ($hits as $hit) {
$h = array();
$h['title'] = $hit->getDocument()->getFieldValue('title');
$h['url'] = $hit->getDocument()->getFieldValue('url');
$h['score'] = $hit->score;
$h['type'] = $hit->getDocument()->getFieldValue('type');
$results[] = $h;
}
return $results;
}
示例6: find
/**
* Performs a query against the index and returns an array
* of Zend_Search_Lucene_Search_QueryHit objects.
* Input is a string or Zend_Search_Lucene_Search_Query.
*
* @param mixed $query
* @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception
*/
public function find($query)
{
return $this->_index->find($query);
}
示例7: getIndexedChildrenDocuments
/**
* Find all existing lucene documents based on the parent url
* @param Zend_Search_Lucene_Interface $index
* @param AJXP_Node $ajxpNode
* @return Zend_Search_Lucene_Search_QueryHit
*/
public function getIndexedChildrenDocuments($index, $ajxpNode)
{
// Try getting doc by url
$testQ = str_replace("/", "AJXPFAKESEP", SystemTextEncoding::toUTF8($ajxpNode->getPath()));
$pattern = new Zend_Search_Lucene_Index_Term($testQ . '*', 'node_path');
$query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$hits = $index->find($query);
return $hits;
}
示例8: fuzzyFindTerms
/**
* finds similar terms
* @param string $queryStr
* @param \Zend_Search_Lucene_Interface $index
* @param integer $prefixLength optionally specify prefix length, default 0
* @param float $similarity optionally specify similarity, default 0.5
* @return string[] $similarSearchTerms
*/
public static function fuzzyFindTerms($queryStr, $index, $prefixLength = 0, $similarity = 0.5)
{
if ($index != NULL) {
\Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($prefixLength);
$term = new \Zend_Search_Lucene_Index_Term($queryStr);
$fuzzyQuery = new \Zend_Search_Lucene_Search_Query_Fuzzy($term, $similarity);
$hits = $index->find($fuzzyQuery);
$terms = $fuzzyQuery->getQueryTerms();
return $terms;
}
}
示例9: _executeSearch
/**
* Execute the search and return the results
*
* @param string|Zym_Search_Lucene_IQuery $query
* @return array
*/
protected function _executeSearch($query)
{
return $this->_searchIndex->find((string) $query);
}