com.algolia.search.saas.Query.getFacetFilters()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中com.algolia.search.saas.Query.getFacetFilters方法的一些代码示例,展示了Query.getFacetFilters的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getFacetFilters方法的具体详情如下:
包路径:com.algolia.search.saas.Query
类名称:Query
方法名:getFacetFilters

Query.getFacetFilters介绍

暂无

代码示例

代码示例来源:origin: algolia/algoliasearch-client-android

@Test
public void facetFilters() throws JSONException {
  final JSONArray VALUE = new JSONArray("[[\"category:Book\", \"category:Movie\"], \"author:John Doe\"]");
  Query query = new Query();
  assertNull(query.getFacetFilters());
  query.setFacetFilters(VALUE);
  assertEquals(VALUE, query.getFacetFilters());
  assertEquals("[[\"category:Book\",\"category:Movie\"],\"author:John Doe\"]", query.get("facetFilters"));
  assertEquals(query.getFacetFilters(), Query.parse(query.build()).getFacetFilters());
}

代码示例来源:origin: algolia/instantsearch-android

@SuppressWarnings("deprecation")
// deprecated facetFilters are used on purpose for filters managed programmatically
@Test
public void facetRefinements() {
  final Searcher searcher = initSearcher();
  searcher.addFacetRefinement("attribute", "foo");
  Assert.assertEquals("facetFilters should represent the refinement", "[\"attribute:foo\"]", searcher.getQuery().getFacetFilters().toString());
  Assert.assertTrue("hasFacetRefinement should return true for attribute/foo", searcher.hasFacetRefinement("attribute", "foo"));
  searcher.removeFacetRefinement("attribute", "foo");
  Assert.assertEquals("facetFilters should not contain the refinement after removeFacetRefinement()", "[]", searcher.getQuery().getFacetFilters().toString());
  Assert.assertFalse("hasFacetRefinement should return false for attribute/foo", searcher.hasFacetRefinement("attribute", "foo"));
  searcher.updateFacetRefinement("attribute", "foo", true);
  Assert.assertEquals("facetFilters should represent again the refinement", "[\"attribute:foo\"]", searcher.getQuery().getFacetFilters().toString());
  searcher.updateFacetRefinement("attribute", "foo", false);
  Assert.assertEquals("facetFilters should not contain the refinement after updateFacetRefinement(false)", "[]", searcher.getQuery().getFacetFilters().toString());
  searcher.addFacetRefinement("attribute", "foo");
  searcher.addFacetRefinement("attribute", "bar");
  Assert.assertTrue("facetFilters should contain the first refinement", searcher.getQuery().getFacetFilters().toString().contains("attribute:foo"));
  Assert.assertTrue("facetFilters should contain the second refinement", searcher.getQuery().getFacetFilters().toString().contains("attribute:bar"));
  searcher.removeFacetRefinement("attribute", "foo");
  Assert.assertFalse("facetFilters should not contain the first refinement anymore", searcher.getQuery().getFacetFilters().toString().contains("attribute:foo"));
  Assert.assertTrue("facetFilters should still contain the second refinement", searcher.getQuery().getFacetFilters().toString().contains("attribute:bar"));
  searcher.addFacetRefinement("attribute", "foo");
  searcher.addFacetRefinement("other", "baz");
  searcher.clearFacetRefinements("attribute");
  Assert.assertFalse("facetFilters should have no more refinements on attribute", searcher.getQuery().getFacetFilters().toString().contains("attribute"));
  Assert.assertTrue("facetFilters should still contain the other attribute's refinement", searcher.getQuery().getFacetFilters().toString().contains("other:baz"));
}

相关文章