Revision 44742
Added by Katerina Iatropoulou over 7 years ago
SolrResultSet.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.solr; |
2 | 2 |
|
3 | 3 |
import com.google.gson.Gson; |
4 |
import eu.dnetlib.data.search.utils.SolrResultSetOptionsUtil; |
|
5 |
import eu.dnetlib.data.search.utils.SolrResultsFormatter; |
|
4 |
import eu.dnetlib.data.search.transform.Transformer; |
|
5 |
import eu.dnetlib.data.search.transform.TransformerException; |
|
6 |
import eu.dnetlib.data.search.utils.solr.SolrResultSetOptionsUtil; |
|
7 |
import eu.dnetlib.data.search.utils.solr.SolrResultsFormatter; |
|
6 | 8 |
import eu.dnetlib.domain.EPR; |
7 | 9 |
import gr.uoa.di.driver.enabling.resultset.ResultSet; |
8 | 10 |
import org.apache.commons.lang.StringEscapeUtils; |
... | ... | |
70 | 72 |
public int size() { |
71 | 73 |
return (int) size; |
72 | 74 |
} |
73 |
|
|
74 |
@Deprecated |
|
75 |
private int getSize() throws SolrServerException { |
|
76 |
//logger.debug("Query opts" + queryOpts); |
|
77 |
QueryResponse rsp = null; |
|
78 |
|
|
79 |
synchronized (solrClient) { |
|
80 |
rsp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
81 |
} |
|
82 |
|
|
83 |
//logger.debug(queryOpts); |
|
84 |
|
|
85 |
if (epr.getParameter("action").equals("lookup")) { |
|
86 |
return (int) rsp.getResults().getNumFound(); |
|
87 |
} else if (epr.getParameter("action").equals("browse")) { |
|
88 |
int max = -12; |
|
89 |
|
|
90 |
for (FacetField field:rsp.getFacetFields()) { |
|
91 |
if (field.getValueCount() > max) { |
|
92 |
max = field.getValueCount(); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
return max; |
|
97 |
} |
|
98 |
|
|
99 |
return 0; |
|
100 |
} |
|
101 |
|
|
102 |
|
|
75 |
|
|
103 | 76 |
@Override |
104 | 77 |
@Deprecated |
105 | 78 |
public List<String> getElements(int from, int to) { |
... | ... | |
172 | 145 |
return null; |
173 | 146 |
} |
174 | 147 |
|
175 |
public Map<String,List<String>> newGet(int from, int to, String format) { |
|
148 |
public Map<String,List<String>> newGet(int from, int to, String format, Transformer transformer) {
|
|
176 | 149 |
List<String> refineSolrResults = new ArrayList<String>(); |
177 | 150 |
List<String> searchSolrResults = new ArrayList<String>(); |
178 | 151 |
|
... | ... | |
239 | 212 |
|
240 | 213 |
for (int i = 0; i < docs.size(); i++) { |
241 | 214 |
String result = ((ArrayList<String>) docs.get(i).get("__result")).get(0); |
215 |
try { |
|
216 |
if (transformer != null) { |
|
217 |
result = transformer.transform(result); |
|
218 |
} |
|
219 |
} catch (TransformerException te) { |
|
220 |
logger.warn("Error transforming " + result, te); |
|
221 |
continue; |
|
222 |
} |
|
223 |
|
|
242 | 224 |
if (format != null && format.equals(MediaType.APPLICATION_JSON)) { |
243 | 225 |
searchSolrResults.add(SolrResultsFormatter.xml2Json(result)); |
244 | 226 |
} else { // default xml |
... | ... | |
259 | 241 |
} catch (SolrServerException sse) { |
260 | 242 |
logger.error("Error calling solr", sse); |
261 | 243 |
} |
262 |
|
|
263 | 244 |
return null; |
264 | 245 |
} |
265 | 246 |
|
... | ... | |
301 | 282 |
synchronized (solrClient) { |
302 | 283 |
resp = solrClient.query(SolrParams.toSolrParams(extraOpts)); |
303 | 284 |
} |
304 |
System.out.println("time: " + resp.getElapsedTime()); |
|
285 |
//System.out.println("time: " + resp.getElapsedTime());
|
|
305 | 286 |
//System.out.println("results: " + resp.getResults()); |
306 | 287 |
|
307 | 288 |
/* System.out.println(resp.getFacetField("contextname").getValueCount()); |
Also available in: Unified diff
Working on backwards compatibility. IMPORTANT: sygma and refine are not yet compatible