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
23 public class DocBoostMatcher {
24
25 private String boostExpression = "0";
26
27 private String matchExpression;
28
29 public DocBoostMatcher() {
30
31 }
32
33 public DocBoostMatcher(final BoostDocumentRule rule) {
34 matchExpression = rule.getUrlExpr();
35 boostExpression = rule.getBoostExpr();
36 }
37
38 public boolean match(final Map<String, Object> map) {
39
40 if (map == null || map.isEmpty() || matchExpression == null) {
41 return false;
42 }
43
44 final Object value = GroovyUtil.evaluate(matchExpression, map);
45 if (value instanceof Boolean) {
46 return ((Boolean) value).booleanValue();
47 }
48
49 return false;
50 }
51
52 public float getValue(final Map<String, Object> map) {
53 if (map == null || map.isEmpty()) {
54 return 0.0f;
55 }
56
57 final Object value = GroovyUtil.evaluate(boostExpression, map);
58 if (value instanceof Integer) {
59 return ((Integer) value).floatValue();
60 } else if (value instanceof Long) {
61 return ((Long) value).floatValue();
62 } else if (value instanceof Float) {
63 return ((Float) value).floatValue();
64 } else if (value instanceof Double) {
65 return ((Double) value).floatValue();
66 } else if (value != null) {
67 return Float.parseFloat(value.toString());
68 }
69
70 return 0.0f;
71 }
72
73 public String getBoostExpression() {
74 return boostExpression;
75 }
76
77 public void setBoostExpression(final String expression) {
78 boostExpression = expression;
79 }
80
81 public String getMatchExpression() {
82 return matchExpression;
83 }
84
85 public void setMatchExpression(final String expression) {
86 matchExpression = expression;
87 }
88
89 }