typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
361 stars 62 forks source link

limit_hits doesn't work #181

Open justin5267 opened 10 months ago

justin5267 commented 10 months ago

Description

I've configured the limit_hits, but it doesn't work,still returning all hits.

Steps to reproduce

I'm using instantsearch.js, and all other parameters are functioning correctly.

Expected Behavior

rutrun limited hits

Actual Behavior

return all the hits

Metadata

Typesense Version:0.25 typesense-instantsearch-adapter Version:2.7.1

const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({ server: { apiKey: "XXX", nodes: [ { host: "XXX", port: "443", protocol: "https", }, ], cacheSearchResultsForSeconds: 2 * 60, },

additionalSearchParameters: {
    num_typos: 0,
    drop_tokens_threshold: 0,
    typo_tokens_threshold: 0,
    per_page: 50,
    limit_hits:200,
    highlight_affix_num_tokens: 30,
    query_by: "content",
    facet_by: "XXX",
    sort_by: "XX"
},

});

jasonbosco commented 10 months ago

Could you open the browser's network tab, then do an action that triggers the search, then open that request in the network tab, copy both the request parameters and the response from Typesense and paste it here?

justin5267 commented 10 months ago

Thanks a lot,the request parameters and the response are as follows:

jasonbosco commented 10 months ago

Ah, I think there might be a misunderstanding about what limit_hits does... It's meant to control the total number of hits that can be retrieved via pagination. So for eg, since you've set limit_hits to 2000, even though 2758 results were found, if you try to fetch the 2001th record via pagination, Typesense will throw an error.

So limit_hits is meant mainly for protecting against someone scraping all results in your dataset. This is also why you'd want to use limit_hits embedded inside a Scoped Search API key, so it cannot be modified by a malicious actor on the client side.

justin5267 commented 10 months ago

Great, it really works, I misunderstood it.