Hello im trying to replicate how you handle faceti...
# community-help
l
Hello im trying to replicate how you handle faceting in https://songs-search.typesense.org/ without using InstantSearch.js. when i click an artist all the previous artists remain. in my case, if i eg. add a facet_by: “category”, and i include the facet results (categories with their corresponding number of results) in a side pane very similar to how you guys in the song search demo, if i click a category, and add it to the filter_by search param, obviously the new facet results are only going to include that single category. i tried exploring facet_query and doing something like facet_query: “category:(*)“, but i found this issue https://github.com/typesense/typesense/issues/590 stating you can only have a single facet query. so i guess im wondering, how does this even work in InstantSearch.js behind the scenes? is the only way to do it with a multiSearch something like:
Copy code
const sharedSearchParams = {
      collection: "items",
      q: searchText === "" ? "*" : searchText,
      query_by: "title,description,embedding",
      exclude_fields: "embedding",
      page: 1,
      per_page: 16,
      rerank_hybrid_matches: true,
      include_fields: "$marketplaces(*)",
      vector_query: "embedding:([], k: 200)",
      facet_by: "category",
    };

    const searchRequests = {
      searches: [
        {
          ...sharedSearchParams,
          filter_by:
            selectedCategories.length > 0
              ? selectedCategories.map((cat) => `category:="${cat}"`).join(" || ")
              : undefined,
        },
        {
          ...sharedSearchParams,
          filter_by: undefined,
        },
      ],
    };

    const multiSearchResults = await typesense.multiSearch.perform(searchRequests);
    const results = multiSearchResults.results[0] as SearchResponse<object>;
    const categoryFacetResults = multiSearchResults.results[1] as SearchResponse<object>;
i dont know if its a concern, or whether it should just be ignored but using this method, if i click to filter by some categories the total count returned by the facet results does not add up to the total “found” in the search results.