1515 */
1616package org .springframework .data .solr .core ;
1717
18+ import static org .apache .solr .common .params .CommonParams .DF ;
19+ import static org .apache .solr .common .params .DisMaxParams .ALTQ ;
20+ import static org .apache .solr .common .params .DisMaxParams .BF ;
21+ import static org .apache .solr .common .params .DisMaxParams .BQ ;
22+ import static org .apache .solr .common .params .DisMaxParams .MM ;
23+ import static org .apache .solr .common .params .DisMaxParams .PF ;
24+ import static org .apache .solr .common .params .DisMaxParams .PS ;
25+ import static org .apache .solr .common .params .DisMaxParams .QS ;
26+ import static org .apache .solr .common .params .DisMaxParams .TIE ;
27+ import static org .apache .solr .common .params .SimpleParams .QF ;
28+
1829import java .util .ArrayList ;
1930import java .util .Collection ;
2031import java .util .List ;
2132import java .util .Map .Entry ;
22-
2333import org .apache .commons .lang3 .StringUtils ;
2434import org .apache .solr .client .solrj .SolrQuery ;
2535import org .apache .solr .client .solrj .SolrQuery .ORDER ;
3545import org .springframework .data .domain .Sort ;
3646import org .springframework .data .domain .Sort .Order ;
3747import org .springframework .data .mapping .context .MappingContext ;
38- import org .springframework .data .solr .core .query .*;
39- import org .springframework .data .solr .core .query .Criteria .Predicate ;
48+ import org .springframework .data .solr .core .query .Criteria ;
49+ import org .springframework .data .solr .core .query .DisMaxOptions ;
50+ import org .springframework .data .solr .core .query .DisMaxQuery ;
51+ import org .springframework .data .solr .core .query .FacetOptions ;
4052import org .springframework .data .solr .core .query .FacetOptions .FacetParameter ;
4153import org .springframework .data .solr .core .query .FacetOptions .FieldWithDateRangeParameters ;
4254import org .springframework .data .solr .core .query .FacetOptions .FieldWithFacetParameters ;
4355import org .springframework .data .solr .core .query .FacetOptions .FieldWithNumericRangeParameters ;
4456import org .springframework .data .solr .core .query .FacetOptions .FieldWithRangeParameters ;
57+ import org .springframework .data .solr .core .query .FacetQuery ;
58+ import org .springframework .data .solr .core .query .Field ;
59+ import org .springframework .data .solr .core .query .FilterQuery ;
60+ import org .springframework .data .solr .core .query .Function ;
4561import org .springframework .data .solr .core .query .Function .Context .Target ;
62+ import org .springframework .data .solr .core .query .GroupOptions ;
63+ import org .springframework .data .solr .core .query .HighlightOptions ;
4664import org .springframework .data .solr .core .query .HighlightOptions .FieldWithHighlightParameters ;
4765import org .springframework .data .solr .core .query .HighlightOptions .HighlightParameter ;
66+ import org .springframework .data .solr .core .query .HighlightQuery ;
67+ import org .springframework .data .solr .core .query .PivotField ;
68+ import org .springframework .data .solr .core .query .Query ;
69+ import org .springframework .data .solr .core .query .QueryParameter ;
70+ import org .springframework .data .solr .core .query .SolrDataQuery ;
71+ import org .springframework .data .solr .core .query .SpellcheckOptions ;
72+ import org .springframework .data .solr .core .query .StatsOptions ;
4873import org .springframework .lang .Nullable ;
4974import org .springframework .util .Assert ;
5075import org .springframework .util .CollectionUtils ;
6590 * @author Joachim Uhrlaß
6691 * @author Petar Tahchiev
6792 * @author Juan Manuel de Blas
93+ * @author Matthew Hall
6894 */
6995public class DefaultQueryParser extends QueryParserBase <SolrDataQuery > {
7096
@@ -109,6 +135,10 @@ public final SolrQuery doConstructSolrQuery(SolrDataQuery query, @Nullable Class
109135 processHighlightOptions (solrQuery , (HighlightQuery ) query , domainType );
110136 }
111137
138+ if (query instanceof DisMaxQuery ) {
139+ processDisMaxOptions (solrQuery , (DisMaxQuery ) query );
140+ }
141+
112142 return solrQuery ;
113143 }
114144
@@ -132,6 +162,38 @@ private void processQueryOptions(SolrQuery solrQuery, Query query, @Nullable Cla
132162 LOGGER .debug ("Constructed SolrQuery:\r \n {}" , solrQuery );
133163 }
134164
165+ protected void processDisMaxOptions (SolrQuery solrQuery , DisMaxQuery disMaxQuery ) {
166+
167+ if (disMaxQuery == null || disMaxQuery .getDisMaxOptions () == null ) {
168+ return ;
169+ }
170+
171+ DisMaxOptions disMaxOptions = disMaxQuery .getDisMaxOptions ();
172+
173+ solrQuery .set ("defType" , "dismax" );
174+
175+ setSolrParamIfPresent (solrQuery , DF , disMaxOptions .getDefaultField ());
176+
177+ setSolrParamIfPresent (solrQuery , ALTQ , disMaxOptions .getAltQuery ());
178+ setSolrParamIfPresent (solrQuery , QF , disMaxOptions .getQueryFunction ());
179+ setSolrParamIfPresent (solrQuery , MM , disMaxOptions .getMinimumMatch ());
180+
181+ setSolrParamIfPresent (solrQuery , BQ , disMaxOptions .getBoostQuery ());
182+ setSolrParamIfPresent (solrQuery , BF , disMaxOptions .getBoostFunction ());
183+ setSolrParamIfPresent (solrQuery , PF , disMaxOptions .getPhraseFunction ());
184+
185+ setSolrParamIfPresent (solrQuery , PS , disMaxOptions .getPhraseSlop () == null ? null :
186+ String .valueOf (disMaxOptions .getPhraseSlop ()));
187+ setSolrParamIfPresent (solrQuery , QS , disMaxOptions .getQuerySlop () == null ? null : String .valueOf (disMaxOptions .getQuerySlop ()));
188+ setSolrParamIfPresent (solrQuery , TIE , disMaxOptions .getTie () == null ? null : String .valueOf (disMaxOptions .getTie ()));
189+ }
190+
191+ private static void setSolrParamIfPresent (SolrQuery solrQuery , String param , String value ) {
192+ if (!org .springframework .util .StringUtils .isEmpty (value )) {
193+ solrQuery .setParam (param , value );
194+ }
195+ }
196+
135197 private void processFacetOptions (SolrQuery solrQuery , FacetQuery query , @ Nullable Class <?> domainType ) {
136198
137199 if (enableFaceting (solrQuery , query )) {
0 commit comments