Thofiq Ahmed
Thofiq Ahmed

Reputation: 205

How can I filter the hits based on their category in algolia instant search

I'd like to filter the hits based on their category, like only shop or coffee.

This is my query:

  searcher.setQuery(new Query().setGetRankingInfo(true).setAroundLatLng(new AbstractQuery.LatLng(12.670913552202967, 78.6066235229373)).setAroundRadius(1000));

How can I filter the results I'm getting?

Upvotes: 1

Views: 687

Answers (1)

Guy Daher
Guy Daher

Reputation: 5601

Have a look at Algolia's Filtering Guide, where you can learn how filtering works.

With the Android client, you can use the setFilters method:

Query query = new Query("foo");
query.setFilters("category:coffee"); 

You can find more information in the client's documentation:

/**
 * Filter the query with numeric, facet or/and tag filters.
 * <p>
 * The syntax is a SQL like syntax, you can use the OR and AND keywords. The syntax for the underlying numeric, facet and tag filters is the same than in the other filters:
 * {@code available=1 AND (category:Book OR NOT category:Ebook) AND _tags:public date: 1441745506 TO 1441755506 AND inStock > 0 AND author:"John Doe"}
 *
 * @param filters a string following the given syntax.
 * @return the {@link Query} for chaining.
 */
public @NonNull Query setFilters(String filters)

Upvotes: 1

Related Questions