01: package org.apache.lucene.xmlparser.builders;
02:
03: import org.apache.lucene.queryParser.ParseException;
04: import org.apache.lucene.queryParser.QueryParser;
05: import org.apache.lucene.search.Query;
06: import org.apache.lucene.xmlparser.DOMUtils;
07: import org.apache.lucene.xmlparser.ParserException;
08: import org.apache.lucene.xmlparser.QueryBuilder;
09: import org.w3c.dom.Element;
10:
11: /**
12: * Licensed to the Apache Software Foundation (ASF) under one or more
13: * contributor license agreements. See the NOTICE file distributed with
14: * this work for additional information regarding copyright ownership.
15: * The ASF licenses this file to You under the Apache License, Version 2.0
16: * (the "License"); you may not use this file except in compliance with
17: * the License. You may obtain a copy of the License at
18: *
19: * http://www.apache.org/licenses/LICENSE-2.0
20: *
21: * Unless required by applicable law or agreed to in writing, software
22: * distributed under the License is distributed on an "AS IS" BASIS,
23: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24: * See the License for the specific language governing permissions and
25: * limitations under the License.
26: */
27:
28: /**
29: * @author maharwood
30: */
31: public class UserInputQueryBuilder implements QueryBuilder {
32:
33: QueryParser parser;
34:
35: /**
36: * @param parser
37: */
38: public UserInputQueryBuilder(QueryParser parser) {
39: this .parser = parser;
40: }
41:
42: /* (non-Javadoc)
43: * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
44: */
45: public Query getQuery(Element e) throws ParserException {
46: String text = DOMUtils.getText(e);
47: try {
48: Query q = parser.parse(text);
49: q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
50: return q;
51: } catch (ParseException e1) {
52: throw new ParserException(e1.getMessage());
53: }
54: }
55:
56: }
|