typesense-instantsearch-adapter 2.9.0-5 → 2.9.0-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -30
- package/dist/typesense-instantsearch-adapter.js +1 -1
- package/dist/typesense-instantsearch-adapter.js.map +1 -1
- package/dist/typesense-instantsearch-adapter.min.js +1 -1
- package/dist/typesense-instantsearch-adapter.min.js.map +1 -1
- package/lib/SearchRequestAdapter.js +1 -1
- package/lib/SearchRequestAdapter.js.map +1 -1
- package/package.json +1 -1
- package/src/SearchRequestAdapter.js +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ Here is an example of UI you can build with this adapater: [songs-search.typesen
|
|
|
21
21
|
- [With vue-instantsearch](#with-vue-instantsearch)
|
|
22
22
|
- [With angular-instantsearch](#with-angular-instantsearch)
|
|
23
23
|
- [Widget Specific Instructions](#widget-specific-instructions)
|
|
24
|
+
- [Caching](#caching)
|
|
24
25
|
- [Compatibility](#compatibility)
|
|
25
26
|
- [Development](#development)
|
|
26
27
|
- [Help](#help)
|
|
@@ -604,38 +605,70 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
604
605
|
// from https://github.com/typesense/showcase-hn-comments-semantic-search/blob/8a33006cae58b425c53f56a64e1273e808cd9375/src/js/index.js#L101
|
|
605
606
|
const searchClient = typesenseInstantsearchAdapter.searchClient;
|
|
606
607
|
search = instantsearch({
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
.setQueryParameter("typesenseVectorQuery", null)
|
|
632
|
-
.setPage(page)
|
|
633
|
-
.search();
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
});
|
|
608
|
+
searchClient,
|
|
609
|
+
indexName: INDEX_NAME,
|
|
610
|
+
routing: true,
|
|
611
|
+
async searchFunction(helper) {
|
|
612
|
+
// This fetches 200 (nearest neighbor) results for semantic / hybrid search
|
|
613
|
+
|
|
614
|
+
let query = helper.getQuery().query;
|
|
615
|
+
const page = helper.getPage(); // Retrieve the current page
|
|
616
|
+
|
|
617
|
+
if (query !== "" && ["semantic", "hybrid"].includes($("#search-type-select").val())) {
|
|
618
|
+
console.log(helper.getQuery().query);
|
|
619
|
+
helper
|
|
620
|
+
.setQueryParameter(
|
|
621
|
+
"typesenseVectorQuery", // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
|
|
622
|
+
`embedding:([], k:200)`,
|
|
623
|
+
)
|
|
624
|
+
.setPage(page)
|
|
625
|
+
.search();
|
|
626
|
+
console.log(helper.getQuery().query);
|
|
627
|
+
} else {
|
|
628
|
+
helper.setQueryParameter("typesenseVectorQuery", null).setPage(page).search();
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
});
|
|
637
632
|
```
|
|
638
633
|
|
|
634
|
+
## Caching
|
|
635
|
+
|
|
636
|
+
There are two modes of caching:
|
|
637
|
+
|
|
638
|
+
1. **Server-side caching:**
|
|
639
|
+
|
|
640
|
+
To enable server-side caching, add a parameter called `useServerSideSearchCache: true` in the `server` configuration block of the typesense-instantsearch-adapter like this:
|
|
641
|
+
|
|
642
|
+
```javascript
|
|
643
|
+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
644
|
+
server: {
|
|
645
|
+
apiKey: "...",
|
|
646
|
+
nearestNode: {...},
|
|
647
|
+
nodes: [...],
|
|
648
|
+
useServerSideSearchCache: true // <<< Add this to send use_cache as a query parameter instead of post body parameter
|
|
649
|
+
},
|
|
650
|
+
additionalSearchParameters: {...}
|
|
651
|
+
});
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
This will cause the adapter to add `?use_cache=true` as a URL query parameter to all search requests initiated by the adapter, which will then cause Typesense Server to enable server-side caching for these requests.
|
|
655
|
+
|
|
656
|
+
2. **Client-side caching:**
|
|
657
|
+
|
|
658
|
+
The adapter also has client-side caching enabled by default, to prevent unnecessary network calls to the server. The TTL for this client-side cache can be configured like this:
|
|
659
|
+
|
|
660
|
+
```javascript
|
|
661
|
+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
662
|
+
server: {
|
|
663
|
+
apiKey: "...",
|
|
664
|
+
nearestNode: {...},
|
|
665
|
+
nodes: [...],
|
|
666
|
+
cacheSearchResultsForSeconds: 2 * 60 // <<< Add this to configure the TTL for client-side cache in the browser
|
|
667
|
+
},
|
|
668
|
+
additionalSearchParameters: {...}
|
|
669
|
+
});
|
|
670
|
+
```
|
|
671
|
+
|
|
639
672
|
## Compatibility
|
|
640
673
|
|
|
641
674
|
| Typesense Server | typesense-instantsearch-adapter | instantsearch.js | react-instantsearch | vue-instantsearch | angular-instantsearch |
|
|
@@ -632,7 +632,7 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
|
|
|
632
632
|
max_facet_values: params.maxValuesPerFacet,
|
|
633
633
|
page: (params.page || 0) + 1
|
|
634
634
|
});
|
|
635
|
-
if (params.hitsPerPage) {
|
|
635
|
+
if (params.hitsPerPage != null) {
|
|
636
636
|
typesenseSearchParams.per_page = params.hitsPerPage;
|
|
637
637
|
}
|
|
638
638
|
if (params.facetQuery) {
|