1 |
41987
|
sandro.lab
|
package eu.dnetlib.index.solr.cql;
|
2 |
|
|
|
3 |
|
|
import java.util.Map;
|
4 |
|
|
import java.util.function.Function;
|
5 |
|
|
|
6 |
|
|
import eu.dnetlib.clients.index.model.Any.ValueType;
|
7 |
45455
|
alessia.ba
|
import eu.dnetlib.cql.CqlValueTransformerMap;
|
8 |
41987
|
sandro.lab
|
import org.apache.commons.logging.Log;
|
9 |
|
|
import org.apache.commons.logging.LogFactory;
|
10 |
|
|
import org.apache.solr.common.SolrException;
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* This class maps the fields in the given index schema with a transformation rule.
|
14 |
|
|
*
|
15 |
|
|
* @author marko
|
16 |
|
|
*/
|
17 |
|
|
public class SolrTypeBasedCqlValueTransformerMap implements CqlValueTransformerMap {
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* logger.
|
21 |
|
|
*/
|
22 |
|
|
private static final Log log = LogFactory.getLog(SolrTypeBasedCqlValueTransformerMap.class); // NOPMD by marko on 11/24/08 5:02 PM
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Index schema.
|
26 |
|
|
*/
|
27 |
|
|
private final Map<String, ValueType> schema;
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Map of functions.
|
31 |
|
|
*/
|
32 |
|
|
private final Map<String, Function<String, String>> transformerMap;
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* Create value transformer map bound to a specific schema
|
36 |
|
|
*
|
37 |
|
|
* @param schema
|
38 |
|
|
*/
|
39 |
|
|
public SolrTypeBasedCqlValueTransformerMap(final Map<String, ValueType> schema, final Map<String, Function<String, String>> transformerMap) {
|
40 |
|
|
this.schema = schema;
|
41 |
|
|
this.transformerMap = transformerMap;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* {@inheritDoc}
|
46 |
|
|
*/
|
47 |
|
|
@Override
|
48 |
|
|
public Function<String, String> transformerFor(final String fieldName) {
|
49 |
|
|
try {
|
50 |
|
|
final ValueType field = schema.get(fieldName);
|
51 |
|
|
|
52 |
|
|
if (field != null) {
|
53 |
|
|
Function<String, String> res = transformerMap.get(field.name());
|
54 |
|
|
if (res != null) {
|
55 |
|
|
return res;
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
} catch (SolrException e) {
|
59 |
|
|
log.debug("cannot find field", e);
|
60 |
|
|
}
|
61 |
|
|
return it -> it;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
}
|