/** * Get map represent facets. * * return map of map * <li>primary key is facet name * <li>secondary key is topic name * <li>value is topic * * @return */ public Map<String, Map<String, FacetTopic>> getFacetsAsMap() { if (facetsAsMap == null && facets != null) { // use local variable to prevent multi-thread problem (multiple add) Map<String, Map<String, FacetTopic>> localFacetsAsMap = new HashMap<String, Map<String, FacetTopic>>(); for (Map.Entry<String, List<FacetTopic>> e : getFacets().entrySet()) { Map<String, FacetTopic> topics = new HashMap<String, FacetTopic>(); localFacetsAsMap.put(e.getKey(), topics); for (FacetTopic t : e.getValue()) { topics.put(t.getTopicName(), t); } } facetsAsMap = localFacetsAsMap; } return facetsAsMap; }
@Override public String toString() { String result = getQueryString() + " results " + getAll(); if (!getFacetNames().isEmpty()) { result += "\nfacets " + getFacets(); } return result; }
String queryString = resultWs.getQueryString(); Map<String, List<org.nuiton.wikitty.query.FacetTopic>> facets = resultWs.getFacets();
@Test public void testSearchExtensionFacet() throws Exception { // essai de facettiser sur les extensions WikittyQuery query = new WikittyQueryMaker().keyword("*").end(); query.setOffset(0); query.setLimit(0); query.setFacetField(Element.EXTENSION); WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query); Assert.assertEquals(1, result.getFacetNames().size()); //TODO echatellier 20120112 : revue this code //Assert.assertNotNull(result.getFacets().get(Element.EXTENSION)); // is more convenient, but wont work Assert.assertNotNull(result.getFacets().get(Element.EXTENSION.getValue())); }
@Test public void testSearchExtensionFacetExplicitly() throws Exception { // essai de facettiser sur les extensions WikittyQuery query = new WikittyQueryMaker().keyword("*").end(); query.setOffset(0); query.setLimit(0); query.setFacetExtension(true); WikittyQueryResult<String> result = wikittyClient.findAllByQuery(query); Assert.assertEquals(1, result.getFacetNames().size()); //TODO echatellier 20120112 : revue this code //Assert.assertNotNull(result.getFacets().get(Element.EXTENSION)); // is more convenient, but wont work Assert.assertNotNull(result.getFacets().get(Element.EXTENSION.getValue())); }
Assert.assertEquals(2, result.getFacets().get(WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME).size()); Assert.assertEquals(1, result.getFacets().get(WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME).size()); Assert.assertEquals(2, result.getFacets().get(WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME).get(0).getCount()); Assert.assertEquals(1, result.getFacets().get(WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME).size()); Assert.assertEquals(2, result.getFacets().get(WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME).get(0).getCount());