1
|
package eu.dnetlib.index.query;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
|
5
|
import eu.dnetlib.clients.index.client.AbstractIndexClient;
|
6
|
import eu.dnetlib.clients.index.query.IndexQuery;
|
7
|
import eu.dnetlib.clients.index.query.IndexQueryFactory;
|
8
|
import eu.dnetlib.clients.index.query.Pruner.Result;
|
9
|
import eu.dnetlib.clients.index.query.QueryLanguage;
|
10
|
import eu.dnetlib.clients.index.utils.IndexFieldUtility;
|
11
|
import eu.dnetlib.cql.lucene.TranslatedQuery;
|
12
|
import eu.dnetlib.index.utils.HighlightUtils;
|
13
|
import org.apache.commons.logging.Log;
|
14
|
import org.apache.commons.logging.LogFactory;
|
15
|
|
16
|
/**
|
17
|
* A factory for creating SolrIndexQuery objects.
|
18
|
*/
|
19
|
public class SolrIndexQueryFactory extends IndexQueryFactory {
|
20
|
|
21
|
/**
|
22
|
* logger.
|
23
|
*/
|
24
|
private static final Log log = LogFactory.getLog(SolrIndexQueryFactory.class);
|
25
|
|
26
|
/**
|
27
|
* The Property name SERVICE_HIGHLIGHT_ENABLE.
|
28
|
*/
|
29
|
private static final String SERVICE_HIGHLIGHT_ENABLE = "service.index.solr.highlight.enable";
|
30
|
|
31
|
/*
|
32
|
* (non-Javadoc)
|
33
|
*
|
34
|
* @see eu.dnetlib.functionality.index.query.IndexQueryFactory#newInstance(eu.dnetlib.functionality.index.cql.TranslatedQuery,
|
35
|
* eu.dnetlib.functionality.index.query.Pruner.Result, eu.dnetlib.functionality.index.query.QueryLanguage)
|
36
|
*/
|
37
|
@Override
|
38
|
protected IndexQuery newInstance(final TranslatedQuery cql, final Result res, final QueryLanguage lang) {
|
39
|
|
40
|
switch (lang) {
|
41
|
case CQL:
|
42
|
return new SolrIndexQuery(cql, res.getOptionMap());
|
43
|
case SOLR:
|
44
|
return new SolrIndexQuery(res.getNode().toCQL(), res.getOptionMap());
|
45
|
default:
|
46
|
throw new IllegalArgumentException("invalid query language: " + lang);
|
47
|
}
|
48
|
}
|
49
|
|
50
|
/*
|
51
|
* (non-Javadoc)
|
52
|
*
|
53
|
* @see eu.dnetlib.functionality.index.query.IndexQueryFactory#setQueryOptions(eu.dnetlib.functionality.index.query.IndexQuery,
|
54
|
* eu.dnetlib.functionality.index.IndexServerDAO)
|
55
|
*/
|
56
|
@Override
|
57
|
protected IndexQuery setQueryOptions(final IndexQuery indexQuery, final AbstractIndexClient client) {
|
58
|
|
59
|
final SolrIndexQuery solrQuery = (SolrIndexQuery) indexQuery;
|
60
|
|
61
|
boolean isHighlightEnabled = Boolean.parseBoolean(client.getServiceProperties().get(SERVICE_HIGHLIGHT_ENABLE));
|
62
|
if (solrQuery.getHighlight() & isHighlightEnabled) {
|
63
|
solrQuery.setHighlightFragsize(0).setHighlightSnippets(1).setHighlightSimplePre(HighlightUtils.DEFAULT_HL_PRE)
|
64
|
.setHighlightSimplePost(HighlightUtils.DEFAULT_HL_POST).addHighlightField(IndexFieldUtility.RESULT)
|
65
|
.addField(IndexFieldUtility.INDEX_RECORD_ID);
|
66
|
}
|
67
|
|
68
|
solrQuery.addField(IndexFieldUtility.RESULT);
|
69
|
if (solrQuery.getFacetFields() != null) {
|
70
|
log.debug("getFacetFields() " + Arrays.asList(solrQuery.getFacetFields()));
|
71
|
solrQuery.setFacetMinCount(1);
|
72
|
}
|
73
|
|
74
|
return solrQuery;
|
75
|
}
|
76
|
|
77
|
}
|