微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

InstantSearch.js 自定义小部件增加返回结果

如何解决InstantSearch.js 自定义小部件增加返回结果

正如您在下面的代码中看到的,我制作了 2 个自定义小部件,一个用于搜索一个用于显示结果,但我无法增加返回结果的限制。当页面加载时,它会自动发出请求并检索认结果,无需查询

我们有超过 500 多个结果,所有结果都必须显示在 UI 上,我无法在任何地方修改结果的限制。限制始终为 200。作为后端,我没有使用 algolia 而是使用 meilisearch,但这不会以任何方式影响这一点。

正如您在图片中看到的,searchParamters 被修改并设置为限制为 1000,但是当发出请求时,它发送为 200。

enter image description here

enter image description here

       const search = instantsearch({
            indexName: "store",searchClient: instantMeiliSearch(m_host,m_key),});

       search.addWidgets([
        configure({
            hitsPerPage: 1000,limit: 1000,filters: `image!=null AND is_active=1 AND (countries_ids=${country_id} OR countries_ids=0) AND goto_link != null`,attributesToHighlight: [],paginationLimitedTo: 1000,}),{
            init: function (opts) {
                const helper = opts.helper;

                const input = document.querySelector('#searchBox');
                input.addEventListener('input',function (e) {
                    helper.setQuery(e.currentTarget.value) // update the parameters
                        .search(); // launch the query
                });
            }
        },{
            render: function (opts) {
                let results = opts.results;
                // read the hits from the results and transform them into HTML.
                let res = toArray(groupBy(filter_stores(results.hits),'category_id'));
                $(`.stores-list`).empty()
                $(`.categories-list`).hide()
                res = res.map(it => {
                    let copy = it;
                    copy[1] = _.orderBy(it[1].map(store => {
                        store.default_rank = store.hasOwnProperty(`rank_country_${country_id}`) ? store[`rank_country_${country_id}`] : store.default_rank;
                        return store;
                    }),'default_rank','asc');
                    return copy;
                });
                res.map(pairs => {
                    let [category_id,stores] = pairs;
                    $(`#category_${category_id}`).show()
                    let html = stores.map(h => create_store(h)).join('')
                    $(`#store_list_${category_id}`).html(html)
                });
            },}
    ]);

    search.start();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?