1
package org.apache.lucene.queryParser.core.nodes;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.util.List;
22
import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
25
* A {@link AnyQueryNode} represents an ANY operator performed on a list of
28
public class AnyQueryNode extends AndQueryNode {
29
private static final long serialVersionUID = 1000791433562954187L;
31
private CharSequence field = null;
32
private int minimumMatchingmElements = 0;
36
* - the query nodes to be or'ed
38
public AnyQueryNode(List<QueryNode> clauses, CharSequence field,
39
int minimumMatchingElements) {
42
this.minimumMatchingmElements = minimumMatchingElements;
44
if (clauses != null) {
46
for (QueryNode clause : clauses) {
48
if (clause instanceof FieldQueryNode) {
50
if (clause instanceof QueryNodeImpl) {
51
((QueryNodeImpl) clause).toQueryStringIgnoreFields = true;
54
if (clause instanceof FieldableNode) {
55
((FieldableNode) clause).setField(field);
65
public int getMinimumMatchingElements() {
66
return this.minimumMatchingmElements;
70
* returns null if the field was not specified
74
public CharSequence getField() {
79
* returns - null if the field was not specified
81
* @return the field as a String
83
public String getFieldAsString() {
84
if (this.field == null)
87
return this.field.toString();
94
public void setField(CharSequence field) {
99
public QueryNode cloneTree() throws CloneNotSupportedException {
100
AnyQueryNode clone = (AnyQueryNode) super.cloneTree();
102
clone.field = this.field;
103
clone.minimumMatchingmElements = this.minimumMatchingmElements;
109
public String toString() {
110
if (getChildren() == null || getChildren().size() == 0)
111
return "<any field='" + this.field + "' matchelements="
112
+ this.minimumMatchingmElements + "/>";
113
StringBuilder sb = new StringBuilder();
114
sb.append("<any field='" + this.field + "' matchelements="
115
+ this.minimumMatchingmElements + ">");
116
for (QueryNode clause : getChildren()) {
118
sb.append(clause.toString());
120
sb.append("\n</any>");
121
return sb.toString();
125
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
126
String anySTR = "ANY " + this.minimumMatchingmElements;
128
StringBuilder sb = new StringBuilder();
129
if (getChildren() == null || getChildren().size() == 0) {
133
for (QueryNode clause : getChildren()) {
134
sb.append(filler).append(clause.toQueryString(escapeSyntaxParser));
139
if (isDefaultField(this.field)) {
140
return "( " + sb.toString() + " ) " + anySTR;
142
return this.field + ":(( " + sb.toString() + " ) " + anySTR + ")";