01: /*
02: * $Header$
03: * $Revision: 1769 $
04: * $Date: 2006-04-05 15:18:41 +0200 (Wed, 05 Apr 2006) $
05: *
06: * ====================================================================
07: *
08: * Copyright 1999-2004 The Apache Software Foundation
09: *
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: *
22: */
23: package org.apache.slide.index.lucene.expressions;
24:
25: import java.io.StringReader;
26:
27: import org.apache.lucene.analysis.Analyzer;
28: import org.apache.lucene.analysis.Token;
29: import org.apache.lucene.analysis.TokenStream;
30: import org.apache.lucene.index.Term;
31: import org.apache.lucene.search.BooleanClause;
32: import org.apache.lucene.search.BooleanQuery;
33: import org.apache.lucene.search.TermQuery;
34: import org.apache.slide.index.lucene.Index;
35: import org.apache.slide.index.lucene.IndexConfiguration;
36: import org.apache.slide.search.BadQueryException;
37: import org.jdom.Element;
38:
39: /**
40: * Implements the <code>property-contains</code> expression, that works
41: * exacly like <code>contains</code> but on properties.
42: */
43: public class StrictPropertyContainsExpression extends
44: PropertyContainsExpression {
45:
46: public StrictPropertyContainsExpression(Index index,
47: Element element, boolean negated) throws BadQueryException {
48: super (index, element, negated);
49: }
50:
51: protected void parseQuery(IndexConfiguration config, String field,
52: String text) throws Exception {
53:
54: Analyzer analyzer = config.getAnalyzerForField(field);
55: TokenStream stream = analyzer.tokenStream(field,
56: new StringReader(text));
57:
58: BooleanQuery query = new BooleanQuery();
59:
60: Token token = stream.next();
61: while (token != null) {
62: query.add(new TermQuery(new Term(field, token.termText())),
63: BooleanClause.Occur.MUST);
64:
65: token = stream.next();
66: }
67: setQuery(query);
68: }
69: }
|