SEARCH-121: Facet fields need to return a List in the search context

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130683 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-15 11:15:20 +00:00
parent 08eb4aa4dc
commit f1b0d77105
4 changed files with 13 additions and 11 deletions

View File

@@ -35,9 +35,9 @@ public class SearchContext
private final Consistency consistency; private final Consistency consistency;
private final List<FacetQueryContext> facetQueries; private final List<FacetQueryContext> facetQueries;
private final SpellCheckContext spellCheck; private final SpellCheckContext spellCheck;
private final FacetFieldContext facetsFields; private final List<FacetFieldContext> facetsFields;
public SearchContext(long lastTxId, List<FacetQueryContext> facetQueries, FacetFieldContext facetsFields, SpellCheckContext spellCheck) public SearchContext(long lastTxId, List<FacetQueryContext> facetQueries, List<FacetFieldContext> facetsFields, SpellCheckContext spellCheck)
{ {
this.spellCheck = spellCheck; this.spellCheck = spellCheck;
if (lastTxId > 0) if (lastTxId > 0)
@@ -67,7 +67,7 @@ public class SearchContext
return spellCheck; return spellCheck;
} }
public FacetFieldContext getFacetsFields() public List<FacetFieldContext> getFacetsFields()
{ {
return facetsFields; return facetsFields;
} }

View File

@@ -141,7 +141,7 @@ public class ResultMapper
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries(); Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
List<FacetQueryContext> facetResults = null; List<FacetQueryContext> facetResults = null;
SpellCheckContext spellCheckContext = null; SpellCheckContext spellCheckContext = null;
FacetFieldContext ffc = null; List<FacetFieldContext> ffcs = null;
//Facet queries //Facet queries
if(facetQueries!= null && !facetQueries.isEmpty()) if(facetQueries!= null && !facetQueries.isEmpty())
@@ -157,6 +157,7 @@ public class ResultMapper
Map<String, List<Pair<String, Integer>>> facetFields = solrResultSet.getFieldFacets(); Map<String, List<Pair<String, Integer>>> facetFields = solrResultSet.getFieldFacets();
if (facetFields != null && !facetFields.isEmpty()) if (facetFields != null && !facetFields.isEmpty())
{ {
ffcs = new ArrayList<>(facetFields.size());
for (Entry<String, List<Pair<String, Integer>>> facet:facetFields.entrySet()) for (Entry<String, List<Pair<String, Integer>>> facet:facetFields.entrySet())
{ {
if (facet.getValue() != null && !facet.getValue().isEmpty()) if (facet.getValue() != null && !facet.getValue().isEmpty())
@@ -166,7 +167,7 @@ public class ResultMapper
{ {
buckets.add(new Bucket(buck.getFirst(), buck.getSecond())); buckets.add(new Bucket(buck.getFirst(), buck.getSecond()));
} }
ffc = new FacetFieldContext(facet.getKey(), buckets); ffcs.add(new FacetFieldContext(facet.getKey(), buckets));
} }
} }
} }
@@ -179,7 +180,7 @@ public class ResultMapper
} }
//Put it all together //Put it all together
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults, ffc, spellCheckContext); context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults, ffcs, spellCheckContext);
return isNullContext(context)?null:context; return isNullContext(context)?null:context;
} }

View File

@@ -146,8 +146,9 @@ public class ResultMapperTests
assertEquals("searchInsteadFor",searchContext.getSpellCheck().getType()); assertEquals("searchInsteadFor",searchContext.getSpellCheck().getType());
assertEquals(1,searchContext.getSpellCheck().getSuggestions().size()); assertEquals(1,searchContext.getSpellCheck().getSuggestions().size());
assertEquals("alfresco",searchContext.getSpellCheck().getSuggestions().get(0)); assertEquals("alfresco",searchContext.getSpellCheck().getSuggestions().get(0));
assertEquals("content.size",searchContext.getFacetsFields().getLabel()); assertEquals(1, searchContext.getFacetsFields().size());
assertEquals(5,searchContext.getFacetsFields().getBuckets().size()); assertEquals("content.size",searchContext.getFacetsFields().get(0).getLabel());
assertEquals(5,searchContext.getFacetsFields().get(0).getBuckets().size());
} }
@Test @Test
@@ -157,7 +158,7 @@ public class ResultMapperTests
assertFalse(mapper.isNullContext(new SearchContext(1l,null,null,null))); assertFalse(mapper.isNullContext(new SearchContext(1l,null,null,null)));
assertFalse(mapper.isNullContext(new SearchContext(0l,null,null,new SpellCheckContext(null, null)))); assertFalse(mapper.isNullContext(new SearchContext(0l,null,null,new SpellCheckContext(null, null))));
assertFalse(mapper.isNullContext(new SearchContext(0l,Arrays.asList(new FacetQueryContext(null, 0)),null,null))); assertFalse(mapper.isNullContext(new SearchContext(0l,Arrays.asList(new FacetQueryContext(null, 0)),null,null)));
assertFalse(mapper.isNullContext(new SearchContext(0l,null,new FacetFieldContext(null, null),null))); assertFalse(mapper.isNullContext(new SearchContext(0l,null,Arrays.asList(new FacetFieldContext(null, null)),null)));
} }
private ResultSet mockResultset(List<Long> archivedNodes) throws JSONException private ResultSet mockResultset(List<Long> archivedNodes) throws JSONException

View File

@@ -118,7 +118,7 @@ public class SearchQuerySerializerTests
FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", 23), new Bucket("b2", 34))); FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", 23), new Bucket("b2", 34)));
SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryContext("f1", 15), new FacetQueryContext("f2", 20)), SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryContext("f1", 15), new FacetQueryContext("f2", 20)),
ffc, Arrays.asList(ffc),
new SpellCheckContext("aFlag", Arrays.asList("bish", "bash"))); new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")));
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext); CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
String out = helper.writeResponse(coll); String out = helper.writeResponse(coll);
@@ -127,7 +127,7 @@ public class SearchQuerySerializerTests
assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"count\":15}")); assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"count\":15}"));
assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}")); assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}")); assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":{\"label\":\"theLabel\",\"buckets\"")); assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"count\":23}")); assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"count\":23}"));
assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34}")); assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34}"));