71
71
import org .opensolaris .opengrok .history .HistoryException ;
72
72
import org .opensolaris .opengrok .history .HistoryGuru ;
73
73
import org .opensolaris .opengrok .history .HistoryReader ;
74
+ import org .opensolaris .opengrok .search .QueryBuilder ;
74
75
import org .opensolaris .opengrok .web .Util ;
75
76
76
77
/**
77
78
* Manages and provides Analyzers as needed. Please see
78
- * <a href="http ://www.opensolaris.org/os/project/opengrok/manual/internals/ ">
79
+ * <a href="https ://github.com/OpenGrok/OpenGrok/wiki/OpenGrok-Internals ">
79
80
* this</a> page for a great description of the purpose of the AnalyzerGuru.
80
81
*
81
82
* Created on September 22, 2005
@@ -89,27 +90,27 @@ public class AnalyzerGuru {
89
90
90
91
/** Map from file names to analyzer factories. */
91
92
private static final Map <String , FileAnalyzerFactory >
92
- FILE_NAMES = new HashMap <String , FileAnalyzerFactory >();
93
+ FILE_NAMES = new HashMap <>();
93
94
94
95
/** Map from file extensions to analyzer factories. */
95
96
private static final Map <String , FileAnalyzerFactory >
96
- ext = new HashMap <String , FileAnalyzerFactory >();
97
+ ext = new HashMap <>();
97
98
98
99
// @TODO: have a comparator
99
100
/** Map from magic strings to analyzer factories. */
100
101
private static final SortedMap <String , FileAnalyzerFactory >
101
- magics = new TreeMap <String , FileAnalyzerFactory >();
102
+ magics = new TreeMap <>();
102
103
103
104
/**
104
105
* List of matcher objects which can be used to determine which analyzer
105
106
* factory to use.
106
107
*/
107
108
private static final List <FileAnalyzerFactory .Matcher >
108
- matchers = new ArrayList <FileAnalyzerFactory . Matcher >();
109
+ matchers = new ArrayList <>();
109
110
110
111
/** List of all registered {@code FileAnalyzerFactory} instances. */
111
112
private static final List <FileAnalyzerFactory >
112
- factories = new ArrayList <FileAnalyzerFactory >();
113
+ factories = new ArrayList <>();
113
114
114
115
public static final Reader dummyR = new StringReader ("" );
115
116
public static final String dummyS = "" ;
@@ -237,41 +238,41 @@ public static FileAnalyzer getAnalyzer(InputStream in, String file) throws IOExc
237
238
* @param xrefOut Where to write the xref (possibly {@code null})
238
239
* @return The Lucene document to add to the index database
239
240
* @throws java.io.IOException If an exception occurs while collecting the
240
- * datas
241
+ * data
241
242
*/
242
243
public Document getDocument (File file , String path ,
243
244
FileAnalyzer fa , Writer xrefOut )
244
245
throws IOException {
245
246
Document doc = new Document ();
246
247
String date = DateTools .timeToString (file .lastModified (),
247
248
DateTools .Resolution .MILLISECOND );
248
- doc .add (new Field ("u" , Util .path2uid (path , date ),
249
+ doc .add (new Field (QueryBuilder . U , Util .path2uid (path , date ),
249
250
string_ft_stored_nanalyzed_norms ));
250
- doc .add (new Field ("fullpath" , file .getAbsolutePath (),
251
+ doc .add (new Field (QueryBuilder . FULLPATH , file .getAbsolutePath (),
251
252
string_ft_nstored_nanalyzed_norms ));
252
253
253
254
try {
254
255
HistoryReader hr = HistoryGuru .getInstance ().getHistoryReader (file );
255
256
if (hr != null ) {
256
- doc .add (new TextField ("hist" , hr ));
257
+ doc .add (new TextField (QueryBuilder . HIST , hr ));
257
258
// date = hr.getLastCommentDate() //RFE
258
259
}
259
260
} catch (HistoryException e ) {
260
261
OpenGrokLogger .getLogger ().log (Level .WARNING , "An error occurred while reading history: " , e );
261
262
}
262
- doc .add (new Field ("date" , date , string_ft_stored_nanalyzed_norms ));
263
+ doc .add (new Field (QueryBuilder . DATE , date , string_ft_stored_nanalyzed_norms ));
263
264
if (path != null ) {
264
- doc .add (new TextField ("path" , path , Store .YES ));
265
+ doc .add (new TextField (QueryBuilder . PATH , path , Store .YES ));
265
266
Project project = Project .getProject (path );
266
267
if (project != null ) {
267
- doc .add (new TextField ("project" , project .getPath (), Store .YES ));
268
+ doc .add (new TextField (QueryBuilder . PROJECT , project .getPath (), Store .YES ));
268
269
}
269
270
}
270
271
271
272
if (fa != null ) {
272
273
Genre g = fa .getGenre ();
273
274
if (g == Genre .PLAIN || g == Genre .XREFABLE || g == Genre .HTML ) {
274
- doc .add (new Field ("t" , g .typeName (), string_ft_stored_nanalyzed_norms
275
+ doc .add (new Field (QueryBuilder . T , g .typeName (), string_ft_stored_nanalyzed_norms
275
276
));
276
277
}
277
278
fa .analyze (doc , StreamSource .fromFile (file ), xrefOut );
@@ -301,9 +302,9 @@ public static String getContentType(InputStream in, String file) throws IOExcept
301
302
}
302
303
303
304
/**
304
- * Write a browsable version of the file
305
+ * Write a browse-able version of the file
305
306
*
306
- * @param factory The analyzer factory for this filetype
307
+ * @param factory The analyzer factory for this file type
307
308
* @param in The input stream containing the data
308
309
* @param out Where to write the result
309
310
* @param defs definitions for the source file, if available
@@ -329,7 +330,7 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in,
329
330
/**
330
331
* Get the genre of a file
331
332
*
332
- * @param file The file to inpect
333
+ * @param file The file to inspect
333
334
* @return The genre suitable to decide how to display the file
334
335
*/
335
336
public static Genre getGenre (String file ) {
@@ -440,7 +441,7 @@ public static FileAnalyzerFactory find(InputStream in, String file)
440
441
*/
441
442
public static FileAnalyzerFactory find (String file ) {
442
443
String path = file ;
443
- int i = 0 ;
444
+ int i ;
444
445
if (((i = path .lastIndexOf ('/' )) > 0 || (i = path .lastIndexOf ('\\' )) > 0 )
445
446
&& (i + 1 < path .length ())) {
446
447
path = path .substring (i + 1 );
@@ -458,7 +459,7 @@ public static FileAnalyzerFactory find(String file) {
458
459
}
459
460
460
461
/**
461
- * Finds a suitable analyser class for the data in this stream
462
+ * Finds a suitable analyzer class for the data in this stream
462
463
*
463
464
* @param in The stream containing the data to analyze
464
465
* @return the analyzer factory to use
@@ -497,7 +498,7 @@ public static FileAnalyzerFactory find(InputStream in) throws IOException {
497
498
}
498
499
499
500
/**
500
- * Finds a suitable analyser class for a magic signature
501
+ * Finds a suitable analyzer class for a magic signature
501
502
*
502
503
* @param signature the magic signature look up
503
504
* @return the analyzer factory to use
@@ -536,7 +537,7 @@ private static FileAnalyzerFactory find(byte[] signature)
536
537
537
538
/** Byte-order markers. */
538
539
private static final Map <String , byte []> BOMS =
539
- new HashMap <String , byte [] >();
540
+ new HashMap <>();
540
541
static {
541
542
BOMS .put ("UTF-8" , new byte [] {(byte ) 0xEF , (byte ) 0xBB , (byte ) 0xBF });
542
543
BOMS .put ("UTF-16BE" , new byte [] {(byte ) 0xFE , (byte ) 0xFF });
0 commit comments