22
22
import org .apache .logging .log4j .LogManager ;
23
23
import org .apache .lucene .analysis .Analyzer ;
24
24
import org .apache .lucene .index .IndexReader ;
25
- import org .apache .lucene .index .IndexReaderContext ;
26
25
import org .apache .lucene .search .IndexSearcher ;
27
26
import org .apache .lucene .search .Query ;
28
27
import org .apache .lucene .search .join .BitSetProducer ;
37
36
import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
38
37
import org .elasticsearch .common .logging .DeprecationLogger ;
39
38
import org .elasticsearch .common .lucene .search .Queries ;
39
+ import org .elasticsearch .common .util .BigArrays ;
40
40
import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
41
41
import org .elasticsearch .common .xcontent .XContentParser ;
42
42
import org .elasticsearch .index .Index ;
68
68
import java .util .Set ;
69
69
import java .util .function .BiConsumer ;
70
70
import java .util .function .BiFunction ;
71
- import java .util .function .Function ;
72
71
import java .util .function .LongSupplier ;
73
72
74
73
import static java .util .Collections .unmodifiableMap ;
@@ -84,13 +83,13 @@ public class QueryShardContext extends QueryRewriteContext {
84
83
85
84
private final ScriptService scriptService ;
86
85
private final IndexSettings indexSettings ;
86
+ private final BigArrays bigArrays ;
87
87
private final MapperService mapperService ;
88
88
private final SimilarityService similarityService ;
89
89
private final BitsetFilterCache bitsetFilterCache ;
90
- private final Function <IndexReaderContext , IndexSearcher > searcherFactory ;
91
90
private final BiFunction <MappedFieldType , String , IndexFieldData <?>> indexFieldDataService ;
92
91
private final int shardId ;
93
- private final IndexReader reader ;
92
+ private final IndexSearcher searcher ;
94
93
private String [] types = Strings .EMPTY_ARRAY ;
95
94
private boolean cacheable = true ;
96
95
private final SetOnce <Boolean > frozen = new SetOnce <>();
@@ -109,42 +108,58 @@ public String[] getTypes() {
109
108
private boolean mapUnmappedFieldAsString ;
110
109
private NestedScope nestedScope ;
111
110
112
- public QueryShardContext (int shardId , IndexSettings indexSettings , BitsetFilterCache bitsetFilterCache ,
113
- Function <IndexReaderContext , IndexSearcher > searcherFactory ,
114
- BiFunction <MappedFieldType , String , IndexFieldData <?>> indexFieldDataLookup , MapperService mapperService ,
115
- SimilarityService similarityService , ScriptService scriptService , NamedXContentRegistry xContentRegistry ,
116
- NamedWriteableRegistry namedWriteableRegistry , Client client , IndexReader reader , LongSupplier nowInMillis ,
117
- String clusterAlias ) {
118
- this (shardId , indexSettings , bitsetFilterCache , searcherFactory , indexFieldDataLookup , mapperService , similarityService ,
119
- scriptService , xContentRegistry , namedWriteableRegistry , client , reader , nowInMillis ,
111
+ public QueryShardContext (int shardId ,
112
+ IndexSettings indexSettings ,
113
+ BigArrays bigArrays ,
114
+ BitsetFilterCache bitsetFilterCache ,
115
+ BiFunction <MappedFieldType , String , IndexFieldData <?>> indexFieldDataLookup ,
116
+ MapperService mapperService ,
117
+ SimilarityService similarityService ,
118
+ ScriptService scriptService ,
119
+ NamedXContentRegistry xContentRegistry ,
120
+ NamedWriteableRegistry namedWriteableRegistry ,
121
+ Client client ,
122
+ IndexSearcher searcher ,
123
+ LongSupplier nowInMillis ,
124
+ String clusterAlias ) {
125
+ this (shardId , indexSettings , bigArrays , bitsetFilterCache , indexFieldDataLookup , mapperService , similarityService ,
126
+ scriptService , xContentRegistry , namedWriteableRegistry , client , searcher , nowInMillis ,
120
127
new Index (RemoteClusterAware .buildRemoteIndexName (clusterAlias , indexSettings .getIndex ().getName ()),
121
128
indexSettings .getIndex ().getUUID ()));
122
129
}
123
130
124
131
public QueryShardContext (QueryShardContext source ) {
125
- this (source .shardId , source .indexSettings , source .bitsetFilterCache , source .searcherFactory , source .indexFieldDataService ,
132
+ this (source .shardId , source .indexSettings , source .bigArrays , source .bitsetFilterCache , source .indexFieldDataService ,
126
133
source .mapperService , source .similarityService , source .scriptService , source .getXContentRegistry (),
127
- source .getWriteableRegistry (), source .client , source .reader , source .nowInMillis , source .fullyQualifiedIndex );
128
- }
129
-
130
- private QueryShardContext (int shardId , IndexSettings indexSettings , BitsetFilterCache bitsetFilterCache ,
131
- Function <IndexReaderContext , IndexSearcher > searcherFactory ,
132
- BiFunction <MappedFieldType , String , IndexFieldData <?>> indexFieldDataLookup , MapperService mapperService ,
133
- SimilarityService similarityService , ScriptService scriptService , NamedXContentRegistry xContentRegistry ,
134
- NamedWriteableRegistry namedWriteableRegistry , Client client , IndexReader reader , LongSupplier nowInMillis ,
135
- Index fullyQualifiedIndex ) {
134
+ source .getWriteableRegistry (), source .client , source .searcher , source .nowInMillis , source .fullyQualifiedIndex );
135
+ }
136
+
137
+ private QueryShardContext (int shardId ,
138
+ IndexSettings indexSettings ,
139
+ BigArrays bigArrays ,
140
+ BitsetFilterCache bitsetFilterCache ,
141
+ BiFunction <MappedFieldType , String , IndexFieldData <?>> indexFieldDataLookup ,
142
+ MapperService mapperService ,
143
+ SimilarityService similarityService ,
144
+ ScriptService scriptService ,
145
+ NamedXContentRegistry xContentRegistry ,
146
+ NamedWriteableRegistry namedWriteableRegistry ,
147
+ Client client ,
148
+ IndexSearcher searcher ,
149
+ LongSupplier nowInMillis ,
150
+ Index fullyQualifiedIndex ) {
136
151
super (xContentRegistry , namedWriteableRegistry , client , nowInMillis );
137
152
this .shardId = shardId ;
138
153
this .similarityService = similarityService ;
139
154
this .mapperService = mapperService ;
140
155
this .bitsetFilterCache = bitsetFilterCache ;
141
- this .searcherFactory = searcherFactory ;
142
156
this .indexFieldDataService = indexFieldDataLookup ;
143
157
this .allowUnmappedFields = indexSettings .isDefaultAllowUnmappedFields ();
144
158
this .nestedScope = new NestedScope ();
145
159
this .scriptService = scriptService ;
146
160
this .indexSettings = indexSettings ;
147
- this .reader = reader ;
161
+ this .bigArrays = bigArrays ;
162
+ this .searcher = searcher ;
148
163
this .fullyQualifiedIndex = fullyQualifiedIndex ;
149
164
}
150
165
@@ -183,10 +198,6 @@ public BitSetProducer bitsetFilter(Query filter) {
183
198
return bitsetFilterCache .getBitSetProducer (filter );
184
199
}
185
200
186
- public IndexSearcher newCachedSearcher (IndexReaderContext context ) {
187
- return searcherFactory .apply (context );
188
- }
189
-
190
201
public <IFD extends IndexFieldData <?>> IFD getForField (MappedFieldType fieldType ) {
191
202
return (IFD ) indexFieldDataService .apply (fieldType , fullyQualifiedIndex .getName ());
192
203
}
@@ -424,7 +435,13 @@ public MapperService getMapperService() {
424
435
/** Return the current {@link IndexReader}, or {@code null} if no index reader is available,
425
436
* for instance if this rewrite context is used to index queries (percolation). */
426
437
public IndexReader getIndexReader () {
427
- return reader ;
438
+ return searcher != null ? searcher .getIndexReader () : null ;
439
+ }
440
+
441
+ /** Return the current {@link IndexSearcher}, or {@code null} if no index reader is available,
442
+ * for instance if this rewrite context is used to index queries (percolation). */
443
+ public IndexSearcher searcher () {
444
+ return searcher ;
428
445
}
429
446
430
447
/**
@@ -433,4 +450,11 @@ public IndexReader getIndexReader() {
433
450
public Index getFullyQualifiedIndex () {
434
451
return fullyQualifiedIndex ;
435
452
}
453
+
454
+ /**
455
+ * Return the {@link BigArrays} instance for this node.
456
+ */
457
+ public BigArrays bigArrays () {
458
+ return bigArrays ;
459
+ }
436
460
}
0 commit comments