Changeset 4182
- Timestamp:
- 12/12/13 14:38:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/dao/SolrDao.java
r2768 r4182 3 3 import eu.clarin.cmdi.vlo.config.VloConfig; 4 4 import java.net.MalformedURLException; 5 import java.util.Arrays; 6 import java.util.HashSet; 7 import java.util.Set; 5 8 import org.apache.solr.client.solrj.SolrQuery; 6 9 import org.apache.solr.client.solrj.SolrServerException; … … 31 34 return solrServer; 32 35 } 36 37 /** 38 * Basic sanitising of Solr queries. 39 * 40 * Query is based on the URL to the VLO web application. Also, explain 41 * about the URL and ?fq=language:dutch 42 * Assume filters have the form a:b 43 * like for example language:dutch 44 * 45 * @param query 46 * @return 47 */ 48 private SolrQuery sanitise (SolrQuery query){ 49 50 // String [] facetsFromConfig; 51 52 // try and get the filters facets from the query 53 String [] filtersInQuery; 54 filtersInQuery = query.getFilterQueries(); 55 56 if (filtersInQuery == null) { 57 // the query does not contain filters 58 } else { 59 // get the facets from the configuration file 60 // facetsFromConfig = VloConfig.getFacetFields(); 61 62 // present the facets from the config file as a list to a new set 63 Set<String> facetsDefined; 64 facetsDefined = new HashSet<String>(Arrays.asList(VloConfig.getFacetFields())); 65 66 // check the filters in the query by name 67 for (String filter : filtersInQuery) { 68 // split up a filter, look at the string preceeding the semicolon 69 String facetInFilter = filter.split(":") [0]; 70 71 if (facetsDefined.contains(facetInFilter)) { 72 // facet in the filter is in the set that is defined by the config file 73 } else { 74 if (facetInFilter.startsWith("_")) { 75 // this facet is hidden, do not consider it 76 } else { 77 // the filter name does not match a facet in the facet 78 query.removeFilterQuery(filter); 79 } 80 } 81 } 82 } 83 84 // finally, return the sanitised query 85 return query; 86 } 33 87 34 88 protected QueryResponse fireQuery(SolrQuery query) { 89 SolrQuery sanitisedQuery; 90 sanitisedQuery = sanitise(query); 35 91 try { 36 return solrServer.query( query);92 return solrServer.query(sanitisedQuery); 37 93 } catch (SolrServerException e) { 38 94 LOG.error("Error getting data:", e);
Note: See TracChangeset
for help on using the changeset viewer.