SupoSE-SolrIntegration.diff

Julian Hochstetter, 07/02/2010 06:22 PM

Download (201.5 KB)

 
supose/pom.xml 2010-07-02 18:19:30.000000000 +0200
24 24
		<quartz.version>1.7.3</quartz.version>
25 25
		<ini4j.version>0.5.1</ini4j.version>
26 26
		<lucene.version>2.4.0</lucene.version>
27
		<tika.version>0.7</tika.version>
27
		<tika.version>0.8-SNAPSHOT</tika.version>
28
		<solr.version>1.4.0</solr.version>
28 29
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29 30
	</properties>
30 31

  
......
526 527
			<version>${lucene.version}</version>
527 528
		</dependency>
528 529
		<dependency>
530
			<groupId>org.apache.solr</groupId>
531
			<artifactId>solr-core</artifactId>
532
			<version>${solr.version}</version>
533
		</dependency>
534
		<dependency>
529 535
			<groupId>org.quartz-scheduler</groupId>
530 536
			<artifactId>quartz</artifactId>
531 537
			<version>${quartz.version}</version>
......
561 567
			<version>1.2.14</version>
562 568
		</dependency>
563 569
		<dependency>
570
		  <groupId>org.slf4j</groupId>
571
		  <artifactId>slf4j-log4j12</artifactId>
572
		  <version>1.6.0</version>
573
		</dependency>
574
		<dependency>
564 575
			<groupId>xml-apis</groupId>
565 576
			<artifactId>xml-apis</artifactId>
566 577
			<version>1.0.b2</version>
supose/src/main/antlr3/grammars/com/soebes/supose/parse/php/Php.g 2010-06-29 14:52:25.000000000 +0200
1
//Todo: Labels and goto have been disabled, need to test on 5.3 
2

  
3
grammar Php;
4

  
5
options {
6
    backtrack = true; 
7
    memoize = true;
8
    k=2;
9
    output = AST;
10
    ASTLabelType = CommonTree;
11
}
12

  
13
tokens{
14
    SemiColon = ';';
15
    Comma = ',';
16
    OpenBrace = '(';
17
    CloseBrace = ')';
18
    OpenSquareBrace = '[';
19
    CloseSquareBrace = ']';
20
    OpenCurlyBrace = '{';
21
    CloseCurlyBrace = '}';
22
    ArrayAssign = '=>';
23
    LogicalOr = '||';
24
    LogicalAnd = '&&';
25
    ClassMember = '::';
26
    InstanceMember = '->';
27
    SuppressWarnings = '@';
28
    QuestionMark = '?';
29
    Dollar = '$';
30
    Colon = ':';
31
    Dot = '.';
32
    Ampersand = '&';
33
    Pipe = '|';
34
    Bang = '!';
35
    Plus = '+';
36
    Minus = '-';
37
    Asterisk = '*';
38
    Percent = '%';
39
    Forwardslash = '/'; 
40
    Tilde = '~';
41
    Equals = '=';
42
    New = 'new';
43
    Clone = 'clone';
44
    Echo = 'echo';
45
    If = 'if';
46
    Else = 'else';
47
    ElseIf = 'elseif';
48
    For = 'for';
49
    Foreach = 'foreach';
50
    While = 'while';
51
    Do = 'do';
52
    Switch = 'switch';
53
    Case = 'case';
54
    Default = 'default';
55
    Function = 'function';
56
    Break = 'break';
57
    Continue = 'continue';
58
    //Goto = 'goto';
59
    Return = 'return';
60
    Global = 'global';
61
    Static = 'static';
62
    And = 'and';
63
    Or = 'or';
64
    Xor = 'xor';
65
    Instanceof = 'instanceof';
66
    
67
    Class = 'class';
68
    Interface = 'interface';
69
    Extends = 'extends';
70
    Implements = 'implements';
71
    Abstract = 'abstract';
72
    Var = 'var';
73
    Const = 'const';
74
    Modifiers;
75
    ClassDefinition;
76
    
77
    Block;
78
    Params;
79
    Apply;
80
    Member;
81
    Reference;
82
    Empty;
83
    Prefix;
84
    Postfix;
85
    IfExpression;
86
    Label;
87
    Cast;
88
    ForInit;
89
    ForCondition;
90
    ForUpdate;
91
    Field;
92
    Method;
93
}
94

  
95
@header{
96
package com.soebes.supose.parse.php; 
97
}
98
@lexer::header{
99
package com.soebes.supose.parse.php;
100
import java.util.ArrayList;
101
}
102

  
103
@members{	
104
	private ArrayList<String> methods = new ArrayList<String>();
105
	private ArrayList<String> classes = new ArrayList<String>();
106

  
107
	public ArrayList<String> getMethods () {
108
		return methods;
109
	}
110
	private void addMethod(String name) {
111
		methods.add(name);
112
	}
113
	
114
	public ArrayList<String> getClasses () {
115
		return classes;
116
	}
117
	
118
	private void addClass(String name) {
119
		classes.add(name);
120
	}
121
}
122

  
123
@lexer::members{
124
    // Handle the first token, which will always be a BodyString.
125
    public Token nextToken(){
126
        //The following code was pulled out from super.nextToken()
127
        if (input.index() == 0) {
128
            try {
129
                state.token = null;
130
                state.channel = Token.DEFAULT_CHANNEL;
131
                state.tokenStartCharIndex = input.index();
132
                state.tokenStartCharPositionInLine = input.getCharPositionInLine();
133
                state.tokenStartLine = input.getLine();
134
                state.text = null;
135
                mFirstBodyString();
136
                state.type = BodyString;
137
                emit();
138
                return state.token;
139
            } catch (NoViableAltException nva) {
140
                reportError(nva);
141
                recover(nva); // throw out current char and try again
142
            } catch (RecognitionException re) {
143
                reportError(re);
144
                // match() routine has already called recover()
145
            }    
146
        }
147
        return super.nextToken();
148
    }
149
    
150
    private ArrayList<String> comments = new ArrayList<String>();
151

  
152
	public ArrayList<String> getComments() {
153
		return comments;
154
	}
155
	public void addComment(String comment) {
156
		comments.add(comment);
157
	}
158
}
159

  
160

  
161

  
162
prog : statement*;
163

  
164
statement
165
    : simpleStatement? BodyString
166
    | '{' statement '}' -> statement
167
    | bracketedBlock
168
    //| UnquotedString Colon statement -> ^(Label UnquotedString statement)
169
    | classDefinition
170
    | interfaceDefinition
171
    | complexStatement
172
    | simpleStatement ';'!
173
    ;
174
    
175
bracketedBlock
176
    : '{' stmts=statement* '}' -> ^(Block $stmts)
177
    ;
178

  
179
interfaceDefinition
180
    : Interface interfaceName=UnquotedString interfaceExtends?
181
        OpenCurlyBrace
182
        interfaceMember*
183
        CloseCurlyBrace
184
        -> ^(Interface $interfaceName interfaceExtends? interfaceMember*)
185
    ;
186

  
187
interfaceExtends
188
    : Extends^ UnquotedString (Comma! UnquotedString)*
189
    ;
190
interfaceMember
191
    : Const UnquotedString (Equals atom)? ';' 
192
        -> ^(Const UnquotedString atom?)
193
    | fieldModifier* Function UnquotedString parametersDefinition ';'
194
        -> ^(Method ^(Modifiers fieldModifier*) UnquotedString parametersDefinition)
195
    ;
196

  
197
classDefinition
198
    :   classModifier? 
199
        Class className=UnquotedString { addClass($className.getText()); }
200
        (Extends extendsclass=UnquotedString)? 
201
        classImplements?
202
        OpenCurlyBrace
203
        classMember*
204
        CloseCurlyBrace 
205
        -> ^(Class ^(Modifiers classModifier?) $className ^(Extends $extendsclass)? classImplements?
206
            classMember*
207
        )
208
     ;
209
    
210
classImplements
211
    :  Implements^ (UnquotedString (Comma! UnquotedString)*)
212
    ;
213

  
214
classMember
215
    : fieldModifier* Function UnquotedString parametersDefinition { addMethod($UnquotedString.getText());}
216
        (bracketedBlock | ';')
217
        -> ^(Method ^(Modifiers fieldModifier*) UnquotedString parametersDefinition bracketedBlock?)
218
        
219
    | Var Dollar UnquotedString (Equals atom)? ';' 
220
        -> ^(Var ^(Dollar UnquotedString) atom?) 
221
    | Const UnquotedString (Equals atom)? ';' 
222
        -> ^(Const UnquotedString atom?)
223
    | fieldModifier* (Dollar UnquotedString) (Equals atom)? ';' 
224
        -> ^(Field ^(Modifiers fieldModifier*) ^(Dollar UnquotedString) atom?)
225
    ;
226

  
227
fieldDefinition
228
    : Dollar UnquotedString (Equals atom)? ';'-> ^(Field ^(Dollar UnquotedString) atom?)
229
    ;
230
    
231
classModifier
232
    : 'abstract';
233
    
234
fieldModifier
235
    : AccessModifier | 'abstract' | 'static' 
236
    ;
237

  
238

  
239
complexStatement
240
    : If '(' ifCondition=expression ')' ifTrue=statement conditional?
241
        -> ^('if' expression $ifTrue conditional?)
242
    | For '(' forInit forCondition forUpdate ')' statement -> ^(For forInit forCondition forUpdate statement)
243
    | Foreach '(' variable 'as' arrayEntry ')' statement -> ^(Foreach variable arrayEntry statement)
244
    | While '(' whileCondition=expression? ')' statement -> ^(While $whileCondition statement)
245
    | Do statement While '(' doCondition=expression ')' ';' -> ^(Do statement $doCondition)
246
    | Switch '(' expression ')' '{'cases'}' -> ^(Switch expression cases)
247
    | functionDefinition
248
    ;
249

  
250
simpleStatement
251
    : Echo^ commaList
252
    | Global^ name (','! name)*
253
    | Static^ variable Equals! atom
254
    | Break^ Integer?
255
    | Continue^ Integer?
256
    //| Goto^ UnquotedString
257
    | Return^ expression?
258
    | RequireOperator^ expression
259
    | expression
260
    ;
261

  
262

  
263
conditional
264
    : ElseIf '(' ifCondition=expression ')' ifTrue=statement conditional? -> ^(If $ifCondition $ifTrue conditional?)
265
    | Else statement -> statement
266
    ;
267

  
268
forInit
269
    : commaList? ';' -> ^(ForInit commaList?)
270
    ;
271

  
272
forCondition
273
    : commaList? ';' -> ^(ForCondition commaList?)
274
    ;
275
    
276
forUpdate
277
    : commaList? -> ^(ForUpdate commaList?)
278
    ;
279

  
280
cases 
281
    : casestatement*  defaultcase
282
    ;
283

  
284
casestatement
285
    : Case^ expression ':'! statement*
286
    ;
287

  
288
defaultcase 
289
    : (Default^ ':'! statement*)
290
    ;
291

  
292
functionDefinition
293
    : Function UnquotedString parametersDefinition bracketedBlock -> 
294
        ^(Function UnquotedString parametersDefinition bracketedBlock)
295
    ;
296

  
297
parametersDefinition
298
    : OpenBrace (paramDef (Comma paramDef)*)? CloseBrace -> ^(Params paramDef*) 
299
    ;
300

  
301
paramDef
302
    : paramName (Equals^ atom)?
303
    ;
304

  
305
paramName
306
    : Dollar^ UnquotedString
307
    | Ampersand Dollar UnquotedString -> ^(Ampersand ^(Dollar UnquotedString))
308
    ;
309

  
310
commaList
311
    : expression (','! expression)* 
312
    ;
313
    
314
expression
315
    : weakLogicalOr
316
    ;
317

  
318
weakLogicalOr
319
    : weakLogicalXor (Or^ weakLogicalXor)*
320
    ;
321

  
322
weakLogicalXor
323
    : weakLogicalAnd (Xor^ weakLogicalAnd)*
324
    ;
325
    
326
weakLogicalAnd
327
    : assignment (And^ assignment)*
328
    ;
329

  
330
assignment
331
    : name ((Equals | AsignmentOperator)^ assignment)
332
    | ternary
333
    ;
334

  
335
ternary
336
    : logicalOr QuestionMark expression Colon expression -> ^(IfExpression logicalOr expression*)
337
    | logicalOr
338
    ;
339
    
340
logicalOr
341
    : logicalAnd (LogicalOr^ logicalAnd)*
342
    ;
343

  
344
logicalAnd
345
    : bitwiseOr (LogicalAnd^ bitwiseOr)*
346
    ;
347
    
348
bitwiseOr
349
    : bitWiseAnd (Pipe^ bitWiseAnd)*
350
    ;
351

  
352
bitWiseAnd
353
    : equalityCheck (Ampersand^ equalityCheck)*
354
    ;
355

  
356
equalityCheck
357
    : comparisionCheck (EqualityOperator^ comparisionCheck)?
358
    ;
359
    
360
comparisionCheck
361
    : bitWiseShift (ComparisionOperator^ bitWiseShift)?
362
    ;
363

  
364
bitWiseShift
365
    : addition (ShiftOperator^ addition)*
366
    ;
367
    
368
addition
369
    : multiplication ((Plus | Minus | Dot)^ multiplication)*
370
    ;
371

  
372
multiplication
373
    : logicalNot ((Asterisk | Forwardslash | Percent)^ logicalNot)*
374
    ;
375

  
376
logicalNot
377
    : Bang^ logicalNot
378
    | instanceOf
379
    ;
380

  
381
instanceOf
382
    : negateOrCast (Instanceof^ negateOrCast)?
383
    ;
384

  
385
negateOrCast
386
    : (Tilde | Minus | SuppressWarnings)^ increment
387
    | OpenBrace PrimitiveType CloseBrace increment -> ^(Cast PrimitiveType increment)
388
    | OpenBrace! weakLogicalAnd CloseBrace!
389
    | increment
390
    ;
391

  
392
increment
393
    : IncrementOperator name -> ^(Prefix IncrementOperator name)
394
    | name IncrementOperator -> ^(Postfix IncrementOperator name)
395
    | newOrClone
396
    ;
397

  
398
newOrClone
399
    : New^ nameOrFunctionCall
400
    | Clone^ name
401
    | atomOrReference
402
    ;
403

  
404
atomOrReference
405
    : atom
406
    | reference
407
    ;
408

  
409
arrayDeclaration
410
    : Array OpenBrace (arrayEntry (Comma arrayEntry)*)? CloseBrace -> ^(Array arrayEntry*)
411
    ;
412

  
413
arrayEntry
414
    : (keyValuePair | expression)
415
    ;
416

  
417
keyValuePair
418
    : (expression ArrayAssign expression) -> ^(ArrayAssign expression+)
419
    ;
420

  
421
atom: SingleQuotedString | DoubleQuotedString | HereDoc | Integer | Real | Boolean | arrayDeclaration
422
    ;
423

  
424
//Need to be smarter with references, they have their own tower of application.
425
reference
426
    : Ampersand^ nameOrFunctionCall
427
    | nameOrFunctionCall
428
    ;
429

  
430
nameOrFunctionCall
431
    : name OpenBrace (expression (Comma expression)*)? CloseBrace -> ^(Apply name expression*)
432
    | name
433
    ;
434

  
435
name: staticMemberAccess
436
    | memberAccess
437
    | variable
438
    ;
439
    
440
staticMemberAccess
441
    : UnquotedString '::'^ variable
442
    ;
443

  
444
memberAccess
445
    : variable 
446
        ( OpenSquareBrace^ expression CloseSquareBrace!
447
        | '->'^ UnquotedString)*
448
    ;
449
    
450
variable
451
    : Dollar^ variable
452
    | UnquotedString
453
    ;
454

  
455
BodyString 
456
    : '?>' (('<' ~ '?')=> '<' | ~'<' )* ('<?' ('php'?))?
457
    ;
458

  
459
fragment
460
FirstBodyString
461
    : (('<' ~ '?')=> '<' | ~'<' )* '<?' ('php'?)
462
    ;
463

  
464
MultilineComment    
465
    : '/*' (('*' ~ '/')=>'*' | ~ '*')* '*/' {$channel=HIDDEN;addComment(getText());}
466
    ;
467

  
468
SinglelineComment
469
    : '//'  (('?' ~'>')=>'?' | ~('\n'|'?'))* {$channel=HIDDEN;addComment(getText());}
470
    ;
471

  
472
UnixComment
473
    : '#' (('?' ~'>')=>'?' | ~('\n'|'?'))* {$channel=HIDDEN;addComment(getText());}
474
    ;
475
    
476

  
477
Array
478
    : ('a'|'A')('r'|'R')('r'|'R')('a'|'A')('y'|'Y')
479
    ;
480

  
481
RequireOperator
482
    : 'require' | 'require_once' | 'include' | 'include_once'
483
    ;
484

  
485
PrimitiveType
486
    : 'int'|'float'|'string'|'array'|'object'|'bool'
487
    ;
488

  
489
AccessModifier
490
    : 'public' | 'private' | 'protected' 
491
    ;
492

  
493
fragment
494
Decimal	
495
	:('1'..'9' ('0'..'9')*)|'0'
496
	;
497
fragment
498
Hexadecimal
499
	: '0'('x'|'X')('0'..'9'|'a'..'f'|'A'..'F')+
500
	;
501
	
502
fragment
503
Octal
504
	: '0'('0'..'7')+
505
	;
506
Integer
507
	:Octal|Decimal|Hexadecimal
508
	;
509
	
510
fragment
511
Digits
512
	: '0'..'9'+
513
	;
514
	
515
fragment
516
DNum
517
	:(('.' Digits)=>('.' Digits)|(Digits '.' Digits?))
518
	;
519
	
520
fragment
521
Exponent_DNum
522
	:((Digits|DNum)('e'|'E')('+''-')?Digits)
523
	;
524
	
525
Real
526
    : DNum|Exponent_DNum
527
    ;
528

  
529
Boolean
530
    : 'true' | 'false'
531
    ;
532

  
533
SingleQuotedString
534
    : '\'' (('\\' '\'')=>'\\' '\''
535
    |         ('\\' '\\')=>'\\' '\\' 
536
    |         '\\' | ~ ('\'' | '\\'))* 
537
      '\''
538
    ;
539

  
540
fragment
541
EscapeCharector
542
    : 'n' | 'r' | 't' | '\\' | '$' | '"' | Digits | 'x'
543
    ;
544

  
545
DoubleQuotedString
546
    : '"'  ( ('\\' EscapeCharector)=> '\\' EscapeCharector 
547
    | '\\' 
548
    | ~('\\'|'"') )* 
549
      '"'
550
    ;
551

  
552
HereDoc 
553
    : '<<<' HereDocContents
554
    ;
555

  
556
//Todo handle '\x7f' - '\xff'
557
UnquotedString
558
   : ('a'..'z' | 'A'..'Z' | '_')  ('a'..'z' | 'A'..'Z' | '0'..'9' | '_')*
559
   ;
560
   
561
//TODO: add error handling
562
fragment 
563
HereDocContents
564
    : {
565
        StringBuilder sb = new StringBuilder();
566
        while(input.LA(1)!='\n'){
567
            sb.append((char)input.LA(1));
568
            input.consume();
569
        }
570
        input.consume();
571
        String hereDocName = sb.toString();
572
        int hdnl = hereDocName.length();
573
        while(true){
574
            boolean matchEnd = true;
575
            for(int i = 0; i<hdnl; i++){
576
                if(input.LA(1)!=hereDocName.charAt(i)){
577
                    matchEnd=false;
578
                    break;
579
                }
580
                input.consume();
581
            }
582
            if(matchEnd==false){
583
                while(input.LA(1)!='\n'){
584
                    input.consume();
585
                }
586
                input.consume();
587
            }else{
588
                break;
589
            }
590
        }
591
    }
592
    ;
593

  
594
AsignmentOperator
595
    : '+='|'-='|'*='|'/='|'.='|'%='|'&='|'|='|'^='|'<<='|'>>='
596
    ;
597
    
598
EqualityOperator
599
    : '==' | '!=' | '===' | '!=='
600
    ;
601

  
602
ComparisionOperator
603
    : '<' | '<=' | '>' | '>=' | '<>'
604
    ;
605
    
606
ShiftOperator
607
    : '<<' | '>>'
608
    ;
609

  
610
IncrementOperator
611
    : '--'|'++'
612
    ;
613
    
614

  
615
fragment
616
Eol : '\n'
617
    ;
618

  
619
WhiteSpace
620
@init{
621
    $channel=HIDDEN;
622
}
623
	:	(' '| '\t'| '\n'|'\r')*
624
	;
625
	
626

  
supose/src/main/java/com/soebes/supose/cli/ScanCommand.java 2010-06-24 18:00:43.000000000 +0200
44 44
    private Option optionToRev = null;
45 45
    private Option optionIndexDir = null;
46 46
    private Option optionCreate = null;
47
    private Option optionSolrUrl = null;
47 48

  
48 49
	public ScanCommand() {
49 50
		setCommand(createCommand());
......
125 126
			)
126 127
			.withDescription("Define the index directory where the created index will be stored.")
127 128
			.create();
129
    	
130
    	optionSolrUrl = obuilder
131
			.withShortName("S")
132
			.withLongName("solr")
133
			.withArgument(
134
				abuilder
135
				.withName("solr")
136
				.withMinimum(1)
137
				.withMaximum(1)
138
				.create()
139
			)
140
			.withDescription("Use Solr to store data. Specify URL at which Solr is running.")
141
			.create();
128 142

  
129 143
    	optionCreate = obuilder
130 144
	    	.withLongName("create")
......
139 153
    		.withOption(optionToRev)
140 154
    		.withOption(optionIndexDir)
141 155
    		.withOption(optionCreate)
156
    		.withOption(optionSolrUrl)
142 157
    		.create();
143 158
    	
144 159
    	return cbuilder
......
180 195
	public boolean getCreate(CommandLine cline) {
181 196
		return cline.hasOption((getOptionCreate()));
182 197
	}
198
	
199
	public Option getOptionSolrUrl() {
200
		return optionSolrUrl;
201
	}
183 202

  
184 203
	public String getURL (CommandLine cline) {
185 204
		String result = (String) cline.getValue((getOptionURL()));
......
257 276
		if (indexDir != null && indexDir.trim().length() > 0) {
258 277
			result = indexDir.trim();
259 278
		}
279
		
280
		if(getSolrUrl(cline) != null) {
281
			return null;
282
		}
260 283
		return result;
261 284
	}
262 285
	
286
	public String getSolrUrl (CommandLine cline) {
287
		String solrUrl = (String) cline.getValue((getOptionSolrUrl()));
288
		return solrUrl;
289
	}
263 290
	
264 291
}
supose/src/main/java/com/soebes/supose/cli/SearchCommand.java 2010-06-24 10:34:04.000000000 +0200
44 44
public class SearchCommand extends CLIBase {
45 45

  
46 46
    private Option optionIndex = null;
47
    private Option optionSolrUrl = null;
47 48
    private Option optionQuery = null;
48 49
    private Option optionFields = null;
49 50
    private Option optionXML = null;
......
64 65
			.withArgument(abuilder.withName("index").create())
65 66
			.withDescription("Define the index directory where to find the index.")
66 67
			.create();
68
    	
69
    	optionSolrUrl = obuilder
70
		.withShortName("S")
71
		.withLongName("solr")
72
		.withArgument(abuilder.withName("solr").create())
73
		.withDescription("Define the Solr url which is used to query.")
74
		.create();
67 75

  
68 76
    	optionQuery = obuilder
69 77
			.withShortName("Q")
......
97 105
    	
98 106
    	Group optionSearch = gbuilder
99 107
    		.withOption(optionIndex)
108
    		.withOption(optionSolrUrl)
100 109
    		.withOption(optionQuery)
101 110
    		.withOption(optionFields)
102 111
    		.withOption(optionXML)
......
113 122
	public Option getOptionIndex() {
114 123
		return optionIndex;
115 124
	}
125
	public Option getOptionSolrUrl() {
126
		return optionSolrUrl;
127
	}
116 128
	public Option getOptionQuery() {
117 129
		return optionQuery;
118 130
	}
......
132 144
			return list.get(0);
133 145
		}
134 146
	}
147
	
148
	public String getSolrUrl (CommandLine cline) {
149
		String solrUrl = (String) cline.getValue(getOptionSolrUrl());
150
		return solrUrl;
151
	}
135 152

  
136 153
	@SuppressWarnings("unchecked")
137 154
	public String getQuery (CommandLine cline) {
supose/src/main/java/com/soebes/supose/cli/SuposeCLI.java 2010-06-29 15:25:39.000000000 +0200
26 26
package com.soebes.supose.cli;
27 27

  
28 28
import java.io.IOException;
29
import java.net.MalformedURLException;
30
import java.net.URL;
29 31
import java.util.ArrayList;
30 32
import java.util.Iterator;
31 33
import java.util.List;
......
39 41
import org.apache.commons.lang.StringUtils;
40 42
import org.apache.commons.lang.WordUtils;
41 43
import org.apache.log4j.Logger;
42
import org.apache.lucene.index.IndexReader;
43 44
import org.quartz.CronTrigger;
44 45
import org.quartz.JobDetail;
45 46
import org.quartz.Scheduler;
......
54 55
import com.soebes.supose.config.RepositoryConfiguration;
55 56
import com.soebes.supose.config.RepositoryFactory;
56 57
import com.soebes.supose.index.IndexHelper;
58
import com.soebes.supose.index.IndexerFactory;
59
import com.soebes.supose.index.Reader;
60
import com.soebes.supose.index.Writer;
57 61
import com.soebes.supose.jobs.JobDataNames;
58 62
import com.soebes.supose.jobs.JobSchedulerListener;
59 63
import com.soebes.supose.jobs.RepositoryScanJob;
60 64
import com.soebes.supose.repository.Repository;
61 65
import com.soebes.supose.scan.ScanSingleRepository;
62 66
import com.soebes.supose.search.ResultEntry;
63
import com.soebes.supose.search.SearchRepository;
64 67
import com.thoughtworks.xstream.XStream;
65 68

  
66 69
/**
......
105 108
	private static void printHelp() {
106 109
		StringBuffer help = new StringBuffer();
107 110
		Group suposeOptions = suposecli.getSuposeOptions();
108
		List helpLines = suposeOptions.helpLines(0, HelpFormatter.DEFAULT_DISPLAY_USAGE_SETTINGS, null);
111
		List<?> helpLines = suposeOptions.helpLines(0, HelpFormatter.DEFAULT_DISPLAY_USAGE_SETTINGS, null);
109 112
		String descriptionPad = StringUtils.repeat(" ", HELP_OPTION_DESCRIPTION_INDENT);
110 113
		int descriptionIndent = HelpFormatter.DEFAULT_FULL_WIDTH - HELP_OPTION_DESCRIPTION_INDENT;
111
		for (Iterator i = helpLines.iterator(); i.hasNext();) {
114
		for (Iterator<?> i = helpLines.iterator(); i.hasNext();) {
112 115
			HelpLine helpLine = (HelpLine) i.next();
113 116
			String usage = helpLine.usage(HelpFormatter.DEFAULT_LINE_USAGE_SETTINGS, null);
114 117
			String usageWrapped = WordUtils.wrap(usage, HelpFormatter.DEFAULT_FULL_WIDTH);
......
133 136
		long fromRev = scanCommand.getFromRev(commandLine);
134 137
		long toRev = scanCommand.getToRev(commandLine);
135 138
		String indexDirectory = scanCommand.getIndexDir(commandLine);
139
		String solrUrl = scanCommand.getSolrUrl(commandLine);
136 140
		boolean create = scanCommand.getCreate(commandLine);
137 141
		String username = scanCommand.getUsername(commandLine);
138 142
		String password = scanCommand.getPassword(commandLine);
143
		
139 144

  
140 145
		ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
141 146
			username, 
142 147
			password
143 148
		);
144

  
149
		Writer indexWriter = null;
150
		
151
		if(indexDirectory != null && solrUrl != null) {
152
			printHelp();
153
	        System.exit(0);
154
		} else if(indexDirectory != null) {
155
			indexWriter = IndexerFactory.getIndexWriter(indexDirectory, create);
156
		} else if(solrUrl != null) {
157
			try {
158
				indexWriter = IndexerFactory.getIndexWriter(new URL(solrUrl));
159
			} catch (MalformedURLException e) {
160
				LOGGER.warn("Could not parse Solr url " + solrUrl + ": " + e);
161
			}
162
		}
163
		
145 164
		LOGGER.info("Start with scanning of revisions.");
146 165

  
147
		long blockNumber = ScanSingleRepository.scanFullRepository(url, fromRev, indexDirectory, create, authManager);
166
		long blockNumber = ScanSingleRepository.scanFullRepository(url, fromRev, indexWriter, create, authManager);
148 167

  
149 168
		LOGGER.info("Scanning of revisions done");
150 169

  
151
		ScanSingleRepository.mergeIndexesAndCleanUp(indexDirectory, blockNumber);
170
		ScanSingleRepository.mergeIndexesAndCleanUp(indexWriter, blockNumber);
152 171
	}
153 172

  
154 173

  
......
190 209
            	jobDetail.getJobDataMap().put(JobDataNames.REPOSITORY, repository);
191 210
            	jobDetail.getJobDataMap().put(JobDataNames.REPOSITORYCONFIGURATION, reposConfig);
192 211
            	jobDetail.getJobDataMap().put(JobDataNames.BASEDIR, configurationBaseDir);
212
            	jobDetail.getJobDataMap().put(JobDataNames.INDEX, configurationBaseDir);
193 213

  
194 214
            	CronTrigger cronTrigger1 = null;
195 215
            	String cronExpression = "";
......
251 271
		System.out.println("Destination: " + destination);
252 272

  
253 273
		long startTime = System.currentTimeMillis();
254
		IndexHelper.mergeIndex(destination, indexList);
274

  
275
		// We assume that the indexes exist.
276
		// Because only LuceneWriter could merge indexes we dont need a separation
277
		IndexerFactory.getIndexWriter(destination, false).merge(destination, indexList);
255 278
		long stopTime = System.currentTimeMillis();
256 279
		long ms = (stopTime-startTime);
257 280
		long seconds = ms / 1000;
......
271 294
	private static void runSearch(SearchCommand searchCommand) {
272 295
		LOGGER.info("Searching started...");
273 296
		String indexDirectory = searchCommand.getIndexDir(commandLine);
297
		String solrUrl = searchCommand.getSolrUrl(commandLine);
274 298
		String queryLine = searchCommand.getQuery(commandLine);
275 299
		boolean xml = searchCommand.getXML(commandLine);
276 300
		List<String> cliFields = searchCommand.getFields(commandLine);
277 301
		
278
		SearchRepository searchRepository = new SearchRepository(indexDirectory);
279

  
280
		List<ResultEntry> result = searchRepository.getResult(queryLine);
302
		Reader indexReader = null;
303
		if(indexDirectory != null && solrUrl != null) {
304
			printHelp();
305
			System.exit(0);
306
		} else if(indexDirectory != null) {
307
			indexReader = IndexerFactory.getIndexReader(indexDirectory);
308
		} else if (solrUrl != null) {
309
			try {
310
				URL solrServerUrl = new URL(solrUrl);
311
				indexReader = IndexerFactory.getIndexReader(solrServerUrl);
312
			} catch (MalformedURLException e) {
313
				LOGGER.error("Could not parse Solr url " + solrUrl + ": " + e);
314
			}
315
			
316
		}
281 317
		
318
		List<ResultEntry> result = indexReader.getResult(queryLine);
319
		/**
320
		 * @todo: solr xml output
321
		 */
282 322
		if (xml) {
283 323
			XStream xstream = new XStream();
284 324
			xstream.alias("entry", ResultEntry.class);
......
319 359
							System.out.println(" --> K:" + prop.getKey() + " V:" + prop.getValue());
320 360
						}
321 361
					} else {
322
						Object attribute = searchRepository.callGetterByName(item, fn.getValue());
362
						Object attribute = IndexHelper.callGetterByName(item, fn.getValue());
323 363
						System.out.print(fn.name() + ":" + attribute + " ");
324 364
					}
325 365
				}
......
328 368
			}
329 369
		}
330 370

  
331
		IndexReader reader = searchRepository.getReader();
332 371
		try {
333
			reader.close();
372
			indexReader.close();
334 373
		} catch (IOException e) {
335 374
			LOGGER.error("Error during closing of the index happened: ", e);
336 375
		}
supose/src/main/java/com/soebes/supose/FieldNames.java 2010-06-25 15:55:41.000000000 +0200
37 37
 *
38 38
 */
39 39
public enum FieldNames {
40
	CONTENTS("contents"),
40
	CONTENT("content"),
41 41
	REVISION("revision"),
42 42
	KIND("kind"),
43 43
	NODE("node"),
......
55 55
	MAVENTAG("maventag"),
56 56
	SUBVERSIONTAG("subversiontag"),
57 57
	BRANCH("branch"),
58
	XLSSHEET("xlssheet"),
59
	XLSSHEETNAME("xlssheetname"),
60
	XLSCOMMENT("xlscomment"),
61
	XLSCOMMENTAUTHOR("xlscommentauthor"),
62
	XLSAUTHOR("xlsauthor"),
63
	PDFAUTHOR("pdfauthor"),
64
	PDFCREATIONDATE("pdfcreationdate"),
65
	PDFCREATOR("pdfcreator"),
66
	PDFKEYWORDS("pdfkeywords"),
67
	PDFMODIFICATIONDATE("pdfmodificationdate"),
68
	PDFPRODUCER("pdfproducer"),
69
	PDFSUBJECT("pdfsubject"),
70
	PDFTITLE("pdftitle"),
71
	PDFTRAPPED("pdftrapped"),
58
	
59
	RTTITLE("rttitle"),
60
	RTSUBJECT("rtsubject"),
61
	RTAUTHOR("rtauthor"),
62
	RTDATE("rtdate"),
63
	RTKEYWORDS("rtkeywords"),
64
	
65
	
72 66
	METHODS("methods"),
73 67
	COMMENTS("comments"),
74 68

  
supose/src/main/java/com/soebes/supose/index/IndexerFactory.java 2010-06-24 10:17:14.000000000 +0200
1
package com.soebes.supose.index;
2

  
3
import java.net.URL;
4

  
5
import com.soebes.supose.index.lucene.LuceneIndexReader;
6
import com.soebes.supose.index.lucene.LuceneIndexWriter;
7
import com.soebes.supose.index.solr.SolrIndexReader;
8
import com.soebes.supose.index.solr.SolrIndexWriter;
9

  
10

  
11
public class IndexerFactory {
12
	
13
	public static Writer getIndexWriter(String indexDirectory, boolean overwrite) {
14
		return new LuceneIndexWriter(indexDirectory, overwrite);
15
	}
16

  
17
	public static Reader getIndexReader(String indexDirectory) {
18
		return new LuceneIndexReader(indexDirectory);
19
	}
20
	
21
	public static Writer getIndexWriter(URL solrUrl) {
22
		return new SolrIndexWriter(solrUrl);
23
	}
24
	
25
	public static Reader getIndexReader(URL solrUrl) {
26
		return new SolrIndexReader(solrUrl);
27
	}
28
	
29
}
supose/src/main/java/com/soebes/supose/index/IndexHelper.java 2010-07-02 18:14:31.000000000 +0200
22 22
 * If you have any questions about the Software or about the license
23 23
 * just write an email to license@soebes.de
24 24
 */
25

  
26 25
package com.soebes.supose.index;
27 26

  
28
import java.util.ArrayList;
29
import java.util.List;
27
import java.lang.reflect.InvocationTargetException;
28
import java.lang.reflect.Method;
30 29

  
31 30
import org.apache.log4j.Logger;
32
import org.apache.lucene.index.IndexWriter;
33
import org.apache.lucene.store.FSDirectory;
34 31

  
32
import com.soebes.supose.search.ResultEntry;
35 33

  
36
/**
37
 * @author Karl Heinz Marbaise
38
 *
39
 */
40 34
public class IndexHelper {
35
	
41 36
	private static Logger LOGGER = Logger.getLogger(IndexHelper.class);
42 37

  
38
	public static Method getGetterByName(Class<?> z, String name) {
39
		Method[] methods = z.getMethods();
40
		Method result = null;
41
		for (Method method : methods) {
42
			if (method.getName().toLowerCase().startsWith("get")) {
43
				String m = method.getName().toLowerCase();
44
				if (m.equals("get" + name.toLowerCase())) {
45
//					System.out.println("MS:" + name);
46
					result = method;
47
				}
48
			}
49
		}
50
		return result;
51
	}
43 52
	
44
	/**
45
	 * Merge a given index area to a single destination index.
46
	 * @param destination The destination to which the source index will
47
	 *   be merged.
48
	 * @param source The index which will be merged to the destination index.
49
	 */
50
	public static void mergeIndex(String destination, String source) {
51
		ArrayList<String> sourceList = new ArrayList<String>();
52
		sourceList.add(source);
53
		mergeIndex(destination, sourceList);
53
	
54
	public static Method getSetterByName(Class<?> z, String name) {
55
		Method[] methods = z.getMethods();
56
		Method result = null;
57
		for (Method method : methods) {
58
			if (method.getName().toLowerCase().startsWith("set")) {
59
				String m = method.getName().toLowerCase();
60
				if (m.equals("set" + name.toLowerCase())) {
61
//					System.out.println("MS:" + name);
62
					result = method;
63
				}
64
			}
65
		}
66
		return result;
54 67
	}
55

  
56
	/**
57
	 * Merge all given indexes together to a single index.
58
	 * @param destination This will define the destination directory
59
	 *   of the index where all other indexes will be merged to.
60
	 * @param indexList This is the list of indexes which are
61
	 *   merged into the destination index.
62
	 */
63
	public static void mergeIndex (String destination, List<String> indexList) {
64
		LOGGER.debug("We are trying to merge indexes to the destination: " + destination);
65
		Index index = new Index ();
66
		//We assume an existing index...
67
		index.setCreate(false);
68
		IndexWriter indexWriter = index.createIndexWriter(destination);
69

  
68
	
69
	
70
	public static Object callGetterByName(ResultEntry z, String name) {
71
		Method m = getGetterByName(z.getClass(), name);
72
		Object attribute = null;
73
		if (m == null) {
74
			LOGGER.fatal("Method get" + name + " not found!");
75
			return attribute; 
76
		}
70 77
		try {
71
			LOGGER.info("Merging of indexes started.");
72
			FSDirectory [] fsDirs = new FSDirectory[indexList.size()];
73
			for (int i = 0; i < indexList.size(); i++) {
74
				fsDirs[i] = FSDirectory.getDirectory(indexList.get(i));
75
			}
76
			indexWriter.addIndexesNoOptimize(fsDirs);
77
			indexWriter.optimize();
78
			indexWriter.close();
79
			LOGGER.info("Merging of indexes succesfull.");
80
		} catch (Exception e) {
81
			LOGGER.error("Something wrong during merge of index: ", e);
78
			attribute = m.invoke(z);
79
		} catch (IllegalArgumentException e) {
80
			LOGGER.fatal("IllegalArgumentException", e);
81
		} catch (IllegalAccessException e) {
82
			LOGGER.fatal("IllegalAccessException", e);
83
		} catch (InvocationTargetException e) {
84
			LOGGER.fatal("InvocationTargetException", e);
82 85
		}
86
		return attribute;
83 87
	}
84

  
85 88
}
supose/src/main/java/com/soebes/supose/index/Index.java 1970-01-01 01:00:00.000000000 +0100
1
/**
2
 * The (Su)bversion Re(po)sitory (S)earch (E)ngine (SupoSE for short).
3
 *
4
 * Copyright (c) 2007, 2008, 2009, 2010 by SoftwareEntwicklung Beratung Schulung (SoEBeS)
5
 * Copyright (c) 2007, 2008, 2009, 2010 by Karl Heinz Marbaise
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20
 *
21
 * The License can viewed online under http://www.gnu.org/licenses/gpl.html
22
 * If you have any questions about the Software or about the license
23
 * just write an email to license@soebes.de
24
 */
25

  
26
package com.soebes.supose.index;
27

  
28
import java.io.File;
29
import java.io.IOException;
30

  
31
import org.apache.log4j.Logger;
32
import org.apache.lucene.analysis.Analyzer;
33
import org.apache.lucene.index.CorruptIndexException;
34
import org.apache.lucene.index.IndexWriter;
35
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
36
import org.apache.lucene.store.LockObtainFailedException;
37

  
38
import com.soebes.supose.utility.AnalyzerFactory;
39

  
40
/**
41
 * @author Karl Heinz Marbaise
42
 *
43
 */
44
public class Index {
45
	private static Logger LOGGER = Logger.getLogger(Index.class);
46

  
47
	private String indexDirectory = null;
48
	private IndexWriter indexWriter = null;
49
	private Analyzer analyzer = null;
50
	
51
	private int mergeFactor = 10;
52
	private int maxBufferedDocs = 10;
53
	private boolean useCompoundFile = false;
54
	private boolean create = false;
55
	
56
	public Index () {
57
		setIndexDirectory(null);
58
		setAnalyzer(AnalyzerFactory.createInstance());
59
		setMergeFactor(1000);
60
		setMaxBufferedDocs(1000);
61
		setUseCompoundFile(false);
62
	}
63
	
64
	public IndexWriter createIndexWriter (String indexDirectory) {
65
		LOGGER.debug("createIndexWriter('" + indexDirectory + "')");
66
		setIndexDirectory(indexDirectory);
67
		File indexDir = new File(getIndexDirectory());
68
		IndexWriter writer = null;
69
		try {
70
			LOGGER.debug("Trying to create a new Index");
71
			if (isCreate()) {
72
				LOGGER.debug("Trying to create a new index (overwrite an exsting)");
73
				//This will create a new index. Independent if one existed before.
74
				writer = new IndexWriter(indexDir, getAnalyzer(), true, MaxFieldLength.UNLIMITED);
75
			} else {
76
				LOGGER.debug("Trying to create a new index (using an exsting)");
77
				//This will use an existing index or will create one if 
78
				//no existed before.
79
				writer = new IndexWriter(indexDir, getAnalyzer(), MaxFieldLength.UNLIMITED);
80
			}
81
			LOGGER.debug("Created new index.");
82
			writer.setUseCompoundFile(isUseCompoundFile());
83
			writer.setMergeFactor(getMergeFactor());
84
			writer.setMaxBufferedDocs(getMaxBufferedDocs());
85
//			writer.setInfoStream(System.out);
86
		} catch (CorruptIndexException e) {
87
			LOGGER.error("CorruptIndex: ", e);
88
		} catch (LockObtainFailedException e) {
89
			LOGGER.error("LockObtain: ", e);
90
		} catch (IOException e) {
91
			LOGGER.error("IOException: ", e);
92
		}
93
		return writer;
94
	}
95

  
96
	public IndexWriter getIndexWriter() {
97
		return indexWriter;
98
	}
99

  
100
	public void setIndexWriter(IndexWriter indexWriter) {
101
		this.indexWriter = indexWriter;
102
	}
103

  
104
	public String getIndexDirectory() {
105
		return indexDirectory;
106
	}
107

  
108
	public void setIndexDirectory(String indexDirectory) {
109
		this.indexDirectory = indexDirectory;
110
	}
111

  
112
	public Analyzer getAnalyzer() {
113
		return analyzer;
114
	}
115

  
116
	public void setAnalyzer(Analyzer analyzer) {
117
		this.analyzer = analyzer;
118
	}
119

  
120
	public int getMergeFactor() {
121
		return mergeFactor;
122
	}
123

  
124
	public void setMergeFactor(int mergeFactor) {
125
		this.mergeFactor = mergeFactor;
126
	}
127

  
128
	public int getMaxBufferedDocs() {
129
		return maxBufferedDocs;
130
	}
131

  
132
	public void setMaxBufferedDocs(int maxBufferedDocs) {
133
		this.maxBufferedDocs = maxBufferedDocs;
134
	}
135

  
136
	public boolean isUseCompoundFile() {
137
		return useCompoundFile;
138
	}
139

  
140
	public void setUseCompoundFile(boolean useCompoundFile) {
141
		this.useCompoundFile = useCompoundFile;
142
	}
143

  
144
	public boolean isCreate() {
145
		return create;
146
	}
147

  
148
	public void setCreate(boolean create) {
149
		this.create = create;
150
	}
151
}
supose/src/main/java/com/soebes/supose/index/lucene/LuceneIndexReader.java 2010-06-29 16:09:48.000000000 +0200
1
package com.soebes.supose.index.lucene;
2

  
3
import java.io.IOException;
4
import java.lang.reflect.InvocationTargetException;
5
import java.lang.reflect.Method;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import org.apache.log4j.Logger;
10
import org.apache.lucene.analysis.Analyzer;
11
import org.apache.lucene.document.Document;
12
import org.apache.lucene.document.Field;
13
import org.apache.lucene.index.CorruptIndexException;
14
import org.apache.lucene.queryParser.QueryParser;
15
import org.apache.lucene.search.BooleanQuery;
16
import org.apache.lucene.search.IndexSearcher;
17
import org.apache.lucene.search.Query;
18
import org.apache.lucene.search.Searcher;
19
import org.apache.lucene.search.Sort;
20
import org.apache.lucene.search.SortField;
21
import org.apache.lucene.search.TopDocs;
22

  
23
import com.soebes.supose.FieldNames;
24
import com.soebes.supose.index.IndexHelper;
25
import com.soebes.supose.index.Reader;
26
import com.soebes.supose.search.CustomQueryParser;
27
import com.soebes.supose.search.ResultEntry;
28
import com.soebes.supose.utility.AnalyzerFactory;
29

  
30
public class LuceneIndexReader implements Reader {
31
	
32
	private static Logger LOGGER = Logger.getLogger(LuceneIndexReader.class);
33
	
34
	private String indexDirectory = null;
35
	private Analyzer analyzer = null;
36
	
37
	public LuceneIndexReader(String indexDirectory) {
38
		this.indexDirectory = indexDirectory;
39
		this.analyzer = AnalyzerFactory.createInstance();
40
	}
41

  
42
	public List<ResultEntry> getResult(String queryLine) {
43
		TopDocs result = getQueryResult(queryLine);
44
		ArrayList<ResultEntry> resultList = new ArrayList<ResultEntry>();
45
		
46
		try {
47
			Searcher searcher = new IndexSearcher(indexDirectory);
48
			for (int i = 0; i < result.scoreDocs.length; i++) {
49
		    	Document hit = searcher.doc(result.scoreDocs[i].doc);
50
				List<Field> fieldList = hit.getFields();
51
				ResultEntry re = new ResultEntry();
52
				for(Field f : fieldList) {
53
					Method method = IndexHelper.getSetterByName(re.getClass(), f.name());
54
					if (method != null) {
55
//						System.out.println(
56
//							"-> Name:" + field.name() 
57
//							+ " " + field.stringValue()
58
//							+ " [" + field.getBinaryLength() + "] "
59
//							+ " Method:" + method.getName());
60
						try {
61
							method.invoke(re, f.stringValue());
62
						} catch (IllegalArgumentException e) {
63
							LOGGER.fatal("IllegalArgumentException", e);
64
						} catch (IllegalAccessException e) {
65
							LOGGER.fatal("IllegalAccessException", e);
66
						} catch (InvocationTargetException e) {
67
							LOGGER.fatal("InvocationTargetException", e);
68
						}
69
					}
70
				}
71
				resultList.add(re);
72
			}
73
		} catch (Exception e) {
74
			LOGGER.fatal("Exception", e);
75
		}
76
		return resultList;
77
	}
78

  
79
	private TopDocs getQueryResult(String queryLine) {
80
	    TopDocs result = null;	    
81
	    try {
82
	    	
83
	    	BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
84
	    	Searcher searcher = new IndexSearcher(indexDirectory);
85
	    	SortField[] sf = {
86
	    		new SortField(FieldNames.REVISION.getValue()),
87
	    		new SortField(FieldNames.FILENAME.getValue()), //We use for sorting the filename
88
	    	};
89
	    	Sort sort = new Sort(sf);
90
	    	//Here we define the default field for searching.
91

  
92
	    	QueryParser parser = new CustomQueryParser(FieldNames.CONTENT.toString(), this.analyzer);
93
	        
94
	    	//We will allow using a wildcard at the beginning of the expression.
95
	    	parser.setAllowLeadingWildcard(true);
96
	        
97
	    	//The search term will not be expanded to lowercase.
98
	        parser.setLowercaseExpandedTerms(true);
99
	        Query query = parser.parse(queryLine);
100
	        LOGGER.info("Query: " + query.toString());
101
	        //That's not the best idea...but currently i have not better solution for this...
102
	        //This is intended to get all results not only a limited number results.
103
	        TopDocs tmp = searcher.search(query, null, 20, sort);
104
		    result = searcher.search(query, null, tmp.totalHits, sort);
105
		    searcher.close();
106
	    } catch (CorruptIndexException e) {
107
			LOGGER.error("Error: The index is corrupted: ", e);
108
	    } catch (IOException e) {
109
			LOGGER.error("Error: IOException: ", e);
110
		} catch (Exception e) {
111
			LOGGER.error("Error: Something has gone wrong: ", e);
112
		}
113
		
114
		return result;
115
	}
116
	
117
	@Override
118
	public void close() throws IOException {
119
		// TODO Auto-generated method stub
120
		
121
	}
122

  
123
	@Override
124
	public void open() throws IOException {
125
		// TODO Auto-generated method stub
126
		
127
	}
128
	
129
}
supose/src/main/java/com/soebes/supose/index/lucene/LuceneIndexWriter.java 2010-06-29 16:10:32.000000000 +0200
1
/**
2
 * The (Su)bversion Re(po)sitory (S)earch (E)ngine (SupoSE for short).
3
 *
4
 * Copyright (c) 2007, 2008, 2009, 2010 by SoftwareEntwicklung Beratung Schulung (SoEBeS)
5
 * Copyright (c) 2007, 2008, 2009, 2010 by Karl Heinz Marbaise
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20
 *
21
 * The License can viewed online under http://www.gnu.org/licenses/gpl.html
22
 * If you have any questions about the Software or about the license
23
 * just write an email to license@soebes.de
24
 */
25

  
26
package com.soebes.supose.index.lucene;
27

  
28
import java.io.File;
29
import java.io.IOException;
30
import java.text.SimpleDateFormat;
31
import java.util.ArrayList;
32
import java.util.Collection;
33
import java.util.Date;
34
import java.util.HashMap;
35
import java.util.List;
36
import java.util.Map.Entry;
37

  
38
import org.apache.log4j.Logger;
39
import org.apache.lucene.analysis.Analyzer;
40
import org.apache.lucene.document.Document;
41
import org.apache.lucene.document.Field;
42
import org.apache.lucene.index.CorruptIndexException;
43
import org.apache.lucene.index.IndexWriter;
44
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
45
import org.apache.lucene.store.FSDirectory;
46
import org.apache.lucene.store.LockObtainFailedException;
47

  
48
import com.soebes.supose.index.Writer;
49
import com.soebes.supose.search.Analyze;
50
import com.soebes.supose.search.ResultEntry;
51
import com.soebes.supose.utility.AnalyzerFactory;
52

  
53
/**
54
 * @author Karl Heinz Marbaise
55
 * 
56
 */
57
public class LuceneIndexWriter implements Writer {
58
	private static Logger LOGGER = Logger.getLogger(LuceneIndexWriter.class);
59
	
60
	private int commitSize = 100;
61
	private Collection<Document> docs = new ArrayList<Document>(commitSize);
62

  
... This diff was truncated because it exceeds the maximum size that can be displayed.