1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.indexer;
17
18 import java.util.Map;
19
20 import org.codelibs.fess.es.config.exentity.BoostDocumentRule;
21 import org.codelibs.fess.util.GroovyUtil;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class DocBoostMatcher {
26 private static final Logger logger = LoggerFactory.getLogger(DocBoostMatcher.class);
27
28 private String boostExpression = "0";
29
30 private String matchExpression;
31
32 public DocBoostMatcher() {
33
34 }
35
36 public DocBoostMatcher(final BoostDocumentRule rule) {
37 matchExpression = rule.getUrlExpr();
38 boostExpression = rule.getBoostExpr();
39 }
40
41 public boolean match(final Map<String, Object> map) {
42
43 if (map == null || map.isEmpty() || matchExpression == null) {
44 return false;
45 }
46
47 final Object value = GroovyUtil.evaluate(matchExpression, map);
48 if (value instanceof Boolean) {
49 return ((Boolean) value).booleanValue();
50 }
51
52 return false;
53 }
54
55 public float getValue(final Map<String, Object> map) {
56 if (map == null || map.isEmpty()) {
57 return 0.0f;
58 }
59
60 final Object value = GroovyUtil.evaluate(boostExpression, map);
61 if (value instanceof Integer) {
62 return ((Integer) value).floatValue();
63 } else if (value instanceof Long) {
64 return ((Long) value).floatValue();
65 } else if (value instanceof Float) {
66 return ((Float) value).floatValue();
67 } else if (value instanceof Double) {
68 return ((Double) value).floatValue();
69 } else if (value != null) {
70 return Float.parseFloat(value.toString());
71 }
72
73 return 0.0f;
74 }
75
76 public String getBoostExpression() {
77 return boostExpression;
78 }
79
80 public void setBoostExpression(final String expression) {
81 boostExpression = expression;
82 }
83
84 public String getMatchExpression() {
85 return matchExpression;
86 }
87
88 public void setMatchExpression(final String expression) {
89 matchExpression = expression;
90 }
91
92 }