1 package org.apache.lucene.xmlparser.builders;
3 import java.util.ArrayList;
5 import org.apache.lucene.search.spans.SpanNearQuery;
6 import org.apache.lucene.search.spans.SpanQuery;
7 import org.apache.lucene.xmlparser.DOMUtils;
8 import org.apache.lucene.xmlparser.ParserException;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node;
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
19 * http://www.apache.org/licenses/LICENSE-2.0
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.
31 public class SpanNearBuilder extends SpanBuilderBase
33 SpanQueryBuilder factory;
34 public SpanNearBuilder(SpanQueryBuilder factory)
39 public SpanQuery getSpanQuery(Element e) throws ParserException
41 String slopString=DOMUtils.getAttributeOrFail(e,"slop");
42 int slop=Integer.parseInt(slopString);
43 boolean inOrder=DOMUtils.getAttribute(e,"inOrder",false);
44 ArrayList<SpanQuery> spans=new ArrayList<SpanQuery>();
45 for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
47 if (kid.getNodeType() == Node.ELEMENT_NODE)
49 spans.add(factory.getSpanQuery((Element) kid));
52 SpanQuery[] spanQueries= spans.toArray(new SpanQuery[spans.size()]);
53 SpanNearQuery snq=new SpanNearQuery(spanQueries,slop,inOrder);