01: package org.apache.lucene.xmlparser.builders;
02:
03: import java.util.ArrayList;
04:
05: import org.apache.lucene.search.spans.SpanOrQuery;
06: import org.apache.lucene.search.spans.SpanQuery;
07: import org.apache.lucene.xmlparser.DOMUtils;
08: import org.apache.lucene.xmlparser.ParserException;
09: import org.w3c.dom.Element;
10: import org.w3c.dom.Node;
11:
12: /**
13: * Licensed to the Apache Software Foundation (ASF) under one or more
14: * contributor license agreements. See the NOTICE file distributed with
15: * this work for additional information regarding copyright ownership.
16: * The ASF licenses this file to You under the Apache License, Version 2.0
17: * (the "License"); you may not use this file except in compliance with
18: * the License. You may obtain a copy of the License at
19: *
20: * http://www.apache.org/licenses/LICENSE-2.0
21: *
22: * Unless required by applicable law or agreed to in writing, software
23: * distributed under the License is distributed on an "AS IS" BASIS,
24: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25: * See the License for the specific language governing permissions and
26: * limitations under the License.
27: */
28: public class SpanOrBuilder extends SpanBuilderBase {
29:
30: SpanQueryBuilder factory;
31:
32: public SpanOrBuilder(SpanQueryBuilder factory) {
33: super ();
34: this .factory = factory;
35: }
36:
37: public SpanQuery getSpanQuery(Element e) throws ParserException {
38: ArrayList clausesList = new ArrayList();
39: for (Node kid = e.getFirstChild(); kid != null; kid = kid
40: .getNextSibling()) {
41: if (kid.getNodeType() == Node.ELEMENT_NODE) {
42: SpanQuery clause = factory.getSpanQuery((Element) kid);
43: clausesList.add(clause);
44: }
45: }
46: SpanQuery[] clauses = (SpanQuery[]) clausesList
47: .toArray(new SpanQuery[clausesList.size()]);
48: SpanOrQuery soq = new SpanOrQuery(clauses);
49: soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
50: return soq;
51: }
52:
53: }
|