15
15
*/
16
16
package org .springframework .data .solr .core ;
17
17
18
+ import static org .apache .solr .common .params .CommonParams .*;
19
+ import static org .apache .solr .common .params .DisMaxParams .*;
20
+ import static org .apache .solr .common .params .SimpleParams .QF ;
21
+
18
22
import java .util .ArrayList ;
19
23
import java .util .Collection ;
20
24
import java .util .List ;
21
25
import java .util .Map .Entry ;
22
-
23
26
import org .apache .commons .lang3 .StringUtils ;
24
27
import org .apache .solr .client .solrj .SolrQuery ;
25
28
import org .apache .solr .client .solrj .SolrQuery .ORDER ;
36
39
import org .springframework .data .domain .Sort .Order ;
37
40
import org .springframework .data .mapping .context .MappingContext ;
38
41
import org .springframework .data .solr .core .query .*;
39
- import org .springframework .data .solr .core .query .Criteria .Predicate ;
40
42
import org .springframework .data .solr .core .query .FacetOptions .FacetParameter ;
41
43
import org .springframework .data .solr .core .query .FacetOptions .FieldWithDateRangeParameters ;
42
44
import org .springframework .data .solr .core .query .FacetOptions .FieldWithFacetParameters ;
65
67
* @author Joachim Uhrlaß
66
68
* @author Petar Tahchiev
67
69
* @author Juan Manuel de Blas
70
+ * @author Matthew Hall
68
71
*/
69
72
public class DefaultQueryParser extends QueryParserBase <SolrDataQuery > {
70
73
@@ -109,6 +112,10 @@ public final SolrQuery doConstructSolrQuery(SolrDataQuery query, @Nullable Class
109
112
processHighlightOptions (solrQuery , (HighlightQuery ) query , domainType );
110
113
}
111
114
115
+ if (query instanceof DisMaxQuery ) {
116
+ processDisMaxOptions (solrQuery , (DisMaxQuery ) query );
117
+ }
118
+
112
119
return solrQuery ;
113
120
}
114
121
@@ -132,6 +139,38 @@ private void processQueryOptions(SolrQuery solrQuery, Query query, @Nullable Cla
132
139
LOGGER .debug ("Constructed SolrQuery:\r \n {}" , solrQuery );
133
140
}
134
141
142
+ protected void processDisMaxOptions (SolrQuery solrQuery , DisMaxQuery disMaxQuery ) {
143
+
144
+ if (disMaxQuery == null || disMaxQuery .getDisMaxOptions () == null ) {
145
+ return ;
146
+ }
147
+
148
+ DisMaxOptions disMaxOptions = disMaxQuery .getDisMaxOptions ();
149
+
150
+ solrQuery .set ("defType" , "dismax" );
151
+
152
+ setSolrParamIfPresent (solrQuery , DF , disMaxOptions .getDefaultField ());
153
+
154
+ setSolrParamIfPresent (solrQuery , ALTQ , disMaxOptions .getAltQuery ());
155
+ setSolrParamIfPresent (solrQuery , QF , disMaxOptions .getQueryFunction ());
156
+ setSolrParamIfPresent (solrQuery , MM , disMaxOptions .getMinimumMatch ());
157
+
158
+ setSolrParamIfPresent (solrQuery , BQ , disMaxOptions .getBoostQuery ());
159
+ setSolrParamIfPresent (solrQuery , BF , disMaxOptions .getBoostFunction ());
160
+ setSolrParamIfPresent (solrQuery , PF , disMaxOptions .getPhraseFunction ());
161
+
162
+ setSolrParamIfPresent (solrQuery , PS , disMaxOptions .getPhraseSlop () == null ? null :
163
+ String .valueOf (disMaxOptions .getPhraseSlop ()));
164
+ setSolrParamIfPresent (solrQuery , QS , disMaxOptions .getQuerySlop () == null ? null : String .valueOf (disMaxOptions .getQuerySlop ()));
165
+ setSolrParamIfPresent (solrQuery , TIE , disMaxOptions .getTie () == null ? null : String .valueOf (disMaxOptions .getTie ()));
166
+ }
167
+
168
+ private static void setSolrParamIfPresent (SolrQuery solrQuery , String param , String value ) {
169
+ if (!org .springframework .util .StringUtils .isEmpty (value )) {
170
+ solrQuery .setParam (param , value );
171
+ }
172
+ }
173
+
135
174
private void processFacetOptions (SolrQuery solrQuery , FacetQuery query , @ Nullable Class <?> domainType ) {
136
175
137
176
if (enableFaceting (solrQuery , query )) {
0 commit comments