@@ -98,6 +98,8 @@ class SuggesterProjectData implements Closeable {
98
98
99
99
private final ReadWriteLock lock = new ReentrantReadWriteLock ();
100
100
101
+ private final Set <String > allowedFields ;
102
+
101
103
private Set <String > fields ;
102
104
103
105
private final Directory tempDir ;
@@ -106,34 +108,35 @@ class SuggesterProjectData implements Closeable {
106
108
final Directory indexDir ,
107
109
final Path suggesterDir ,
108
110
final boolean allowMostPopular ,
109
- final Set <String > fields
111
+ final Set <String > allowedFields
110
112
) throws IOException {
111
113
this .indexDir = indexDir ;
112
114
this .suggesterDir = suggesterDir ;
113
115
this .allowMostPopular = allowMostPopular ;
116
+ this .allowedFields = allowedFields ;
114
117
115
118
tempDir = FSDirectory .open (Paths .get (System .getProperty (TMP_DIR_PROPERTY )));
116
119
117
- initFields (fields );
120
+ initFields ();
118
121
}
119
122
120
- private void initFields (final Set < String > fields ) throws IOException {
123
+ private void initFields () throws IOException {
121
124
try (IndexReader indexReader = DirectoryReader .open (indexDir )) {
122
125
Collection <String > indexedFields = FieldInfos .getIndexedFields (indexReader );
123
- if (fields == null ) {
126
+ if (allowedFields == null ) {
124
127
this .fields = new HashSet <>(indexedFields );
125
- } else if (!indexedFields .containsAll (fields )) {
126
- Set <String > copy = new HashSet <>(fields );
128
+ } else if (!indexedFields .containsAll (allowedFields )) {
129
+ Set <String > copy = new HashSet <>(allowedFields );
127
130
copy .removeAll (indexedFields );
128
131
logger .log (Level .WARNING ,
129
132
"Fields {0} will be ignored because they were not found in index directory {1}" ,
130
133
new Object [] {copy , indexDir });
131
134
132
- copy = new HashSet <>(fields );
135
+ copy = new HashSet <>(allowedFields );
133
136
copy .retainAll (indexedFields );
134
137
this .fields = copy ;
135
138
} else {
136
- this .fields = new HashSet <>(fields );
139
+ this .fields = new HashSet <>(allowedFields );
137
140
}
138
141
}
139
142
}
@@ -231,6 +234,7 @@ private File getFile(final String fileName) {
231
234
public void rebuild () throws IOException {
232
235
lock .writeLock ().lock ();
233
236
try {
237
+ initFields ();
234
238
build ();
235
239
236
240
if (allowMostPopular ) {
0 commit comments