1 package org.apache.lucene.queryParser.core.processors;
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.Iterator;
21 import java.util.List;
23 import org.apache.lucene.queryParser.core.QueryNodeException;
24 import org.apache.lucene.queryParser.core.nodes.DeletedQueryNode;
25 import org.apache.lucene.queryParser.core.nodes.MatchNoDocsQueryNode;
26 import org.apache.lucene.queryParser.core.nodes.QueryNode;
29 * A {@link QueryNodeProcessorPipeline} class removes every instance of
30 * {@link DeletedQueryNode} from a query node tree. If the resulting root node
31 * is a {@link DeletedQueryNode}, {@link MatchNoDocsQueryNode} is returned.
34 public class RemoveDeletedQueryNodesProcessor extends QueryNodeProcessorImpl {
36 public RemoveDeletedQueryNodesProcessor() {
41 public QueryNode process(QueryNode queryTree) throws QueryNodeException {
42 queryTree = super.process(queryTree);
44 if (queryTree instanceof DeletedQueryNode
45 && !(queryTree instanceof MatchNoDocsQueryNode)) {
47 return new MatchNoDocsQueryNode();
56 protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
59 List<QueryNode> children = node.getChildren();
60 boolean removeBoolean = false;
62 if (children == null || children.size() == 0) {
68 for (Iterator<QueryNode> it = children.iterator(); it.hasNext();) {
70 if (!(it.next() instanceof DeletedQueryNode)) {
71 removeBoolean = false;
81 return new DeletedQueryNode();
91 protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
92 throws QueryNodeException {
94 for (int i = 0; i < children.size(); i++) {
96 if (children.get(i) instanceof DeletedQueryNode) {
107 protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {