This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
/
IndexingContext.java
266 lines (223 loc) · 6.82 KB
/
IndexingContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
* Copyright (c) 2007-2008 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package org.sonatype.nexus.index.context;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.sonatype.nexus.artifact.GavCalculator;
/**
* An indexing context is representing artifact repository for indexing and searching. Indexing context is a statefull
* component, it keeps state of index readers and writers.
*
* @author Jason van Zyl
* @author Tamas Cservenak
* @author Eugene Kuleshov
*/
public interface IndexingContext
{
/**
* Standard name of the full repository index that is used when clients requesting index information have nothing to
* start with.
*/
public static final String INDEX_FILE = "nexus-maven-repository-index";
/**
* A prefix used for all index property names
*/
public static final String INDEX_PROPERTY_PREFIX = "nexus.index.";
/**
* A property name used to specify index id
*/
public static final String INDEX_ID = INDEX_PROPERTY_PREFIX + "id";
/**
* A property name used to specify legacy index timestam (the last update time)
*/
public static final String INDEX_LEGACY_TIMESTAMP = INDEX_PROPERTY_PREFIX + "time";
/**
* A property name used to specify index timtestamp
*/
public static final String INDEX_TIMESTAMP = INDEX_PROPERTY_PREFIX + "timestamp";
/**
* A prefix used to specify an incremental update chunk name
*/
public static final String INDEX_CHUNK_PREFIX = INDEX_PROPERTY_PREFIX + "incremental-";
/**
* A date format used for index timestamp
*/
public static final String INDEX_TIME_FORMAT = "yyyyMMddHHmmss.SSS Z";
/**
* A date format used for incremental update chunk names
*/
public static final String INDEX_TIME_DAY_FORMAT = "yyyyMMdd";
/**
* A counter used to id the chunks
*/
public static final String INDEX_CHUNK_COUNTER = INDEX_PROPERTY_PREFIX + "last-incremental";
/**
* An id that defines the current incremental chain. If when checking remote repo, the index chain doesnt match
* you'll know that you need to download the full index
*/
public static final String INDEX_CHAIN_ID = INDEX_PROPERTY_PREFIX + "chain-id";
/**
* Returns this indexing context id.
*/
String getId();
/**
* Returns repository id.
*/
String getRepositoryId();
/**
* Returns location for the local repository.
*/
File getRepository();
/**
* Returns public repository url.
*/
String getRepositoryUrl();
/**
* Returns url for the index update
*/
String getIndexUpdateUrl();
/**
* Is the context searchable when doing "non-targeted" searches? Ie. Should it take a part when searching without
* specifying context?
*
* @return
*/
boolean isSearchable();
/**
* Sets is the context searchable when doing "non-targeted" searches.
*
* @param searchable
*/
void setSearchable( boolean searchable );
/**
* Returns index update time
*/
Date getTimestamp();
void updateTimestamp()
throws IOException;
void updateTimestamp( boolean save )
throws IOException;
void updateTimestamp( boolean save, Date date )
throws IOException;
/**
* Returns the Lucene IndexReader of this context.
*
* @return reader
* @throws IOException
*/
IndexReader getIndexReader()
throws IOException;
/**
* Returns the Lucene IndexSearcher of this context.
*
* @return searcher
* @throws IOException
*/
IndexSearcher getIndexSearcher()
throws IOException;
/**
* Returns the Lucene IndexWriter of this context.
*
* @return indexWriter
* @throws IOException
*/
IndexWriter getIndexWriter()
throws IOException;
/**
* List of IndexCreators used in this context.
*
* @return list of index creators.
*/
List<IndexCreator> getIndexCreators();
/**
* Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher. Note: this method always
* creates a new instance of analyzer!
*
* @return
*/
Analyzer getAnalyzer();
/**
* Optimizes index
*/
void optimize()
throws CorruptIndexException, IOException;
/**
* Shuts down this context.
*/
void close( boolean deleteFiles )
throws IOException;
/**
* Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state.
*
* @throws IOException
*/
void purge()
throws IOException;
/**
* Merges content of given Lucene directory with this context.
*
* @param directory - the directory to merge
*/
void merge( Directory directory )
throws IOException;
/**
* Merges content of given Lucene directory with this context, but filters out the unwanted ones.
*
* @param directory - the directory to merge
*/
void merge( Directory directory, DocumentFilter filter )
throws IOException;
/**
* Replaces the Lucene index with the one from supplied directory.
*
* @param directory
* @throws IOException
*/
void replace( Directory directory )
throws IOException;
Directory getIndexDirectory();
File getIndexDirectoryFile();
/**
* Returns the GavCalculator for this Context. Implies repository layout.
*/
GavCalculator getGavCalculator();
/**
* Sets all group names stored in the current indexing context
*/
void setAllGroups( Collection<String> groups )
throws IOException;
/**
* Gets all group names stored in the current indexing context
*/
Set<String> getAllGroups()
throws IOException;
/**
* Sets root group names stored in the current indexing context
*/
void setRootGroups( Collection<String> groups )
throws IOException;
/**
* Gets root group names stored in the current indexing context
*/
Set<String> getRootGroups()
throws IOException;
/**
* Rebuilds stored group names from the index
*/
void rebuildGroups()
throws IOException;
}