Author: brett
Date: Sun Jan  8 17:47:23 2006
New Revision: 367157

URL: http://svn.apache.org/viewcvs?rev=367157&view=rev
Log:
restructure querying to make construction more intuitive

Added:
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
   (contents, props changed)
      - copied, changed from r367102, 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
   (with props)
Removed:
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OptionalQuery.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RequiredQuery.java
Modified:
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java

Modified: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java?rev=367157&r1=367156&r2=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
 Sun Jan  8 17:47:23 2006
@@ -24,10 +24,9 @@
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
-import org.apache.maven.repository.indexing.query.AbstractCompoundQuery;
-import org.apache.maven.repository.indexing.query.OptionalQuery;
+import org.apache.maven.repository.indexing.query.CompoundQuery;
+import org.apache.maven.repository.indexing.query.CompoundQueryTerm;
 import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.RequiredQuery;
 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
 
 import java.io.IOException;
@@ -43,18 +42,12 @@
 {
     protected RepositoryIndex index;
 
-    private BooleanQuery bQry;
-
-    private BooleanQuery mainQry;
-
-    private boolean isRequired = true;
-
     /**
      * Constructor
      *
      * @param index the index object
      */
-    public AbstractRepositoryIndexSearcher( RepositoryIndex index )
+    protected AbstractRepositoryIndexSearcher( RepositoryIndex index )
     {
         this.index = index;
     }
@@ -70,9 +63,7 @@
     public List search( Query query )
         throws RepositoryIndexSearchException
     {
-        List artifactList = null;
-        IndexSearcher searcher = null;
-        Hits hits = null;
+        IndexSearcher searcher;
 
         try
         {
@@ -83,43 +74,21 @@
             throw new RepositoryIndexSearchException( e.getMessage(), e );
         }
 
-        if ( query instanceof SinglePhraseQuery )
+        Hits hits;
+        try
         {
-            SinglePhraseQuery singleQry = (SinglePhraseQuery) query;
-            createSubQuery();
-            try
-            {
-                addQuery( singleQry.getField(), singleQry.getValue(), true, 
false );
-                hits = searcher.search( bQry );
-            }
-            catch ( IOException ie )
-            {
-                throw new RepositoryIndexSearchException( ie.getMessage(), ie 
);
-            }
-            catch ( ParseException pe )
-            {
-                throw new RepositoryIndexSearchException( pe.getMessage(), pe 
);
-            }
-
+            hits = searcher.search( createLuceneQuery( query ) );
         }
-        else if ( query instanceof RequiredQuery || query instanceof 
OptionalQuery )
+        catch ( IOException e )
         {
-            createMainQuery();
-            try
-            {
-                buildCompoundQuery( query );
-                hits = searcher.search( mainQry );
-            }
-            catch ( IOException ie )
-            {
-                throw new RepositoryIndexSearchException( ie.getMessage(), ie 
);
-            }
-            catch ( ParseException pe )
-            {
-                throw new RepositoryIndexSearchException( pe.getMessage(), pe 
);
-            }
+            throw new RepositoryIndexSearchException( e.getMessage(), e );
+        }
+        catch ( ParseException e )
+        {
+            throw new RepositoryIndexSearchException( e.getMessage(), e );
         }
 
+        List artifactList;
         try
         {
             artifactList = buildList( hits );
@@ -133,44 +102,7 @@
         return artifactList;
     }
 
-    /**
-     * Create a main BooleanQuery object that will contain the other
-     * BooleanQuery objects.
-     */
-    private void createMainQuery()
-    {
-        mainQry = new BooleanQuery();
-    }
-
-    /**
-     * Add the other BooleanQuery objects to the main BooleanQuery object
-     *
-     * @param required   specifies if the search is AND or OR
-     * @param prohibited specifies if NOT will be used in the search
-     */
-    private void addToMainQuery( boolean required, boolean prohibited )
-    {
-        mainQry.add( bQry, required, prohibited );
-    }
-
-    /**
-     * Create a new BooleanQuery object for nested search
-     */
-    private void createSubQuery()
-    {
-        bQry = new BooleanQuery();
-    }
-
-    /**
-     * Add query to the globally declared BooleanQuery object
-     *
-     * @param field      the name of the field in the index where the value is 
to be searched
-     * @param value      the value to be searched in the index
-     * @param required   specifies if the search is AND or OR
-     * @param prohibited specifies if NOT will be used in the search
-     * @throws ParseException
-     */
-    private void addQuery( String field, String value, boolean required, 
boolean prohibited )
+    private org.apache.lucene.search.Query createLuceneQuery( String field, 
String value )
         throws ParseException
     {
         org.apache.lucene.search.Query qry;
@@ -184,62 +116,35 @@
             QueryParser parser = new QueryParser( field, index.getAnalyzer() );
             qry = parser.parse( value );
         }
-        bQry.add( qry, required, prohibited );
+        return qry;
     }
 
-    /**
-     * Build or construct the query that will be used by the searcher
-     *
-     * @param query the query object that contains the search criteria
-     * @throws ParseException
-     */
-    private void buildCompoundQuery( Query query )
+    private org.apache.lucene.search.Query createLuceneQuery( Query query )
         throws ParseException
     {
-        AbstractCompoundQuery cQry = null;
-        boolean required = false;
+        org.apache.lucene.search.Query retVal;
 
-        if ( query instanceof RequiredQuery )
+        if ( query instanceof CompoundQuery )
         {
-            cQry = (RequiredQuery) query;
-            required = true;
-        }
-        else
-        {
-            cQry = (OptionalQuery) query;
-            required = false;
-        }
-
-        boolean reset = true;
-
-        // get the query list and iterate through each
-        List queries = cQry.getQueryList();
-        for ( Iterator iter = queries.iterator(); iter.hasNext(); )
-        {
-            Query query2 = (Query) iter.next();
-
-            if ( query2 instanceof SinglePhraseQuery )
+            BooleanQuery booleanQuery = new BooleanQuery();
+            CompoundQuery compoundQuery = (CompoundQuery) query;
+            List queries = compoundQuery.getQueries();
+            for ( Iterator i = queries.iterator(); i.hasNext(); )
             {
-                SinglePhraseQuery sQry = (SinglePhraseQuery) query2;
-                if ( reset )
-                {
-                    createSubQuery();
-                }
-                addQuery( sQry.getField(), sQry.getValue(), required, false );
-                reset = false;
-
-                if ( !iter.hasNext() )
-                {
-                    addToMainQuery( isRequired, false );
-                }
+                CompoundQueryTerm subquery = (CompoundQueryTerm) i.next();
 
+                org.apache.lucene.search.Query luceneQuery = 
createLuceneQuery( subquery.getQuery() );
+
+                booleanQuery.add( luceneQuery, subquery.isRequired(), 
subquery.isProhibited() );
             }
-            else if ( query2 instanceof RequiredQuery || query2 instanceof 
OptionalQuery )
-            {
-                isRequired = required;
-                buildCompoundQuery( query2 );
-            }
+            retVal = booleanQuery;
+        }
+        else
+        {
+            SinglePhraseQuery singlePhraseQuery = (SinglePhraseQuery) query;
+            retVal = createLuceneQuery( singlePhraseQuery.getField(), 
singlePhraseQuery.getValue() );
         }
+        return retVal;
     }
 
     /**

Modified: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java?rev=367157&r1=367156&r2=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
 Sun Jan  8 17:47:23 2006
@@ -25,14 +25,6 @@
 public class PomRepositoryIndexSearcher
     extends AbstractRepositoryIndexSearcher
 {
-    private static final String GROUPID = "groupId";
-
-    private static final String ARTIFACTID = "artifactId";
-
-    private static final String VERSION = "version";
-
-    private static final String PACKAGING = "packaging";
-
     private ArtifactFactory factory;
 
     public PomRepositoryIndexSearcher( RepositoryIndex index, ArtifactFactory 
artifactFactory )

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java?rev=367157&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
 Sun Jan  8 17:47:23 2006
@@ -0,0 +1,51 @@
+package org.apache.maven.repository.indexing.query;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Base of all query terms.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ */
+public abstract class AbstractCompoundQueryTerm
+    implements CompoundQueryTerm
+{
+    /**
+     * The query being added.
+     */
+    private Query query;
+
+    protected AbstractCompoundQueryTerm( Query query )
+    {
+        this.query = query;
+    }
+
+    public boolean isRequired()
+    {
+        return false;
+    }
+
+    public boolean isProhibited()
+    {
+        return false;
+    }
+
+    public Query getQuery()
+    {
+        return query;
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java?rev=367157&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
 Sun Jan  8 17:47:23 2006
@@ -0,0 +1,36 @@
+package org.apache.maven.repository.indexing.query;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A Boolean AND join for queries.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ */
+public class AndQueryTerm
+    extends AbstractCompoundQueryTerm
+{
+    public AndQueryTerm( Query query )
+    {
+        super( query );
+    }
+
+    public boolean isRequired()
+    {
+        return true;
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
 (from r367102, 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java)
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java?p2=maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java&p1=maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java&r1=367102&r2=367157&rev=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
 Sun Jan  8 17:47:23 2006
@@ -1,14 +1,13 @@
 package org.apache.maven.repository.indexing.query;
 
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
- 
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,22 +22,32 @@
 /**
  * @author Edwin Punzalan
  */
-public abstract class AbstractCompoundQuery
+public class CompoundQuery
     implements Query
 {
     protected List queries;
 
-    public AbstractCompoundQuery()
+    public CompoundQuery()
     {
         queries = new ArrayList();
     }
 
-    public void add( Query query )
+    public void and( Query query )
     {
-        queries.add( query );
+        queries.add( new AndQueryTerm( query ) );
     }
 
-    public List getQueryList()
+    public void or( Query query )
+    {
+        queries.add( new OrQueryTerm( query ) );
+    }
+
+    public void not( Query query )
+    {
+        queries.add( new NotQueryTerm( query ) );
+    }
+
+    public List getQueries()
     {
         return queries;
     }

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java?rev=367157&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
 Sun Jan  8 17:47:23 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.repository.indexing.query;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Term in a compound query.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ */
+public interface CompoundQueryTerm
+{
+    boolean isRequired();
+
+    boolean isProhibited();
+
+    Query getQuery();
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java?rev=367157&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
 Sun Jan  8 17:47:23 2006
@@ -0,0 +1,36 @@
+package org.apache.maven.repository.indexing.query;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A boolean NOT query term.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ */
+public class NotQueryTerm
+    extends AbstractCompoundQueryTerm
+{
+    public NotQueryTerm( Query query )
+    {
+        super( query );
+    }
+
+    public boolean isProhibited()
+    {
+        return true;
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java?rev=367157&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
 Sun Jan  8 17:47:23 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.repository.indexing.query;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A boolean OR join term.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ */
+public class OrQueryTerm
+    extends AbstractCompoundQueryTerm
+{
+    public OrQueryTerm( Query query )
+    {
+        super( query );
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java?rev=367157&r1=367156&r2=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
 Sun Jan  8 17:47:23 2006
@@ -23,9 +23,8 @@
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.repository.digest.DefaultDigester;
 import org.apache.maven.repository.digest.Digester;
-import org.apache.maven.repository.indexing.query.OptionalQuery;
+import org.apache.maven.repository.indexing.query.CompoundQuery;
 import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.RequiredQuery;
 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
@@ -314,9 +313,9 @@
         // ex. artifactId=maven-artifact AND groupId=org.apache.maven
         Query qry1 = new SinglePhraseQuery( ARTIFACTID, "maven-artifact" );
         Query qry2 = new SinglePhraseQuery( GROUPID, "org.apache.maven" );
-        RequiredQuery rQry = new RequiredQuery();
-        rQry.add( qry1 );
-        rQry.add( qry2 );
+        CompoundQuery rQry = new CompoundQuery();
+        rQry.and( qry1 );
+        rQry.and( qry2 );
 
         List artifacts = repoSearcher.search( rQry );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -330,9 +329,9 @@
         // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) OR
         // version=2.0.3
         Query qry3 = new SinglePhraseQuery( VERSION, "2.0.3" );
-        OptionalQuery oQry = new OptionalQuery();
-        oQry.add( rQry );
-        oQry.add( qry3 );
+        CompoundQuery oQry = new CompoundQuery();
+        oQry.or( rQry );
+        oQry.or( qry3 );
 
         artifacts = repoSearcher.search( oQry );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -347,20 +346,20 @@
         // (version=2.0.3 OR version=2.0.1)
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)
         Query qry4 = new SinglePhraseQuery( VERSION, "2.0.1" );
-        oQry = new OptionalQuery();
-        oQry.add( qry3 );
-        oQry.add( qry4 );
+        oQry = new CompoundQuery();
+        oQry.or( qry3 );
+        oQry.or( qry4 );
 
-        OptionalQuery oQry5 = new OptionalQuery();
+        CompoundQuery oQry5 = new CompoundQuery();
         Query qry9 = new SinglePhraseQuery( NAME, "maven-artifact-2.0.1.jar" );
         Query qry10 = new SinglePhraseQuery( NAME, "maven-artifact" );
-        oQry5.add( qry9 );
-        oQry5.add( qry10 );
+        oQry5.or( qry9 );
+        oQry5.or( qry10 );
 
-        RequiredQuery rQry2 = new RequiredQuery();
-        rQry2.add( oQry );
-        rQry2.add( rQry );
-        rQry2.add( oQry5 );
+        CompoundQuery rQry2 = new CompoundQuery();
+        rQry2.or( oQry );
+        rQry2.and( rQry );
+        rQry2.or( oQry5 );
 
         artifacts = repoSearcher.search( rQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -376,14 +375,14 @@
         // (version=2.0.3 OR version=2.0.1)
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)]
         // OR [(artifactId=sample AND groupId=test)]
-        RequiredQuery rQry3 = new RequiredQuery();
+        CompoundQuery rQry3 = new CompoundQuery();
         Query qry5 = new SinglePhraseQuery( ARTIFACTID, "sample" );
         Query qry6 = new SinglePhraseQuery( GROUPID, "test" );
-        rQry3.add( qry5 );
-        rQry3.add( qry6 );
-        OptionalQuery oQry2 = new OptionalQuery();
-        oQry2.add( rQry2 );
-        oQry2.add( rQry3 );
+        rQry3.and( qry5 );
+        rQry3.and( qry6 );
+        CompoundQuery oQry2 = new CompoundQuery();
+        oQry2.and( rQry2 );
+        oQry2.and( rQry3 );
 
         artifacts = repoSearcher.search( oQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -400,12 +399,12 @@
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)] OR
         // [(artifactId=sample AND groupId=test)] OR
         // [(artifactId=sample2 AND groupId=test)]
-        RequiredQuery rQry4 = new RequiredQuery();
+        CompoundQuery rQry4 = new CompoundQuery();
         Query qry7 = new SinglePhraseQuery( ARTIFACTID, "sample2" );
         Query qry8 = new SinglePhraseQuery( GROUPID, "test" );
-        rQry4.add( qry7 );
-        rQry4.add( qry8 );
-        oQry2.add( rQry4 );
+        rQry4.and( qry7 );
+        rQry4.and( qry8 );
+        oQry2.and( rQry4 );
 
         artifacts = repoSearcher.search( oQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )

Modified: 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java?rev=367157&r1=367156&r2=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/PomRepositoryIndexingTest.java
 Sun Jan  8 17:47:23 2006
@@ -29,9 +29,8 @@
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.repository.digest.DefaultDigester;
 import org.apache.maven.repository.digest.Digester;
-import org.apache.maven.repository.indexing.query.OptionalQuery;
+import org.apache.maven.repository.indexing.query.CompoundQuery;
 import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.RequiredQuery;
 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
@@ -74,7 +73,6 @@
     public void testIndexerExceptions()
         throws Exception
     {
-        PomRepositoryIndex indexer;
         RepositoryIndexingFactory factory = (RepositoryIndexingFactory) 
lookup( RepositoryIndexingFactory.ROLE );
 
         try
@@ -101,7 +99,7 @@
 
         Model pom = getPom( "test", "test-artifactId", "1.0" );
 
-        indexer = factory.createPomRepositoryIndex( indexPath, repository );
+        PomRepositoryIndex indexer = factory.createPomRepositoryIndex( 
indexPath, repository );
         indexer.close();
 
         try
@@ -228,8 +226,8 @@
             while ( dependencies.hasNext() )
             {
                 Dependency dep = (Dependency) dependencies.next();
-                if ( ( dep.getGroupId() + ":" + dep.getArtifactId() + ":" + 
dep.getVersion() ).equals(
-                    "org.codehaus.plexus:plexus-utils:1.0.5" ) )
+                if ( "org.codehaus.plexus:plexus-utils:1.0.5".equals(
+                    dep.getGroupId() + ":" + dep.getArtifactId() + ":" + 
dep.getVersion() ) )
                 {
                     depFound = true;
                     break;
@@ -251,8 +249,8 @@
             while ( plugins.hasNext() )
             {
                 Plugin plugin = (Plugin) plugins.next();
-                if ( ( plugin.getKey() + ":" + plugin.getVersion() ).equals(
-                    "org.codehaus.modello:modello-maven-plugin:2.0" ) )
+                if ( "org.codehaus.modello:modello-maven-plugin:2.0".equals(
+                    plugin.getKey() + ":" + plugin.getVersion() ) )
                 {
                     found = true;
                     break;
@@ -274,8 +272,8 @@
             while ( plugins.hasNext() )
             {
                 ReportPlugin plugin = (ReportPlugin) plugins.next();
-                if ( ( plugin.getKey() + ":" + plugin.getVersion() ).equals(
-                    "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" ) )
+                if ( 
"org.apache.maven.plugins:maven-checkstyle-plugin:2.0".equals(
+                    plugin.getKey() + ":" + plugin.getVersion() ) )
                 {
                     found = true;
                     break;
@@ -295,7 +293,7 @@
         for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
         {
             Artifact artifact2 = (Artifact) artifacts.next();
-            String sha1Tmp = digester.createChecksum( getPomFile( artifact ), 
Digester.SHA1 );
+            String sha1Tmp = digester.createChecksum( getPomFile( artifact2 ), 
Digester.SHA1 );
             assertEquals( sha1, sha1Tmp );
         }
 
@@ -332,9 +330,9 @@
         // ex. artifactId=maven-artifact AND groupId=org.apache.maven
         Query qry1 = new SinglePhraseQuery( PomRepositoryIndex.FLD_ARTIFACTID, 
"maven-artifact" );
         Query qry2 = new SinglePhraseQuery( PomRepositoryIndex.FLD_GROUPID, 
"org.apache.maven" );
-        RequiredQuery rQry = new RequiredQuery();
-        rQry.add( qry1 );
-        rQry.add( qry2 );
+        CompoundQuery rQry = new CompoundQuery();
+        rQry.and( qry1 );
+        rQry.and( qry2 );
 
         List artifacts = repoSearcher.search( rQry );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -348,9 +346,9 @@
         // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) OR
         // version=2.0.3
         Query qry3 = new SinglePhraseQuery( PomRepositoryIndex.FLD_VERSION, 
"2.0.3" );
-        OptionalQuery oQry = new OptionalQuery();
-        oQry.add( rQry );
-        oQry.add( qry3 );
+        CompoundQuery oQry = new CompoundQuery();
+        oQry.and( rQry );
+        oQry.or( qry3 );
 
         artifacts = repoSearcher.search( oQry );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -365,22 +363,22 @@
         // (version=2.0.3 OR version=2.0.1)
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)
         Query qry4 = new SinglePhraseQuery( PomRepositoryIndex.FLD_VERSION, 
"2.0.1" );
-        oQry = new OptionalQuery();
-        oQry.add( qry3 );
-        oQry.add( qry4 );
+        oQry = new CompoundQuery();
+        oQry.or( qry3 );
+        oQry.or( qry4 );
 
-        OptionalQuery oQry5 = new OptionalQuery();
+        CompoundQuery oQry5 = new CompoundQuery();
         Query qry9 =
             new SinglePhraseQuery( PomRepositoryIndex.FLD_DEPENDENCIES, 
"org.codehaus.plexus:plexus-utils:1.0.5" );
         Query qry10 = new SinglePhraseQuery( 
PomRepositoryIndex.FLD_DEPENDENCIES,
                                              
"org.codehaus.plexus:plexus-container-defualt:1.0-alpha-9" );
-        oQry5.add( qry9 );
-        oQry5.add( qry10 );
+        oQry5.or( qry9 );
+        oQry5.or( qry10 );
 
-        RequiredQuery rQry2 = new RequiredQuery();
-        rQry2.add( oQry );
-        rQry2.add( rQry );
-        rQry2.add( oQry5 );
+        CompoundQuery rQry2 = new CompoundQuery();
+        rQry2.or( oQry );
+        rQry2.and( rQry );
+        rQry2.and( oQry5 );
 
         artifacts = repoSearcher.search( rQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -396,14 +394,14 @@
         // (version=2.0.3 OR version=2.0.1)
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)]
         // OR [(artifactId=sample AND groupId=test)]
-        RequiredQuery rQry3 = new RequiredQuery();
+        CompoundQuery rQry3 = new CompoundQuery();
         Query qry5 = new SinglePhraseQuery( PomRepositoryIndex.FLD_ARTIFACTID, 
"sample" );
         Query qry6 = new SinglePhraseQuery( PomRepositoryIndex.FLD_GROUPID, 
"test" );
-        rQry3.add( qry5 );
-        rQry3.add( qry6 );
-        OptionalQuery oQry2 = new OptionalQuery();
-        oQry2.add( rQry2 );
-        oQry2.add( rQry3 );
+        rQry3.and( qry5 );
+        rQry3.and( qry6 );
+        CompoundQuery oQry2 = new CompoundQuery();
+        oQry2.and( rQry2 );
+        oQry2.and( rQry3 );
 
         artifacts = repoSearcher.search( oQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -420,12 +418,12 @@
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)] OR
         // [(artifactId=sample AND groupId=test)] OR
         // [(artifactId=sample2 AND groupId=test)]
-        RequiredQuery rQry4 = new RequiredQuery();
+        CompoundQuery rQry4 = new CompoundQuery();
         Query qry7 = new SinglePhraseQuery( PomRepositoryIndex.FLD_ARTIFACTID, 
"sample2" );
         Query qry8 = new SinglePhraseQuery( PomRepositoryIndex.FLD_GROUPID, 
"test" );
-        rQry4.add( qry7 );
-        rQry4.add( qry8 );
-        oQry2.add( rQry4 );
+        rQry4.and( qry7 );
+        rQry4.and( qry8 );
+        oQry2.and( rQry4 );
 
         artifacts = repoSearcher.search( oQry2 );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )

Modified: 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java?rev=367157&r1=367156&r2=367157&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java
 Sun Jan  8 17:47:23 2006
@@ -28,57 +28,49 @@
     public void testSinglePhraseQueryObject()
     {
         SinglePhraseQuery query = new SinglePhraseQuery( "Field", "Value" );
-        assertTrue( query instanceof Query );
         assertEquals( "Field", query.getField() );
         assertEquals( "Value", query.getValue() );
     }
 
     public void testCompoundQueries()
     {
-        RequiredQuery rQuery = new RequiredQuery();
-        assertTrue( rQuery instanceof Query );
-        rQuery.add( new SinglePhraseQuery( "r1Field", "r1Value" ) );
-        rQuery.add( new SinglePhraseQuery( "r2Field", "r2Value" ) );
-
-        OptionalQuery oQuery = new OptionalQuery();
-        oQuery.add( new SinglePhraseQuery( "oField", "oValue" ) );
-
-        RequiredQuery all = new RequiredQuery();
-        all.add( rQuery );
-        all.add( oQuery );
-        assertEquals( 2, all.getQueryList().size() );
-
-        for ( int ctr = 0; ctr < all.getQueryList().size(); ctr++ )
-        {
-            Query query = (Query) all.getQueryList().get( ctr );
-            switch ( ctr )
-            {
-                case 0:
-                    assertTrue( query instanceof RequiredQuery );
-                    rQuery = (RequiredQuery) query;
-                    assertEquals( 2, rQuery.getQueryList().size() );
-                    query = (Query) rQuery.getQueryList().get( 0 );
-                    assertTrue( query instanceof SinglePhraseQuery );
-                    SinglePhraseQuery sQuery = (SinglePhraseQuery) query;
-                    assertEquals( "r1Field", sQuery.getField() );
-                    assertEquals( "r1Value", sQuery.getValue() );
-                    query = (Query) rQuery.getQueryList().get( 1 );
-                    assertTrue( query instanceof SinglePhraseQuery );
-                    sQuery = (SinglePhraseQuery) query;
-                    assertEquals( "r2Field", sQuery.getField() );
-                    assertEquals( "r2Value", sQuery.getValue() );
-                    break;
-                case 1:
-                    assertTrue( query instanceof OptionalQuery );
-                    oQuery = (OptionalQuery) query;
-                    assertEquals( 1, oQuery.getQueryList().size() );
-                    query = (Query) oQuery.getQueryList().get( 0 );
-                    assertTrue( query instanceof SinglePhraseQuery );
-                    sQuery = (SinglePhraseQuery) query;
-                    assertEquals( "oField", sQuery.getField() );
-                    assertEquals( "oValue", sQuery.getValue() );
-                    break;
-            }
-        }
+        CompoundQuery rQuery = new CompoundQuery();
+        rQuery.and( new SinglePhraseQuery( "r1Field", "r1Value" ) );
+        rQuery.and( new SinglePhraseQuery( "r2Field", "r2Value" ) );
+
+        CompoundQuery oQuery = new CompoundQuery();
+        oQuery.or( new SinglePhraseQuery( "oField", "oValue" ) );
+
+        CompoundQuery all = new CompoundQuery();
+        all.and( rQuery );
+        all.or( oQuery );
+        assertEquals( 2, all.getQueries().size() );
+
+        CompoundQueryTerm queryTerm = (CompoundQueryTerm) 
all.getQueries().get( 0 );
+        assertTrue( queryTerm.getQuery() instanceof CompoundQuery );
+        rQuery = (CompoundQuery) queryTerm.getQuery();
+        assertEquals( 2, rQuery.getQueries().size() );
+        queryTerm = (CompoundQueryTerm) rQuery.getQueries().get( 0 );
+        assertTrue( queryTerm.getQuery() instanceof SinglePhraseQuery );
+        SinglePhraseQuery sQuery = (SinglePhraseQuery) queryTerm.getQuery();
+        assertEquals( "r1Field", sQuery.getField() );
+        assertEquals( "r1Value", sQuery.getValue() );
+        queryTerm = (CompoundQueryTerm) rQuery.getQueries().get( 1 );
+        assertTrue( queryTerm.getQuery() instanceof SinglePhraseQuery );
+        sQuery = (SinglePhraseQuery) queryTerm.getQuery();
+        assertEquals( "r2Field", sQuery.getField() );
+        assertEquals( "r2Value", sQuery.getValue() );
+
+        queryTerm = (CompoundQueryTerm) all.getQueries().get( 1 );
+        assertTrue( queryTerm.getQuery() instanceof CompoundQuery );
+        rQuery = (CompoundQuery) queryTerm.getQuery();
+        assertEquals( 1, rQuery.getQueries().size() );
+        queryTerm = (CompoundQueryTerm) rQuery.getQueries().get( 0 );
+        assertTrue( queryTerm.getQuery() instanceof SinglePhraseQuery );
+        sQuery = (SinglePhraseQuery) queryTerm.getQuery();
+        assertEquals( "oField", sQuery.getField() );
+        assertEquals( "oValue", sQuery.getValue() );
+
     }
 }
+


Reply via email to