gpt4 book ai didi

php - 你如何使用日光浴室在 solr 中分页?

转载 作者:行者123 更新时间:2023-12-04 00:42:24 25 4
gpt4 key购买 nike

我正在使用 solrium,一个 PHP Solr cilent,用于将 Solr 与 PHP 结合使用,我能够使用诸如选择等查询。当我使用 select 时,我只得到 10 个结果,这些结果在 Solr 的默认配置中被设置为 10,如何在结果中使用分页获得所有结果?

这是代码

<?php



require('/var/www/lg/vendor/solarium/solarium/examples/init.php');

htmlHeader();

// create a client instance
$client = new Solarium\Client($config);


// get a select query instance
$query = $client->createQuery($client::QUERY_SELECT);




// this executes the query and returns the result
$resultset = $client->execute($query);


// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();

// show documents using the resultset iterator
foreach ($resultset as $document) {


$query->setStart(2)->setRows(10);

//$query->setStart(21)->setRows(30);
echo '<hr/><table>';

// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);

echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}

echo '</table>';
}

//new PageRequest(0, 10)

htmlFooter();





?>

最佳答案

你可以这样做:$query->setStart(2)->setRows(20) 看看这个例子:http://wiki.solarium-project.org/index.php/V3:Usage_modes

这里还有一些关于您可以提供的选项的信息:​​http://wiki.solarium-project.org/index.php/V2:Building_a_select_query

关于php - 你如何使用日光浴室在 solr 中分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17501630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com