如何在 algolia 即时搜索中根据类别过滤命中

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

我想根据类别过滤匹配项,例如仅商店或咖啡。

这是我的查询:

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

如何过滤我得到的结果?

看看 Algolia's Filtering Guide,您可以从中了解过滤的工作原理。

使用Android客户端,可以使用setFilters方法:

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

您可以在 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)