SolrDocumentQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrDocumentQueryFactory { @Override public SolrQuery createDocumentQuery(QueryFacetsSelection selection, int first, int count) { final SolrQuery query = getDefaultDocumentQuery(); query.addFilterQuery(COLLAPSE_FIELD_QUERY); addQueryFacetParameters(query, selection); query.setStart(first); query.setRows(count); return query; } SolrDocumentQueryFactoryImpl(Collection<String> documentFields, FieldNameService fieldNameService); @Override SolrQuery createDocumentQuery(QueryFacetsSelection selection, int first, int count); @Override SolrQuery createExpandedDocumentQuery(QueryFacetsSelection selection, int first, int count); @Override SolrQuery createDocumentQueryWithExpansion(QueryFacetsSelection selection, int first, int count); @Override SolrQuery createDocumentQuery(String docId); @Override SolrQuery createDuplicateDocumentsQuery(String docId, String collapseField, String collapseValue, QueryFacetsSelection selection, int offset, int expansionLimit); @Override SolrQuery createSimilarDocumentsQuery(String docId);  }
@Test public void testCreateDocumentQueryForSelection() { final Map<String, FacetSelection> selectionMap = Collections.<String, FacetSelection>singletonMap("field1", new FacetSelection(FacetSelectionType.AND, Collections.singleton("value 1"))); final QueryFacetsSelection selection = new QueryFacetsSelection("query", selectionMap); final int first = 100; final int count = 15; final SolrQuery query = instance.createDocumentQuery(selection, first, count); assertEquals(Integer.valueOf(100), query.getStart()); assertEquals(Integer.valueOf(15), query.getRows()); final String[] filterQueries = query.getFilterQueries(); assertEquals(2, filterQueries.length); assertThat(filterQueries, Matchers.hasItemInArray("field1:\"value\\ 1\"")); final String fields = query.getFields(); assertTrue(fields.contains("field1")); assertTrue(fields.contains("field2")); assertTrue(fields.contains("field3")); assertEquals("query", query.getQuery()); }
@Test public void testCreateDocumentQueryForDocId() { final SolrQuery query = instance.createDocumentQuery("document\"Id"); final String[] filterQueries = query.getFilterQueries(); assertEquals(1, filterQueries.length); assertThat(filterQueries, Matchers.hasItemInArray("id:\"document\\\"Id\" OR _selfLink:\"document\\\"Id\"")); final String fields = query.getFields(); assertTrue(fields.contains("field1")); assertTrue(fields.contains("field2")); assertTrue(fields.contains("field3")); }