01: /*
02: * $Header$
03: * $Revision: 7957 $
04: * $Date: 2007-08-23 04:22:35 -0700 $
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 org.apache.lucene.index.Term;
26: import org.apache.lucene.search.TermQuery;
27:
28: import org.apache.slide.index.lucene.Index;
29: import org.apache.slide.index.lucene.IndexConfiguration;
30: import org.apache.slide.search.BadQueryException;
31: import org.jdom.Element;
32:
33: /**
34: * Implements the <code>is-defined</code> and the <code>not-is-defined</code>
35: * expression.
36: */
37: public class IsDefinedExpression extends AbstractLuceneExpression {
38: public IsDefinedExpression(Index index, Element element,
39: boolean negated) throws BadQueryException {
40: super (index);
41:
42: Element prop = getPropertyElement(element);
43: String field = IndexConfiguration.generateFieldName(prop
44: .getNamespaceURI(), prop.getName());
45:
46: setQuery(new TermQuery(new Term(Index.IS_DEFINED_FIELD_NAME,
47: field)));
48: if (negated) {
49: setQuery(negateQuery(getQuery()));
50: }
51: }
52:
53: public IsDefinedExpression(Index index, String field,
54: boolean negated) {
55: super (index);
56:
57: setQuery(new TermQuery(new Term(Index.IS_DEFINED_FIELD_NAME,
58: field)));
59: if (negated) {
60: setQuery(negateQuery(getQuery()));
61: }
62: }
63: }
|