如何使用PHP增加Algolia的命中?

发布于 2025-02-08 10:52:48 字数 939 浏览 0 评论 0原文

如何使用阿尔戈利亚获得更多的1000结果。此功能仅返回1000个结果。我使用$ CurrentPage ++增加了页码。但是在返回1000个结果后,当阿尔戈利亚有9000多个记录时,将显示0个结果。我已经用PHP编写了此代码,找不到可能的解决方案。

function getAlgoliaResults($index, $query, $userid, $ipaddress)
{
    global $ObjectidsArray;
    $currentpage = 0;
    $objects = null;
    $idarray = array();

    do {
        
        $objects = $index->search($query, [
            'hitsPerPage' => 1000,
            'page' => $currentpage,
            'offset' => 0,
            'length' => 1000,
            'X-Forwarded-For' => $ipaddress,
            'userToken' => $userid
        ]);

        foreach ($objects['hits'] as $rec) {
            $ObjectidsArray[$rec['id']] = $rec['objectID'];
            array_push($idarray, $rec['id']);
        }

        if (count($objects['hits']) <= 1000){

        $currentpage++;

        }
    } while (count($objects['hits']) > 0);

    return $idarray;
}

How can I get more then 1000 result using algolia. This function is only returning 1000 results. I have increase the page number using $currentpage++. But after returning 1000 results it is showing 0 result when there is 9000+ records in Algolia. I have written this code in php and couldn't find the possible solutions.

function getAlgoliaResults($index, $query, $userid, $ipaddress)
{
    global $ObjectidsArray;
    $currentpage = 0;
    $objects = null;
    $idarray = array();

    do {
        
        $objects = $index->search($query, [
            'hitsPerPage' => 1000,
            'page' => $currentpage,
            'offset' => 0,
            'length' => 1000,
            'X-Forwarded-For' => $ipaddress,
            'userToken' => $userid
        ]);

        foreach ($objects['hits'] as $rec) {
            $ObjectidsArray[$rec['id']] = $rec['objectID'];
            array_push($idarray, $rec['id']);
        }

        if (count($objects['hits']) <= 1000){

        $currentpage++;

        }
    } while (count($objects['hits']) > 0);

    return $idarray;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文