Changeset 25863
- Timestamp:
- 2012-06-28T13:05:27+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java
r25862 r25863 21 21 // Greenstone classes 22 22 import java.io.File; 23 import java.util.ArrayList; 23 24 import java.util.HashMap; 24 25 import java.util.Iterator; … … 36 37 import org.greenstone.util.GlobalProperties; 37 38 import org.w3c.dom.Element; 39 import org.w3c.dom.NodeList; 38 40 39 41 public class GS2SolrSearch extends SharedSoleneGS2FieldSearch … … 45 47 protected HashMap solr_core_cache; 46 48 protected SolrQueryWrapper solr_src = null; 49 50 protected ArrayList<String> _facets = new ArrayList<String>(); 47 51 48 52 public GS2SolrSearch() … … 57 61 if (all_solr_cores == null) 58 62 { 59 // Share one CoreContainer across all s ties/collections63 // Share one CoreContainer across all sites/collections 60 64 try 61 65 { 62 63 66 String gsdl3_home = GlobalProperties.getGSDL3Home(); 64 67 String solr_ext_name = GlobalProperties.getProperty("gsdlext.solr.dirname", "solr"); … … 79 82 } 80 83 84 /** configure this service */ 85 public boolean configure(Element info, Element extra_info) 86 { 87 if (!super.configure(info, extra_info)) 88 { 89 return false; 90 } 91 92 Element searchElem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM); 93 NodeList configIndexElems = searchElem.getElementsByTagName(GSXML.INDEX_ELEM); 94 95 ArrayList<String> chosenFacets = new ArrayList<String>(); 96 for (int i = 0; i < configIndexElems.getLength(); i++) 97 { 98 Element current = (Element) configIndexElems.item(i); 99 if (current.getAttribute(GSXML.FACET_ATT).equals("true")) 100 { 101 chosenFacets.add(current.getAttribute(GSXML.NAME_ATT)); 102 } 103 } 104 105 Element indexListElem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_ELEM + GSXML.LIST_MODIFIER); 106 NodeList buildIndexElems = indexListElem.getElementsByTagName(GSXML.INDEX_ELEM); 107 108 for(int j = 0; j < buildIndexElems.getLength(); j++) 109 { 110 Element current = (Element) buildIndexElems.item(j); 111 for(int i = 0; i < chosenFacets.size(); i++) 112 { 113 if (current.getAttribute(GSXML.NAME_ATT).equals(chosenFacets.get(i))) 114 { 115 _facets.add(current.getAttribute(GSXML.SHORTNAME_ATT)); 116 } 117 } 118 } 119 120 return true; 121 } 122 81 123 public void cleanUp() 82 124 { … … 91 133 protected boolean setUpQueryer(HashMap params) 92 134 { 93 String indexdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar + "index" + File.separatorChar; 135 this.solr_src.clearFacets(); 136 this.solr_src.clearFacetQueries(); 137 138 for (int i = 0; i < _facets.size(); i++) 139 { 140 this.solr_src.addFacet(_facets.get(i)); 141 } 94 142 95 143 String index = "didx"; … … 119 167 { 120 168 start_page = Integer.parseInt(value); 121 122 169 } 123 170 else if (name.equals(MATCH_PARAM)) … … 150 197 index = "didx"; 151 198 } 199 } 200 else if (name.equals("facets") && value.length() > 0) 201 { 202 String[] facets = value.split(","); 203 204 for (String facet : facets) 205 { 206 this.solr_src.addFacet(facet); 207 } 208 } 209 else if (name.equals("facetQueries") && value.length() > 0) 210 { 211 this.solr_src.addFacetQuery(value); 152 212 } 153 213 else if (name.equals(INDEX_SUBCOLLECTION_PARAM)) … … 190 250 191 251 String core_name = site_name + "-" + coll_name + "-" + index; 192 252 193 253 EmbeddedSolrServer solr_core = null; 194 254 … … 212 272 protected Object runQuery(String query) 213 273 { 214 215 /*216 * ModifiableSolrParams solrParams = new ModifiableSolrParams();217 * solrParams.set("collectionName", myCollection);218 * solrParams.set("username", "admin"); solrParams.set("password",219 * "password"); solrParams.set("facet", facet); solrParams.set("q",220 * query); solrParams.set("start", start); solrParams.set("rows",221 * nbDocuments); return server.query(solrParams);222 */223 224 /*225 * SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);226 * //solrQuery.set("collectionName", myCollection);227 * solrQuery.set("username", "admin"); solrQuery.set("password",228 * "password"); solrQuery.set("facet", facet);229 * solrQuery.setStart(start); solrQuery.setRows(nbDocuments); //return230 * server.query(solrQuery);231 */232 233 274 try 234 275 { 276 //SharedSoleneQueryResult sqr = this.solr_src.runQuery(query); 235 277 SharedSoleneQueryResult sqr = this.solr_src.runQuery(query); 278 236 279 return sqr; 237 280 }
Note:
See TracChangeset
for help on using the changeset viewer.