javascript – React native algolia search with filters query

0
28

[ad_1]

Iam trying to convert an Ionic app to React Native and it has algolia search for some data.

This is the code block of ionic

this.client = algoliasearch(APP_ID, API_KEY);

this.client.initIndex(PROFILES_INDEX)
        .search({
          filters: `(status = ${STATUS.ACTIVE}) AND (role = ${ROLE.BARMAN} OR role = ${ROLE.ADMIN})`,
          attributesToRetrieve: ['fullName', 'uid'],
          hitsPerPage: 1000,
          page: page
        }).then((barmen) => {
        return isDefined(barmen) && isDefined(barmen.hits) && barmen.hits
          ? Resolve({barmen: barmen.hits, page: barmen.page, nbPages: barmen.nbPages}) : Resolve([]);
      }, (err) => {
        Resolve([]);
      });

But this javascript function doesnt work as expected on react native and it doesnt showing hits.

Instead of this i had to use InstantSearch from ‘react-instantsearch-native’ to implement algolia search.

  <InstantSearch 
     searchClient={client}
     indexName={PROFILES_INDEX}>
  <InfiniteHits />
  </InstantSearch>

I was able to get hits like this in a useeffect inside InfiniteHits.js.

import React, { useEffect } from 'react';
import { StyleSheet, Text, View, FlatList } from 'react-native';
import { connectInfiniteHits } from 'react-instantsearch-native'; 

const InfiniteHits = ({ hits, hasMore, refineNext }) => (
    useEffect(() => {
     console.log(hits)
      }, [ hits])
 
);

// [...]

export default connectInfiniteHits(InfiniteHits);

I want to filter the data like in Ionic app but couldnt able to to that.

I want to know how should this can apply to react native code.

  filters: `(status = ${STATUS.ACTIVE}) AND (role = ${ROLE.BARMAN} OR role = ${ROLE.ADMIN})`,
          attributesToRetrieve: ['fullName', 'uid'],
          hitsPerPage: 1000,
          page: page

Documentation doesnt provide information. Please help.

Thank you

[ad_2]