Changeset 4628
- Timestamp:
- 03/06/14 10:58:13 (11 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/SolrDocumentQueryFactory.java
r4566 r4628 15 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 18 17 package eu.clarin.cmdi.vlo.service; 19 18 19 import eu.clarin.cmdi.vlo.FacetConstants; 20 20 import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; 21 21 import org.apache.solr.client.solrj.SolrQuery; … … 27 27 public interface SolrDocumentQueryFactory { 28 28 29 /** 30 * Creates a query to retrieve all document that match a query/facet 31 * selection with an offset and limit 32 * 33 * @param selection selection criteria 34 * @param first search result offset 35 * @param count limits the number of results 36 * @return a query set up to retrieve the matching documents, starting with 37 * the specified starting index and limited to the specified count 38 */ 29 39 SolrQuery createDocumentQuery(QueryFacetsSelection selection, int first, int count); 30 40 41 /** 42 * Creates a query to retrieve a single document by id 43 * 44 * @param docId identifier of document to retrieve 45 * @return a query set up to retrieve one row at most with the document that 46 * has the specified identifier 47 * @see FacetConstants#FIELD_ID 48 */ 49 SolrQuery createDocumentQuery(String docId); 50 31 51 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/AbstractSolrQueryFactory.java
r4566 r4628 31 31 public abstract class AbstractSolrQueryFactory { 32 32 33 pr ivatestatic final String SOLR_SEARCH_ALL = "*:*";33 protected static final String SOLR_SEARCH_ALL = "*:*"; 34 34 35 protected void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections) {35 protected final void addQueryFacetParameters(final SolrQuery query, QueryFacetsSelection queryFacetsSelections) { 36 36 final String queryString = queryFacetsSelections.getQuery(); 37 37 if (queryString == null) { … … 48 48 if (values != null) { 49 49 for (String value : values) { 50 encodedQueries.add( String.format("%s:%s", facetName, ClientUtils.escapeQueryChars(value)));50 encodedQueries.add(createFilterQuery(facetName, value)); 51 51 } 52 52 } … … 56 56 } 57 57 58 protected final String createFilterQuery(String facetName, String value) { 59 return String.format("%s:%s", facetName, ClientUtils.escapeQueryChars(value)); 60 } 61 58 62 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/SolrDocumentQueryFactoryImpl.java
r4566 r4628 15 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 18 17 package eu.clarin.cmdi.vlo.service.impl; 19 18 … … 27 26 * @author twagoo 28 27 */ 29 public class SolrDocumentQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrDocumentQueryFactory {28 public class SolrDocumentQueryFactoryImpl extends AbstractSolrQueryFactory implements SolrDocumentQueryFactory { 30 29 31 30 @Override … … 38 37 } 39 38 39 @Override 40 public SolrQuery createDocumentQuery(String docId) { 41 final SolrQuery query = getDefaultDocumentQuery(); 42 query.setQuery(SOLR_SEARCH_ALL); 43 query.addFilterQuery(createFilterQuery(FacetConstants.FIELD_ID, docId)); 44 query.setRows(1); 45 return query; 46 47 } 48 40 49 private SolrQuery getDefaultDocumentQuery() { 41 50 SolrQuery query = new SolrQuery(); -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/SolrDocumentServiceImpl.java
r4626 r4628 24 24 import org.apache.solr.client.solrj.SolrQuery; 25 25 import org.apache.solr.common.SolrDocument; 26 import org.apache.solr.common.SolrDocumentList; 27 import org.slf4j.Logger; 28 import org.slf4j.LoggerFactory; 26 29 27 30 /** … … 31 34 public class SolrDocumentServiceImpl implements SolrDocumentService { 32 35 36 private final static Logger logger = LoggerFactory.getLogger(SolrDocumentServiceImpl.class); 33 37 private final SearchResultsDao searchResultsDao; 34 38 private final SolrDocumentQueryFactory queryFatory; … … 41 45 @Override 42 46 public SolrDocument getDocument(String docId) { 43 throw new UnsupportedOperationException("Not supported yet."); 47 final SolrQuery query = queryFatory.createDocumentQuery(docId); 48 final SolrDocumentList result = searchResultsDao.getDocuments(query); 49 if (result.size() < 1) { 50 return null; 51 } else { 52 logger.debug("Document with docId {} retrieved:", result); 53 return result.get(0); 54 } 44 55 } 45 56 46 57 @Override 47 58 public List<SolrDocument> getDocuments(QueryFacetsSelection selection, int first, int count) { 48 SolrQuery query = queryFatory.createDocumentQuery(selection,first, count);59 final SolrQuery query = queryFatory.createDocumentQuery(selection, first, count); 49 60 return searchResultsDao.getDocuments(query); 50 61 } … … 52 63 @Override 53 64 public long getDocumentCount(QueryFacetsSelection selection) { 54 SolrQuery query = queryFatory.createDocumentQuery(selection,0,0);65 final SolrQuery query = queryFatory.createDocumentQuery(selection, 0, 0); 55 66 return searchResultsDao.getDocuments(query).getNumFound(); 56 67 }
Note: See TracChangeset
for help on using the changeset viewer.