本文整理汇总了PHP中Zend\Search\Lucene\Lucene::getResultSetLimit方法的典型用法代码示例。如果您正苦于以下问题:PHP Lucene::getResultSetLimit方法的具体用法?PHP Lucene::getResultSetLimit怎么用?PHP Lucene::getResultSetLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Search\Lucene\Lucene
的用法示例。
在下文中一共展示了Lucene::getResultSetLimit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLimitingResult
public function testLimitingResult()
{
$index = Lucene\Lucene::open(dirname(__FILE__) . '/_index23Sample/_files');
$storedResultSetLimit = Lucene\Lucene::getResultSetLimit();
Lucene\Lucene::setResultSetLimit(3);
$hits = $index->find('"reporting bugs"', 'path');
$this->assertEquals(count($hits), 3);
$expectedResultset = array(array(7, 0.212395, 'IndexSource/contributing.bugs.html'), array(0, 0.247795, 'IndexSource/contributing.documentation.html'), array(2, 0.176996, 'IndexSource/contributing.patches.html'));
foreach ($hits as $resId => $hit) {
$this->assertEquals($hit->id, $expectedResultset[$resId][0]);
$this->assertTrue(abs($hit->score - $expectedResultset[$resId][1]) < 1.0E-6);
$this->assertEquals($hit->path, $expectedResultset[$resId][2]);
}
Lucene\Lucene::setResultSetLimit($storedResultSetLimit);
}
示例2: 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\InvalidArgumentException
* @throws \Zend\Search\Lucene\Exception\RuntimeException
*/
public function find($query)
{
if (is_string($query)) {
$query = Search\QueryParser::parse($query);
}
if (!$query instanceof Search\Query\AbstractQuery) {
throw new InvalidArgumentException('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;
$resultSetLimit = Lucene::getResultSetLimit();
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if( $docScore != 0 ) {
$hit = new Search\QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if ($resultSetLimit != 0 && count($hits) >= $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();
for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count];
if (!is_string($fieldName)) {
throw new RuntimeException('Field name must be a string.');
}
if (strtolower($fieldName) == 'score') {
$sortArgs[] = &$scores;
} else {
if (!in_array($fieldName, $fieldNames)) {
throw new RuntimeException('Wrong field name.');
}
//.........这里部分代码省略.........