01: /*
02: * Created on May 30, 2007
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.apache.slide.index.lucene.expressions;
08:
09: import org.apache.lucene.analysis.Analyzer;
10: import org.apache.lucene.queryParser.ParseException;
11: import org.apache.lucene.queryParser.QueryParser;
12: import org.apache.lucene.search.Query;
13: import org.apache.slide.index.lucene.Index;
14: import org.apache.slide.index.lucene.IndexConfiguration;
15: import org.apache.slide.search.BadQueryException;
16: import nl.hippo.slide.index.analysis.SimpleStandardAnalyzer;
17: import org.jdom.Element;
18:
19: /**
20: * @author aschrijvers
21: *
22: * TODO To change the template for this generated type comment go to
23: * Window - Preferences - Java - Code Style - Code Templates
24: */
25: public class PropSearchExpression extends AbstractLuceneExpression {
26:
27: public PropSearchExpression(Index index, Element element,
28: boolean negated) throws BadQueryException {
29: super (index);
30:
31: IndexConfiguration config = index.getConfiguration();
32: Element prop = getPropertyElement(element);
33: String field = IndexConfiguration.generateFieldName(prop
34: .getNamespaceURI(), IndexConfiguration.TOKENIZED_PREFIX
35: + prop.getName());
36: String literal = getLiteralElement(element).getText();
37:
38: // use queryparser to make the query here
39: Analyzer analyzer;
40: if (config.getAnalyzerForField(field) != null) {
41: analyzer = config.getAnalyzerForField(field);
42: } else {
43: analyzer = new SimpleStandardAnalyzer();
44: }
45:
46: QueryParser parser = new QueryParser(field, analyzer);
47: Query finalQuery;
48: try {
49: finalQuery = parser.parse(literal);
50: setQuery(finalQuery);
51: } catch (ParseException e) {
52: throw new BadQueryException(e);
53: }
54:
55: }
56:
57: }
|