nuxt-modules / algolia

🔎 Algolia module for Nuxt
https://algolia.nuxtjs.org/
MIT License
185 stars 32 forks source link

How to add facet display? #184

Closed IskandarAlex2 closed 9 months ago

IskandarAlex2 commented 9 months ago

I am trying to make a blog instantsearch page where you can use the search bar to search by title or use facet (Filter) by tags. However, I could not find any facet being mentioned on the documentation page and my VSCode is not helpful because IntelliSense kept saying it could not resolve the module while Nuxt runs perfectly fine with no errors. image

Baroshem commented 9 months ago

Hey Buddy,

I think you have two cases/questions:

  1. Using facets -> Have you tried https://algolia.nuxtjs.org/getting-started/usage#usealgoliafacetedsearch?
  2. The error is related to the fact that Vue Instantsearch library provides both cjs and es imports and in order to make it work, I had to import it this way. This is strange but I cannot make it work any other way.

Hope that I helped :)

IskandarAlex2 commented 9 months ago

Oh I guess that slipped from my eyes, I'll try that then I will tell how it goes. And secondly, there's really no way to make vscode recognize the import as valid? It annoys me a bit

IskandarAlex2 commented 9 months ago

@Baroshem so I decided to use useAlgoliaSearch because the useAlgoliaFacetedSearch is only for getting the Facets. However, I am having trouble applying the Facet filter as the Algolia official documentation shows, it still lists other object that does not have specified facet

const { result, search } = useAlgoliaSearch("PUBLIC_BLOGS_REGISTRY");

let hits: any[];

onBeforeMount(async () => {
    await search({ query: "", facetFilters: [["tags:happy"]] });
    hits = result.value.hits;
    console.table(result.value.hits);
})
Baroshem commented 9 months ago

Regarding first question. I dont think there is. Unless maybe there is some tsconfig that I am not aware off.

Regarding second. Have you tried using request options of search method as explained here https://algolia.nuxtjs.org/getting-started/usage/#usealgoliasearch

IskandarAlex2 commented 9 months ago

so after some messing around trying to find a solution, I finally understand how it works so now it works. Just gonna close this with my code so other people won't be as confused as me

const { result, search } = useAlgoliaSearch("INDEX_NAME");
await search({ query: input_string, requestOptions: {facetFilters: ["tags:happy"]} });
console.table(result.value.hits);
JMKelley commented 4 months ago

This really needs to be added to the docs somewhere. Took me a while to hunt this down.

Baroshem commented 4 months ago

@JMKelley added in 42ba62813d35f2b3583fb77c964e181f05523eb3 :)