本文整理汇总了PHP中Zend_Search_Lucene_Search_QueryHit类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_QueryHit类的具体用法?PHP Zend_Search_Lucene_Search_QueryHit怎么用?PHP Zend_Search_Lucene_Search_QueryHit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Search_Lucene_Search_QueryHit类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDocument
/**
* Return the associated index document
*
* @return \Tollwerk\TwLucenesearch\Domain\Model\Document Associated index document
* @see \Zend_Search_Lucene_Search_QueryHit::getDocument()
*/
public function getDocument()
{
if (!$this->_document instanceof \Tollwerk\TwLucenesearch\Domain\Model\Document) {
$this->_document = \Tollwerk\TwLucenesearch\Domain\Model\Document::cast(parent::getDocument());
}
return $this->_document;
}
示例2: find
public function find($query)
{
if (is_string($query)) {
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
}
$this->commit();
$hits = array();
$scores = array();
$ids = array();
$query = $query->rewrite($this)->optimize($this);
$query->execute($this);
$topScore = 0;
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if ($docScore != 0) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
break;
}
}
if (count($hits) == 0) {
// skip sorting, which may cause a error on empty index
return array();
}
if ($topScore > 1) {
foreach ($hits as $hit) {
$hit->score /= $topScore;
}
}
if (func_num_args() == 1) {
// sort by scores
array_multisort($scores, SORT_DESC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC, $hits);
} else {
// sort by given field names
$argList = func_get_args();
$fieldNames = $this->getFieldNames();
$sortArgs = array();
require_once 'Zend/Search/Lucene/Exception.php';
for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count];
if (!is_string($fieldName)) {
throw new Zend_Search_Lucene_Exception('Field name must be a string.');
}
if (!in_array($fieldName, $fieldNames)) {
throw new Zend_Search_Lucene_Exception('Wrong field name.');
}
$valuesArray = array();
foreach ($hits as $hit) {
try {
$value = $hit->getDocument()->getFieldValue($fieldName);
} catch (Zend_Search_Lucene_Exception $e) {
if (strpos($e->getMessage(), 'not found') === false) {
throw $e;
} else {
$value = null;
}
}
$valuesArray[] = $value;
}
$sortArgs[] = $valuesArray;
if ($count + 1 < count($argList) && is_integer($argList[$count + 1])) {
$count++;
$sortArgs[] = $argList[$count];
if ($count + 1 < count($argList) && is_integer($argList[$count + 1])) {
$count++;
$sortArgs[] = $argList[$count];
} else {
if ($argList[$count] == SORT_ASC || $argList[$count] == SORT_DESC) {
$sortArgs[] = SORT_REGULAR;
} else {
$sortArgs[] = SORT_ASC;
}
}
} else {
$sortArgs[] = SORT_ASC;
$sortArgs[] = SORT_REGULAR;
}
}
// Sort by id's if values are equal
$sortArgs[] = $ids;
$sortArgs[] = SORT_ASC;
$sortArgs[] = SORT_NUMERIC;
// Array to be sorted
$sortArgs[] =& $hits;
// Do sort
call_user_func_array('array_multisort', $sortArgs);
}
//.........这里部分代码省略.........
示例3: 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 Zend_Search_Lucene_Search_QueryParser|string $query
* @return array Zend_Search_Lucene_Search_QueryHit
* @throws Zend_Search_Lucene_Exception
*/
public function find($query)
{
if (is_string($query)) {
// require_once 'Zend/Search/Lucene/Search/QueryParser.php';
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
// require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
}
$this->commit();
$hits = array();
$scores = array();
$ids = array();
$query = $query->rewrite($this)->optimize($this);
$query->execute($this);
$topScore = 0;
/** Zend_Search_Lucene_Search_QueryHit */
// require_once 'Zend/Search/Lucene/Search/QueryHit.php';
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if ($docScore != 0) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
break;
}
}
if (count($hits) == 0) {
// skip sorting, which may cause a error on empty index
return array();
}
if ($topScore > 1) {
foreach ($hits as $hit) {
$hit->score /= $topScore;
}
}
if (func_num_args() == 1) {
// sort by scores
array_multisort($scores, SORT_DESC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC, $hits);
} else {
// sort by given field names
$argList = func_get_args();
$fieldNames = $this->getFieldNames();
$sortArgs = array();
// PHP 5.3 now expects all arguments to array_multisort be passed by
// reference (if it's invoked through call_user_func_array());
// since constants can't be passed by reference, create some placeholder variables.
$sortReg = SORT_REGULAR;
$sortAsc = SORT_ASC;
$sortNum = SORT_NUMERIC;
$sortFieldValues = array();
// require_once 'Zend/Search/Lucene/Exception.php';
for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count];
if (!is_string($fieldName)) {
throw new Zend_Search_Lucene_Exception('Field name must be a string.');
}
if (strtolower($fieldName) == 'score') {
$sortArgs[] =& $scores;
} else {
if (!in_array($fieldName, $fieldNames)) {
throw new Zend_Search_Lucene_Exception('Wrong field name.');
}
if (!isset($sortFieldValues[$fieldName])) {
$valuesArray = array();
foreach ($hits as $hit) {
try {
$value = $hit->getDocument()->getFieldValue($fieldName);
} catch (Zend_Search_Lucene_Exception $e) {
if (strpos($e->getMessage(), 'not found') === false) {
throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
} else {
$value = null;
}
}
$valuesArray[] = $value;
}
// Collect loaded values in $sortFieldValues
// Required for PHP 5.3 which translates references into values when source
// variable is destroyed
$sortFieldValues[$fieldName] = $valuesArray;
}
//.........这里部分代码省略.........
示例4: getHitProperties
/**
* Get twig properties for matching search document.
*
* @param Zend_Search_Lucene_Search_QueryHit $hit
* @return array
*/
public function getHitProperties(Zend_Search_Lucene_Search_QueryHit $hit)
{
$r = $this->getRequest();
$snippet = Curry_String::toInternalEncoding($hit->body, 'utf-8');
$snippet = self::createSearchSnippet($snippet, $r->get['query'], $this->snippetLength);
$relatedObject = null;
$model = Curry_String::toInternalEncoding($hit->model, 'utf-8');
$fields = array();
foreach ($hit->getDocument()->getFieldNames() as $fieldName) {
$fields[$fieldName] = $hit->{$fieldName};
}
return array('Title' => Curry_String::toInternalEncoding($hit->title, 'utf-8'), 'Description' => Curry_String::toInternalEncoding($hit->description, 'utf-8'), 'Url' => Curry_String::toInternalEncoding($hit->url, 'utf-8'), 'Snippet' => $snippet, 'Score' => $hit->score, 'Fields' => $fields, 'RelatedObject' => new Curry_OnDemand(array($this, 'getRelatedObject'), $model, unserialize($hit->model_id)));
}
示例5: find
public function find($query)
{
if (is_string($query)) {
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
}
$this->commit();
$hits = array();
$scores = array();
$ids = array();
$query = $query->rewrite($this)->optimize($this);
$query->execute($this);
$topScore = 0;
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if ($docScore != 0) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
break;
}
}
if (count($hits) == 0) {
return array();
}
if ($topScore > 1) {
foreach ($hits as $hit) {
$hit->score /= $topScore;
}
}
if (func_num_args() == 1) {
array_multisort($scores, SORT_DESC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC, $hits);
} else {
$argList = func_get_args();
$fieldNames = $this->getFieldNames();
$sortArgs = array();
$sortReg = SORT_REGULAR;
$sortAsc = SORT_ASC;
$sortNum = SORT_NUMERIC;
$sortFieldValues = array();
for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count];
if (!is_string($fieldName)) {
throw new Zend_Search_Lucene_Exception('Field name must be a string.');
}
if (strtolower($fieldName) == 'score') {
$sortArgs[] =& $scores;
} else {
if (!in_array($fieldName, $fieldNames)) {
throw new Zend_Search_Lucene_Exception('Wrong field name.');
}
if (!isset($sortFieldValues[$fieldName])) {
$valuesArray = array();
foreach ($hits as $hit) {
try {
$value = $hit->getDocument()->getFieldValue($fieldName);
} catch (Zend_Search_Lucene_Exception $e) {
if (strpos($e->getMessage(), 'not found') === false) {
throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
} else {
$value = null;
}
}
$valuesArray[] = $value;
}
$sortFieldValues[$fieldName] = $valuesArray;
}
$sortArgs[] =& $sortFieldValues[$fieldName];
}
if ($count + 1 < count($argList) && is_integer($argList[$count + 1])) {
$count++;
$sortArgs[] =& $argList[$count];
if ($count + 1 < count($argList) && is_integer($argList[$count + 1])) {
$count++;
$sortArgs[] =& $argList[$count];
} else {
if ($argList[$count] == SORT_ASC || $argList[$count] == SORT_DESC) {
$sortArgs[] =& $sortReg;
} else {
$sortArgs[] =& $sortAsc;
}
}
} else {
$sortArgs[] =& $sortAsc;
$sortArgs[] =& $sortReg;
}
}
$sortArgs[] =& $ids;
$sortArgs[] =& $sortAsc;
$sortArgs[] =& $sortNum;
//.........这里部分代码省略.........
示例6: getHitProperties
/**
* Get twig properties for matching search document.
*
* @param \Zend_Search_Lucene_Search_QueryHit $hit
* @return array
*/
public function getHitProperties(\Zend_Search_Lucene_Search_QueryHit $hit)
{
$r = $this->app->request;
$snippet = self::createSearchSnippet($hit->body, $r->query->get('query'), $this->snippetLength);
$fields = array();
foreach ($hit->getDocument()->getFieldNames() as $fieldName) {
$fields[$fieldName] = $hit->{$fieldName};
}
return array('Title' => $hit->title, 'Description' => $hit->description, 'Url' => $hit->url, 'Snippet' => $snippet, 'Score' => $hit->score, 'Fields' => $fields, 'RelatedObject' => new OnDemand(array($this, 'getRelatedObject'), $hit->model, unserialize($hit->model_id)));
}