typesense-instantsearch-adapter 2.9.0-3 → 2.9.0-4
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 +33 -34
- package/dist/typesense-instantsearch-adapter.js +8639 -6478
- 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/SearchResponseAdapter.js +12 -0
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/SearchResponseAdapter.js +12 -0
package/README.md
CHANGED
|
@@ -582,7 +582,7 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
582
582
|
|
|
583
583
|
The general idea is to first hook into the query life-cycle of Instantsearch, intercept the typed query and send it to an embedding API, fetch the embeddings and then send the vectors to Typesense to do a nearest neighbor vector search.
|
|
584
584
|
|
|
585
|
-
Here's a demo that you can run locally to see this in action: [https://github.com/typesense/
|
|
585
|
+
Here's a demo that you can run locally to see this in action: [https://github.com/typesense/showcase-hn-comments-semantic-search](https://github.com/typesense/showcase-hn-comments-semantic-search).
|
|
586
586
|
|
|
587
587
|
Here's how to do this in Instantsearch.js:
|
|
588
588
|
|
|
@@ -601,39 +601,39 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
601
601
|
},
|
|
602
602
|
additionalSearchParameters,
|
|
603
603
|
});
|
|
604
|
+
// from https://github.com/typesense/showcase-hn-comments-semantic-search/blob/8a33006cae58b425c53f56a64e1273e808cd9375/src/js/index.js#L101
|
|
604
605
|
const searchClient = typesenseInstantsearchAdapter.searchClient;
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
});
|
|
606
|
+
search = instantsearch({
|
|
607
|
+
searchClient,
|
|
608
|
+
indexName: INDEX_NAME,
|
|
609
|
+
routing: true,
|
|
610
|
+
async searchFunction(helper) {
|
|
611
|
+
// This fetches 200 (nearest neighbor) results for semantic / hybrid search
|
|
612
|
+
|
|
613
|
+
let query = helper.getQuery().query;
|
|
614
|
+
const page = helper.getPage(); // Retrieve the current page
|
|
615
|
+
|
|
616
|
+
if (
|
|
617
|
+
query !== "" &&
|
|
618
|
+
["semantic", "hybrid"].includes($("#search-type-select").val())
|
|
619
|
+
) {
|
|
620
|
+
console.log(helper.getQuery().query);
|
|
621
|
+
helper
|
|
622
|
+
.setQueryParameter(
|
|
623
|
+
"typesenseVectorQuery", // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
|
|
624
|
+
`embedding:([], k:200)`,
|
|
625
|
+
)
|
|
626
|
+
.setPage(page)
|
|
627
|
+
.search();
|
|
628
|
+
console.log(helper.getQuery().query);
|
|
629
|
+
} else {
|
|
630
|
+
helper
|
|
631
|
+
.setQueryParameter("typesenseVectorQuery", null)
|
|
632
|
+
.setPage(page)
|
|
633
|
+
.search();
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
637
|
```
|
|
638
638
|
|
|
639
639
|
## Compatibility
|
|
@@ -657,7 +657,6 @@ If a particular version of the above libraries don't work with the adapter, plea
|
|
|
657
657
|
|
|
658
658
|
This adapter works with all widgets in [this list](https://www.algolia.com/doc/api-reference/widgets/js/), _except_ for the following:
|
|
659
659
|
|
|
660
|
-
- `queryRuleCustomData`
|
|
661
660
|
- `queryRuleContext`
|
|
662
661
|
|
|
663
662
|
## Development
|