You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/10/19 22:33:55 UTC

svn commit: r1024402 - in /lucene/dev/trunk/lucene/contrib: ./ queryparser/src/java/org/apache/lucene/queryParser/core/processors/ queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ queryparser/src/test/org/apache/lucene/queryParse...

Author: rmuir
Date: Tue Oct 19 20:33:54 2010
New Revision: 1024402

URL: http://svn.apache.org/viewvc?rev=1024402&view=rev
Log:
LUCENE-1937: add methods to manipulate QueryNodeProcessorPipeline elements

Modified:
    lucene/dev/trunk/lucene/contrib/CHANGES.txt
    lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/processors/QueryNodeProcessorPipeline.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
    lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java

Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Tue Oct 19 20:33:54 2010
@@ -158,6 +158,10 @@ API Changes
  * LUCENE-2712: FieldBoostMapAttribute in contrib/queryparser was changed from 
    a Map<CharSequence,Float> to a Map<String,Float>. Per the CharSequence javadoc,
    CharSequence is inappropriate as a map key. (Robert Muir)
+
+ * LUCENE-1937: Add more methods to manipulate QueryNodeProcessorPipeline elements.
+   QueryNodeProcessorPipeline now implements the List interface, this is useful
+   if you want to extend or modify an existing pipeline. (Adriano Crestani via Robert Muir)
     
 New features
 

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/processors/QueryNodeProcessorPipeline.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/processors/QueryNodeProcessorPipeline.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/processors/QueryNodeProcessorPipeline.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/processors/QueryNodeProcessorPipeline.java Tue Oct 19 20:33:54 2010
@@ -17,7 +17,11 @@ package org.apache.lucene.queryParser.co
  * limitations under the License.
  */
 
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
 
 import org.apache.lucene.queryParser.core.QueryNodeException;
 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
@@ -33,11 +37,12 @@ import org.apache.lucene.queryParser.cor
  * processors were on the pipeline.
  * 
  * When a {@link QueryConfigHandler} object is set on a
- * {@link QueryNodeProcessorPipeline}, it takes care of also setting this
+ * {@link QueryNodeProcessorPipeline}, it also takes care of setting this
  * {@link QueryConfigHandler} on all processor on pipeline.
  * 
  */
-public class QueryNodeProcessorPipeline implements QueryNodeProcessor {
+public class QueryNodeProcessorPipeline implements QueryNodeProcessor,
+    List<QueryNodeProcessor> {
 
   private LinkedList<QueryNodeProcessor> processors = new LinkedList<QueryNodeProcessor>();
 
@@ -74,11 +79,10 @@ public class QueryNodeProcessorPipeline 
    * For reference about this method check:
    * {@link QueryNodeProcessor#process(QueryNode)}.
    * 
-   * @param queryTree
-   *          the query node tree to be processed
+   * @param queryTree the query node tree to be processed
    * 
-   * @throws QueryNodeException
-   *           if something goes wrong during the query node processing
+   * @throws QueryNodeException if something goes wrong during the query node
+   *         processing
    * 
    * @see QueryNode
    */
@@ -96,9 +100,12 @@ public class QueryNodeProcessorPipeline 
    * Adds a processor to the pipeline, it's always added to the end of the
    * pipeline.
    * 
-   * @param processor
-   *          the processor to be added
+   * @deprecated this class now conforms to {@link List} interface, so use
+   *             {@link #add(QueryNodeProcessor)} instead
+   * 
+   * @param processor the processor to be added
    */
+  @Deprecated
   public void addProcessor(QueryNodeProcessor processor) {
     this.processors.add(processor);
 
@@ -110,8 +117,7 @@ public class QueryNodeProcessorPipeline 
    * For reference about this method check:
    * {@link QueryNodeProcessor#setQueryConfigHandler(QueryConfigHandler)}.
    * 
-   * @param queryConfigHandler
-   *          the query configuration handler to be set.
+   * @param queryConfigHandler the query configuration handler to be set.
    * 
    * @see QueryNodeProcessor#getQueryConfigHandler()
    * @see QueryConfigHandler
@@ -125,4 +131,195 @@ public class QueryNodeProcessorPipeline 
 
   }
 
+  /**
+   * @see List#add(Object)
+   */
+  public boolean add(QueryNodeProcessor processor) {
+    boolean added = this.processors.add(processor);
+
+    if (added) {
+      processor.setQueryConfigHandler(this.queryConfig);
+    }
+
+    return added;
+
+  }
+
+  /**
+   * @see List#add(int, Object)
+   */
+  public void add(int index, QueryNodeProcessor processor) {
+    this.processors.add(index, processor);
+    processor.setQueryConfigHandler(this.queryConfig);
+
+  }
+
+  /**
+   * @see List#addAll(Collection)
+   */
+  public boolean addAll(Collection<? extends QueryNodeProcessor> c) {
+    boolean anyAdded = this.processors.addAll(c);
+
+    for (QueryNodeProcessor processor : c) {
+      processor.setQueryConfigHandler(this.queryConfig);
+    }
+
+    return anyAdded;
+
+  }
+
+  /**
+   * @see List#addAll(int, Collection)
+   */
+  public boolean addAll(int index, Collection<? extends QueryNodeProcessor> c) {
+    boolean anyAdded = this.processors.addAll(index, c);
+
+    for (QueryNodeProcessor processor : c) {
+      processor.setQueryConfigHandler(this.queryConfig);
+    }
+
+    return anyAdded;
+    
+  }
+
+  /**
+   * @see List#clear()
+   */
+  public void clear() {
+    this.processors.clear();
+  }
+
+  /**
+   * @see List#contains(Object)
+   */
+  public boolean contains(Object o) {
+    return this.processors.contains(o);
+  }
+
+  /**
+   * @see List#containsAll(Collection)
+   */
+  public boolean containsAll(Collection<?> c) {
+    return this.processors.containsAll(c);
+  }
+
+  /**
+   * @see List#get(int)
+   */
+  public QueryNodeProcessor get(int index) {
+    return this.processors.get(index);
+  }
+
+  /**
+   * @see List#indexOf(Object)
+   */
+  public int indexOf(Object o) {
+    return this.processors.indexOf(o);
+  }
+
+  /**
+   * @see List#isEmpty()
+   */
+  public boolean isEmpty() {
+    return this.processors.isEmpty();
+  }
+
+  /**
+   * @see List#iterator()
+   */
+  public Iterator<QueryNodeProcessor> iterator() {
+    return this.processors.iterator();
+  }
+
+  /**
+   * @see List#lastIndexOf(Object)
+   */
+  public int lastIndexOf(Object o) {
+    return this.processors.lastIndexOf(o);
+  }
+
+  /**
+   * @see List#listIterator()
+   */
+  public ListIterator<QueryNodeProcessor> listIterator() {
+    return this.processors.listIterator();
+  }
+
+  /**
+   * @see List#listIterator(int)
+   */
+  public ListIterator<QueryNodeProcessor> listIterator(int index) {
+    return this.processors.listIterator(index);
+  }
+
+  /**
+   * @see List#remove(Object)
+   */
+  public boolean remove(Object o) {
+    return this.processors.remove(o);
+  }
+
+  /**
+   * @see List#remove(int)
+   */
+  public QueryNodeProcessor remove(int index) {
+    return this.processors.remove(index);
+  }
+
+  /**
+   * @see List#removeAll(Collection)
+   */
+  public boolean removeAll(Collection<?> c) {
+    return this.processors.removeAll(c);
+  }
+
+  /**
+   * @see List#retainAll(Collection)
+   */
+  public boolean retainAll(Collection<?> c) {
+    return this.processors.retainAll(c);
+  }
+
+  /**
+   * @see List#set(int, Object)
+   */
+  public QueryNodeProcessor set(int index, QueryNodeProcessor processor) {
+    QueryNodeProcessor oldProcessor = this.processors.set(index, processor);
+    
+    if (oldProcessor != processor) {
+      processor.setQueryConfigHandler(this.queryConfig);
+    }
+    
+    return oldProcessor;
+    
+  }
+
+  /**
+   * @see List#size()
+   */
+  public int size() {
+    return this.processors.size();
+  }
+
+  /**
+   * @see List#subList(int, int)
+   */
+  public List<QueryNodeProcessor> subList(int fromIndex, int toIndex) {
+    return this.processors.subList(fromIndex, toIndex);
+  }
+
+  /**
+   * @see List#toArray(Object[])
+   */
+  public <T> T[] toArray(T[] array) {
+    return this.processors.toArray(array);
+  }
+
+  /**
+   * @see List#toArray()
+   */
+  public Object[] toArray() {
+    return this.processors.toArray();
+  }
+
 }

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java Tue Oct 19 20:33:54 2010
@@ -48,23 +48,23 @@ public class StandardQueryNodeProcessorP
   public StandardQueryNodeProcessorPipeline(QueryConfigHandler queryConfig) {
     super(queryConfig);
 
-    addProcessor(new WildcardQueryNodeProcessor());    
-    addProcessor(new MultiFieldQueryNodeProcessor());
-    addProcessor(new FuzzyQueryNodeProcessor());
-    addProcessor(new MatchAllDocsQueryNodeProcessor());
-    addProcessor(new LowercaseExpandedTermsQueryNodeProcessor());
-    addProcessor(new ParametricRangeQueryNodeProcessor());
-    addProcessor(new AllowLeadingWildcardProcessor());    
-    addProcessor(new AnalyzerQueryNodeProcessor());
-    addProcessor(new PhraseSlopQueryNodeProcessor());
-    addProcessor(new GroupQueryNodeProcessor());
-    addProcessor(new NoChildOptimizationQueryNodeProcessor());
-    addProcessor(new RemoveDeletedQueryNodesProcessor());
-    addProcessor(new RemoveEmptyNonLeafQueryNodeProcessor());
-    addProcessor(new BooleanSingleChildOptimizationQueryNodeProcessor());
-    addProcessor(new DefaultPhraseSlopQueryNodeProcessor());
-    addProcessor(new BoostQueryNodeProcessor());    
-    addProcessor(new MultiTermRewriteMethodProcessor());
+    add(new WildcardQueryNodeProcessor());    
+    add(new MultiFieldQueryNodeProcessor());
+    add(new FuzzyQueryNodeProcessor());
+    add(new MatchAllDocsQueryNodeProcessor());
+    add(new LowercaseExpandedTermsQueryNodeProcessor());
+    add(new ParametricRangeQueryNodeProcessor());
+    add(new AllowLeadingWildcardProcessor());    
+    add(new AnalyzerQueryNodeProcessor());
+    add(new PhraseSlopQueryNodeProcessor());
+    add(new GroupQueryNodeProcessor());
+    add(new NoChildOptimizationQueryNodeProcessor());
+    add(new RemoveDeletedQueryNodesProcessor());
+    add(new RemoveEmptyNonLeafQueryNodeProcessor());
+    add(new BooleanSingleChildOptimizationQueryNodeProcessor());
+    add(new DefaultPhraseSlopQueryNodeProcessor());
+    add(new BoostQueryNodeProcessor());    
+    add(new MultiTermRewriteMethodProcessor());
   }
 
 }

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java Tue Oct 19 20:33:54 2010
@@ -117,11 +117,9 @@ public class TestSpanQueryParser extends
     this.spanProcessorPipeline
         .setQueryConfigHandler(this.spanQueryConfigHandler);
 
-    this.spanProcessorPipeline.addProcessor(new WildcardQueryNodeProcessor());
-    this.spanProcessorPipeline
-        .addProcessor(new SpansValidatorQueryNodeProcessor());
-    this.spanProcessorPipeline
-        .addProcessor(new UniqueFieldQueryNodeProcessor());
+    this.spanProcessorPipeline.add(new WildcardQueryNodeProcessor());
+    this.spanProcessorPipeline.add(new SpansValidatorQueryNodeProcessor());
+    this.spanProcessorPipeline.add(new UniqueFieldQueryNodeProcessor());
 
   }
 

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParserSimpleSample.java Tue Oct 19 20:33:54 2010
@@ -113,9 +113,9 @@ public class TestSpanQueryParserSimpleSa
     QueryNodeProcessorPipeline spanProcessorPipeline = new QueryNodeProcessorPipeline(
         spanQueryConfigHandler);
     // @see SpansValidatorQueryNodeProcessor
-    spanProcessorPipeline.addProcessor(new SpansValidatorQueryNodeProcessor());
+    spanProcessorPipeline.add(new SpansValidatorQueryNodeProcessor());
     // @see UniqueFieldQueryNodeProcessor
-    spanProcessorPipeline.addProcessor(new UniqueFieldQueryNodeProcessor());
+    spanProcessorPipeline.add(new UniqueFieldQueryNodeProcessor());
 
     // print to show out the QueryNode tree before being processed
     if (VERBOSE) System.out.println(queryTree);

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java Tue Oct 19 20:33:54 2010
@@ -138,7 +138,7 @@ public class TestQPHelper extends Lucene
   public static class QPTestParser extends StandardQueryParser {
     public QPTestParser(Analyzer a) {
       ((QueryNodeProcessorPipeline)getQueryNodeProcessor())
-          .addProcessor(new QPTestParserQueryNodeProcessor());
+          .add(new QPTestParserQueryNodeProcessor());
       this.setAnalyzer(a);
 
     }

Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java?rev=1024402&r1=1024401&r2=1024402&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java Tue Oct 19 20:33:54 2010
@@ -139,9 +139,9 @@ public class TestQueryParserWrapper exte
 
       QueryNodeProcessorPipeline newProcessorPipeline = new QueryNodeProcessorPipeline(
           getQueryProcessor().getQueryConfigHandler());
-      newProcessorPipeline.addProcessor(new WildcardQueryNodeProcessor());
-      newProcessorPipeline.addProcessor(new QPTestParserQueryNodeProcessor());
-      newProcessorPipeline.addProcessor(getQueryProcessor());
+      newProcessorPipeline.add(new WildcardQueryNodeProcessor());
+      newProcessorPipeline.add(new QPTestParserQueryNodeProcessor());
+      newProcessorPipeline.add(getQueryProcessor());
 
       setQueryProcessor(newProcessorPipeline);