MtasCQLQParser.java.html
9.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasCQLQParser.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.search</a> > <span class="el_source">MtasCQLQParser.java</span></div><h1>MtasCQLQParser.java</h1><pre class="source lang-java linenums">package mtas.solr.search;
import java.io.BufferedReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import mtas.parser.cql.MtasCQLParser;
import mtas.search.spans.util.MtasSpanQuery;
import org.apache.lucene.search.Query;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SyntaxError;
/**
* The Class MtasCQLQParser.
*/
public class MtasCQLQParser extends QParser {
/** The Constant MTAS_CQL_QPARSER_FIELD. */
public static final String MTAS_CQL_QPARSER_FIELD = "field";
/** The Constant MTAS_CQL_QPARSER_QUERY. */
public static final String MTAS_CQL_QPARSER_QUERY = "query";
/** The Constant MTAS_CQL_QPARSER_IGNORE. */
public static final String MTAS_CQL_QPARSER_IGNORE = "ignore";
/** The Constant MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH. */
public static final String MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH = "maximumIgnoreLength";
/** The Constant MTAS_CQL_QPARSER_PREFIX. */
public static final String MTAS_CQL_QPARSER_PREFIX = "prefix";
/** The field. */
<span class="fc" id="L39"> String field = null;</span>
/** The cql. */
<span class="fc" id="L42"> String cql = null;</span>
/** The ignore query. */
<span class="fc" id="L45"> String ignoreQuery = null;</span>
/** The maximum ignore length. */
<span class="fc" id="L48"> Integer maximumIgnoreLength = null;</span>
/** The default prefix. */
<span class="fc" id="L51"> String defaultPrefix = null;</span>
/** The variables. */
<span class="fc" id="L54"> HashMap<String, String[]> variables = null;</span>
/**
* Instantiates a new mtas CQLQ parser.
*
* @param qstr the qstr
* @param localParams the local params
* @param params the params
* @param req the req
*/
public MtasCQLQParser(String qstr, SolrParams localParams, SolrParams params,
SolrQueryRequest req) {
<span class="fc" id="L66"> super(qstr, localParams, params, req);</span>
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_CQL_QPARSER_FIELD) != null)</span>
<span class="pc bpc" id="L69" title="1 of 2 branches missed."> && (localParams.getParams(MTAS_CQL_QPARSER_FIELD).length == 1)) {</span>
<span class="fc" id="L70"> field = localParams.getParams(MTAS_CQL_QPARSER_FIELD)[0];</span>
}
<span class="pc bpc" id="L72" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_CQL_QPARSER_QUERY) != null)</span>
<span class="pc bpc" id="L73" title="1 of 2 branches missed."> && (localParams.getParams(MTAS_CQL_QPARSER_QUERY).length == 1)) {</span>
<span class="fc" id="L74"> cql = localParams.getParams(MTAS_CQL_QPARSER_QUERY)[0];</span>
}
<span class="pc bpc" id="L76" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_CQL_QPARSER_IGNORE) != null)</span>
<span class="nc bnc" id="L77" title="All 2 branches missed."> && (localParams.getParams(MTAS_CQL_QPARSER_IGNORE).length == 1)) {</span>
<span class="nc" id="L78"> ignoreQuery = localParams.getParams(MTAS_CQL_QPARSER_IGNORE)[0];</span>
}
<span class="pc bpc" id="L80" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH) != null)</span>
&& (localParams
<span class="nc bnc" id="L82" title="All 2 branches missed."> .getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH).length == 1)) {</span>
try {
<span class="nc" id="L84"> maximumIgnoreLength = Integer.parseInt(</span>
<span class="nc" id="L85"> localParams.getParams(MTAS_CQL_QPARSER_MAXIMUM_IGNORE_LENGTH)[0]);</span>
<span class="nc" id="L86"> } catch (NumberFormatException e) {</span>
<span class="nc" id="L87"> maximumIgnoreLength = null;</span>
<span class="nc" id="L88"> }</span>
}
<span class="pc bpc" id="L90" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_CQL_QPARSER_PREFIX) != null)</span>
<span class="nc bnc" id="L91" title="All 2 branches missed."> && (localParams.getParams(MTAS_CQL_QPARSER_PREFIX).length == 1)) {</span>
<span class="nc" id="L92"> defaultPrefix = localParams.getParams(MTAS_CQL_QPARSER_PREFIX)[0];</span>
}
<span class="fc" id="L94"> variables = new HashMap<>();</span>
<span class="fc" id="L95"> Iterator<String> it = localParams.getParameterNamesIterator();</span>
<span class="fc bfc" id="L96" title="All 2 branches covered."> while (it.hasNext()) {</span>
<span class="fc" id="L97"> String item = it.next();</span>
<span class="pc bpc" id="L98" title="1 of 2 branches missed."> if (item.startsWith("variable_")) {</span>
<span class="nc bnc" id="L99" title="All 2 branches missed."> if (localParams.getParams(item).length == 0</span>
<span class="nc bnc" id="L100" title="All 2 branches missed."> || (localParams.getParams(item).length == 1</span>
<span class="nc bnc" id="L101" title="All 2 branches missed."> && localParams.getParams(item)[0].isEmpty())) {</span>
<span class="nc" id="L102"> variables.put(item.substring(9), new String[0]);</span>
} else {
<span class="nc" id="L104"> ArrayList<String> list = new ArrayList<>();</span>
<span class="nc bnc" id="L105" title="All 2 branches missed."> for (int i = 0; i < localParams.getParams(item).length; i++) {</span>
<span class="nc" id="L106"> String[] subList = localParams.getParams(item)[i]</span>
<span class="nc" id="L107"> .split("(?<!\\\\),");</span>
<span class="nc bnc" id="L108" title="All 2 branches missed."> for (int j = 0; j < subList.length; j++) {</span>
<span class="nc" id="L109"> list.add(subList[j].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
}
<span class="nc" id="L112"> variables.put(item.substring(9),</span>
<span class="nc" id="L113"> list.toArray(new String[list.size()]));</span>
}
}
<span class="fc" id="L116"> }</span>
<span class="fc" id="L117"> }</span>
/*
* (non-Javadoc)
*
* @see org.apache.solr.search.QParser#parse()
*/
@Override
public Query parse() throws SyntaxError {
<span class="pc bpc" id="L126" title="1 of 2 branches missed."> if (field == null) {</span>
<span class="nc" id="L127"> throw new SyntaxError("no " + MTAS_CQL_QPARSER_FIELD);</span>
<span class="pc bpc" id="L128" title="1 of 2 branches missed."> } else if (cql == null) {</span>
<span class="nc" id="L129"> throw new SyntaxError("no " + MTAS_CQL_QPARSER_QUERY);</span>
} else {
<span class="fc" id="L131"> MtasSpanQuery q = null;</span>
<span class="fc" id="L132"> MtasSpanQuery iq = null;</span>
<span class="pc bpc" id="L133" title="1 of 2 branches missed."> if (ignoreQuery != null) {</span>
<span class="nc" id="L134"> Reader ignoreReader = new BufferedReader(new StringReader(ignoreQuery));</span>
<span class="nc" id="L135"> MtasCQLParser ignoreParser = new MtasCQLParser(ignoreReader);</span>
try {
<span class="nc" id="L137"> iq = ignoreParser.parse(field, null, null, null, null);</span>
<span class="nc" id="L138"> } catch (mtas.parser.cql.TokenMgrError</span>
| mtas.parser.cql.ParseException e) {
<span class="nc" id="L140"> throw new SyntaxError(e);</span>
<span class="nc" id="L141"> }</span>
}
<span class="fc" id="L143"> Reader queryReader = new BufferedReader(new StringReader(cql));</span>
<span class="fc" id="L144"> MtasCQLParser queryParser = new MtasCQLParser(queryReader);</span>
try {
<span class="fc" id="L146"> q = queryParser.parse(field, defaultPrefix, variables, iq,</span>
maximumIgnoreLength);
<span class="nc" id="L148"> } catch (mtas.parser.cql.TokenMgrError</span>
| mtas.parser.cql.ParseException e) {
<span class="nc" id="L150"> throw new SyntaxError(e);</span>
<span class="fc" id="L151"> }</span>
<span class="fc" id="L152"> return q;</span>
}
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>