28 |
28 |
|
29 |
29 |
import java.io.IOException;
|
30 |
30 |
import java.io.InputStream;
|
|
31 |
import java.io.StringWriter;
|
|
32 |
import java.util.ArrayList;
|
31 |
33 |
import java.util.List;
|
32 |
34 |
import java.util.Map;
|
33 |
35 |
import java.util.Set;
|
... | ... | |
38 |
40 |
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
39 |
41 |
import org.apache.solr.client.solrj.response.QueryResponse;
|
40 |
42 |
import org.apache.solr.common.params.SolrParams;
|
|
43 |
import org.apache.solr.common.util.XML;
|
41 |
44 |
import org.apache.solr.core.CoreContainer;
|
42 |
45 |
import org.apache.solr.core.SolrCore;
|
|
46 |
import org.apache.solr.schema.IndexSchema;
|
43 |
47 |
import org.apache.solr.schema.SchemaField;
|
44 |
48 |
import org.dataone.service.exceptions.NotFound;
|
45 |
49 |
import org.dataone.service.exceptions.NotImplemented;
|
... | ... | |
60 |
64 |
private CoreContainer coreContainer = null;
|
61 |
65 |
private String collectionName = null;
|
62 |
66 |
private SolrCore solrCore = null;
|
|
67 |
private Map<String, SchemaField> fieldMap = null;
|
|
68 |
private IndexSchema schema = null;
|
|
69 |
private List<String> validSolrFieldNames = null;
|
|
70 |
private String solrSpecVersion = "";
|
|
71 |
|
63 |
72 |
/**
|
64 |
73 |
* Constructor.
|
65 |
74 |
* @param solrServer
|
... | ... | |
83 |
92 |
if(solrCore == null) {
|
84 |
93 |
throw new NotFound("0000","EmbeddedSolrQueryService.constructor - There is no SolrCore named "+collectionName+".");
|
85 |
94 |
}
|
|
95 |
schema = solrCore.getSchema();
|
|
96 |
fieldMap = schema.getFields();
|
86 |
97 |
}
|
87 |
98 |
/**
|
88 |
99 |
* Query the Solr server with specified query and user's identity. If the Subjects
|
... | ... | |
131 |
142 |
|
132 |
143 |
|
133 |
144 |
/**
|
134 |
|
* Get the fields list of the index schema
|
|
145 |
* Get the fields map of the index schema
|
|
146 |
* @return the fields map (the field name is the key and the SchemaField is the value).
|
|
147 |
*/
|
|
148 |
public Map<String, SchemaField> getIndexSchemaFields() {
|
|
149 |
return fieldMap;
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
|
135 |
154 |
* @return
|
136 |
|
* @throws Exception
|
137 |
155 |
*/
|
138 |
|
public Map<String, SchemaField> getIndexSchemaFields() throws Exception {
|
139 |
|
return null;
|
|
156 |
public List<String> getValidSchemaField() {
|
|
157 |
if (validSolrFieldNames != null && validSolrFieldNames.isEmpty()) {
|
|
158 |
//System.out.println("the valid file name is\n"+validSolrFieldNames);
|
|
159 |
return validSolrFieldNames;
|
|
160 |
} else {
|
|
161 |
validSolrFieldNames = new ArrayList<String>();
|
|
162 |
if(fieldMap != null) {
|
|
163 |
Set<String> fieldNames = fieldMap.keySet();
|
|
164 |
for(String fieldName : fieldNames) {
|
|
165 |
SchemaField field = fieldMap.get(fieldName);
|
|
166 |
//remove the field which is the target field of a CopyField.
|
|
167 |
if(field != null && !schema.isCopyFieldTarget(field)) {
|
|
168 |
validSolrFieldNames.add(fieldName);
|
|
169 |
}
|
|
170 |
}
|
|
171 |
}
|
|
172 |
//System.out.println("the valid file name is\n"+validSolrFieldNames);
|
|
173 |
return validSolrFieldNames;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
|
140 |
178 |
}
|
141 |
179 |
|
142 |
180 |
/**
|
... | ... | |
144 |
182 |
* @return
|
145 |
183 |
*/
|
146 |
184 |
public String getSolrServerVersion() {
|
147 |
|
return null;
|
|
185 |
if( solrSpecVersion !=null ) {
|
|
186 |
return solrSpecVersion;
|
|
187 |
} else {
|
|
188 |
Package p = SolrCore.class.getPackage();
|
|
189 |
StringWriter tmp = new StringWriter();
|
|
190 |
solrSpecVersion = p.getSpecificationVersion();
|
|
191 |
if (null != solrSpecVersion) {
|
|
192 |
try {
|
|
193 |
XML.escapeCharData(solrSpecVersion, tmp);
|
|
194 |
} catch (IOException e) {
|
|
195 |
e.printStackTrace();
|
|
196 |
}
|
|
197 |
solrSpecVersion = tmp.toString();
|
|
198 |
}
|
|
199 |
if (solrSpecVersion == null || solrSpecVersion.trim().equals("")) {
|
|
200 |
solrSpecVersion = UNKNOWN;
|
|
201 |
}
|
|
202 |
return solrSpecVersion;
|
|
203 |
}
|
148 |
204 |
}
|
149 |
205 |
}
|
Imeplement the getSolrVersion, getSchemaField and getValidSchemaFields for the EmbeddedSolrServer.