20
20
package org .elasticsearch .index .query .support ;
21
21
22
22
import org .apache .lucene .analysis .Analyzer ;
23
+ import org .apache .lucene .index .Term ;
23
24
import org .apache .lucene .queryParser .ParseException ;
24
25
import org .apache .lucene .queryParser .QueryParser ;
25
26
import org .apache .lucene .search .BooleanClause ;
@@ -52,6 +53,8 @@ public class MapperQueryParser extends QueryParser {
52
53
53
54
private final FilterCache filterCache ;
54
55
56
+ private FieldMapper currentMapper ;
57
+
55
58
public MapperQueryParser (String defaultField , Analyzer analyzer ,
56
59
@ Nullable MapperService mapperService ,
57
60
@ Nullable FilterCache filterCache ) {
@@ -61,17 +64,28 @@ public MapperQueryParser(String defaultField, Analyzer analyzer,
61
64
setMultiTermRewriteMethod (MultiTermQuery .CONSTANT_SCORE_AUTO_REWRITE_DEFAULT );
62
65
}
63
66
67
+ @ Override protected Query newTermQuery (Term term ) {
68
+ if (currentMapper != null ) {
69
+ Query termQuery = currentMapper .queryStringTermQuery (term );
70
+ if (termQuery != null ) {
71
+ return termQuery ;
72
+ }
73
+ }
74
+ return super .newTermQuery (term );
75
+ }
76
+
64
77
@ Override public Query getFieldQuery (String field , String queryText ) throws ParseException {
78
+ currentMapper = null ;
65
79
if (mapperService != null ) {
66
80
MapperService .SmartNameFieldMappers fieldMappers = mapperService .smartName (field );
67
81
if (fieldMappers != null ) {
68
- FieldMapper mapper = fieldMappers .fieldMappers ().mapper ();
69
- if (mapper != null ) {
82
+ currentMapper = fieldMappers .fieldMappers ().mapper ();
83
+ if (currentMapper != null ) {
70
84
Query query ;
71
- if (mapper .useFieldQueryWithQueryString ()) {
72
- query = fieldMappers . fieldMappers (). mapper () .fieldQuery (queryText );
85
+ if (currentMapper .useFieldQueryWithQueryString ()) {
86
+ query = currentMapper .fieldQuery (queryText );
73
87
} else {
74
- query = super .getFieldQuery (mapper .names ().indexName (), queryText );
88
+ query = super .getFieldQuery (currentMapper .names ().indexName (), queryText );
75
89
}
76
90
return wrapSmartNameQuery (query , fieldMappers , filterCache );
77
91
}
@@ -87,11 +101,13 @@ public MapperQueryParser(String defaultField, Analyzer analyzer,
87
101
if ("*" .equals (part2 )) {
88
102
part2 = null ;
89
103
}
104
+ currentMapper = null ;
90
105
if (mapperService != null ) {
91
106
MapperService .SmartNameFieldMappers fieldMappers = mapperService .smartName (field );
92
107
if (fieldMappers != null ) {
93
- if (fieldMappers .fieldMappers ().mapper () != null ) {
94
- Query rangeQuery = fieldMappers .fieldMappers ().mapper ().rangeQuery (part1 , part2 , inclusive , inclusive );
108
+ currentMapper = fieldMappers .fieldMappers ().mapper ();
109
+ if (currentMapper != null ) {
110
+ Query rangeQuery = currentMapper .rangeQuery (part1 , part2 , inclusive , inclusive );
95
111
return wrapSmartNameQuery (rangeQuery , fieldMappers , filterCache );
96
112
}
97
113
}
@@ -101,11 +117,13 @@ public MapperQueryParser(String defaultField, Analyzer analyzer,
101
117
102
118
@ Override protected Query getPrefixQuery (String field , String termStr ) throws ParseException {
103
119
String indexedNameField = field ;
120
+ currentMapper = null ;
104
121
if (mapperService != null ) {
105
122
MapperService .SmartNameFieldMappers fieldMappers = mapperService .smartName (field );
106
123
if (fieldMappers != null ) {
107
- if (fieldMappers .fieldMappers ().mapper () != null ) {
108
- indexedNameField = fieldMappers .fieldMappers ().mapper ().names ().indexName ();
124
+ currentMapper = fieldMappers .fieldMappers ().mapper ();
125
+ if (currentMapper != null ) {
126
+ indexedNameField = currentMapper .names ().indexName ();
109
127
}
110
128
return wrapSmartNameQuery (super .getPrefixQuery (indexedNameField , termStr ), fieldMappers , filterCache );
111
129
}
@@ -115,11 +133,13 @@ public MapperQueryParser(String defaultField, Analyzer analyzer,
115
133
116
134
@ Override protected Query getFuzzyQuery (String field , String termStr , float minSimilarity ) throws ParseException {
117
135
String indexedNameField = field ;
136
+ currentMapper = null ;
118
137
if (mapperService != null ) {
119
138
MapperService .SmartNameFieldMappers fieldMappers = mapperService .smartName (field );
120
139
if (fieldMappers != null ) {
121
- if (fieldMappers .fieldMappers ().mapper () != null ) {
122
- indexedNameField = fieldMappers .fieldMappers ().mapper ().names ().indexName ();
140
+ currentMapper = fieldMappers .fieldMappers ().mapper ();
141
+ if (currentMapper != null ) {
142
+ indexedNameField = currentMapper .names ().indexName ();
123
143
}
124
144
return wrapSmartNameQuery (super .getFuzzyQuery (indexedNameField , termStr , minSimilarity ), fieldMappers , filterCache );
125
145
}
@@ -129,11 +149,13 @@ public MapperQueryParser(String defaultField, Analyzer analyzer,
129
149
130
150
@ Override protected Query getWildcardQuery (String field , String termStr ) throws ParseException {
131
151
String indexedNameField = field ;
152
+ currentMapper = null ;
132
153
if (mapperService != null ) {
133
154
MapperService .SmartNameFieldMappers fieldMappers = mapperService .smartName (field );
134
155
if (fieldMappers != null ) {
135
- if (fieldMappers .fieldMappers ().mapper () != null ) {
136
- indexedNameField = fieldMappers .fieldMappers ().mapper ().names ().indexName ();
156
+ currentMapper = fieldMappers .fieldMappers ().mapper ();
157
+ if (currentMapper != null ) {
158
+ indexedNameField = currentMapper .names ().indexName ();
137
159
}
138
160
return wrapSmartNameQuery (super .getWildcardQuery (indexedNameField , termStr ), fieldMappers , filterCache );
139
161
}
0 commit comments