Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error in searchOptions["facets"] which should also accept string #1432

Open
bidoubiwa opened this issue Dec 13, 2022 · 3 comments
Open

Comments

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Dec 13, 2022

The current type of facets in the searchOptions is:

Nonetheless, while this is true when no facets are checked, once it is facets may contain a string.

Screenshot 2022-12-13 at 17 58 29

Screenshot 2022-12-13 at 17 58 40

@Haroenv
Copy link
Contributor

Haroenv commented Dec 13, 2022

Normally facets gets casted back to an array in all/almost all use cases, which is why it's an array in these types here. Where is it a string for you? it looks like the issue may slightly be incomplete

@bidoubiwa bidoubiwa changed the title Type error in searchOptions["facets"] which should also accept string WIP: Type error in searchOptions["facets"] which should also accept string Dec 13, 2022
@bidoubiwa bidoubiwa changed the title WIP: Type error in searchOptions["facets"] which should also accept string Type error in searchOptions["facets"] which should also accept string Dec 13, 2022
@bidoubiwa
Copy link
Contributor Author

Hey @Haroenv , thanks for the quick reply.

I'm going to check with instantsearch response to see if indeed that's the case when using algoliasearch

@bidoubiwa
Copy link
Contributor Author

bidoubiwa commented Dec 13, 2022

I added a console.log here:

export const multipleQueries = (base: SearchClient) => {
return <TObject>(
queries: readonly MultipleQueriesQuery[],
requestOptions?: RequestOptions & MultipleQueriesOptions
): Readonly<Promise<MultipleQueriesResponse<TObject>>> => {
const requests = queries.map(query => {
return {
...query,
params: serializeQueryParameters(query.params || {}),
};
});
return base.transporter.read(
{
method: MethodEnum.Post,
path: '1/indexes/*/queries',
data: {
requests,
},
cacheable: true,
},
requestOptions
);
};
};

These are my filters:

Screenshot 2022-12-13 at 18 23 54

This is what appears in my console:

[
  {
    "indexName": "movies",
    "params": {
      "facetFilters": [
        [
          "genres:Action"
        ]
      ],
      "facets": [
        "genres"
      ],
      "highlightPostTag": "</ais-highlight-0000000000>",
      "highlightPreTag": "<ais-highlight-0000000000>",
      "maxValuesPerFacet": 10,
      "query": "",
      "tagFilters": ""
    }
  },
  {
    "indexName": "movies",
    "params": {
      "analytics": false,
      "clickAnalytics": false,
      "facets": "genres",
      "highlightPostTag": "</ais-highlight-0000000000>",
      "highlightPreTag": "<ais-highlight-0000000000>",
      "hitsPerPage": 0,
      "maxValuesPerFacet": 10,
      "page": 0,
      "query": ""
    }
  }
]

This is my instantsearch setup:

import algoliasearch from "algoliasearch";
import {
  InstantSearch,
  SearchBox,
  Hits,
  Highlight,
  RefinementList
} from "react-instantsearch-dom";


const searchClient = algoliasearch("x","x");

const Hit = ({ hit }: { hit: Record<string, any> }) => {
  return (
    <div key={hit.id}>

      <div className="hit-name">
        <Highlight attribute="title" hit={hit} />
      </div>
    </div>
  );
};

export default function App() {
  return (
    <InstantSearch searchClient={searchClient} indexName="movies">
      <RefinementList attribute="genres" />
      <SearchBox />
      <Hits hitComponent={Hit} />
    </InstantSearch>
  );
}

and these are my package versions:

    "@types/react-instantsearch-dom": "6.12.3",
    "algoliasearch": "../algoliasearch-client-javascript/packages/algoliasearch", // "version": "4.14.2",
    "algoliasearch-helper": "3.11.1",
    "react-instantsearch-dom": "^6.38.1"

If you like I can also try it out in a vanilla javascript environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants