maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r425298 - in /maven/repository-manager/trunk: maven-repository-indexer/ maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/ maven-re...
Date Tue, 25 Jul 2006 06:02:20 GMT
Author: brett
Date: Mon Jul 24 23:02:19 2006
New Revision: 425298

URL: http://svn.apache.org/viewvc?rev=425298&view=rev
Log:
[MNG-127] start refactoring by clarifying terminology (this is more inline with what Lucene has). Take some additional notes.

Added:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java   (contents, props changed)
      - copied, changed from r425040, maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SinglePhraseQuery.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/site/
Removed:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQueryTerm.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AndQueryTerm.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/NotQueryTerm.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/OrQueryTerm.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SinglePhraseQuery.java
Modified:
    maven/repository-manager/trunk/maven-repository-indexer/   (props changed)
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.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/MetadataRepositoryIndexingTest.java
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
    maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java

Propchange: maven/repository-manager/trunk/maven-repository-indexer/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Jul 24 23:02:19 2006
@@ -1,4 +1,3 @@
-
 target
 *.iml
 .classpath

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearchLayer.java Mon Jul 24 23:02:19 2006
@@ -24,7 +24,8 @@
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
+import org.apache.maven.repository.indexing.query.QueryTerm;
+import org.apache.maven.repository.indexing.query.SingleTermQuery;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -61,8 +62,9 @@
         List generalSearchResults = new ArrayList();
         for ( int i = 0; i < RepositoryIndex.FIELDS.length; i++ )
         {
-            Query qry = new SinglePhraseQuery( RepositoryIndex.FIELDS[i], keyword );
-            List results = searchAdvanced( qry, index );
+            // TODO! does simply iterating the fields and searching each perform well enough and yield correct rankings?
+            QueryTerm term = new QueryTerm( RepositoryIndex.FIELDS[i], keyword );
+            List results = searchAdvanced( new SingleTermQuery( term ), index );
             for ( Iterator iter = results.iterator(); iter.hasNext(); )
             {
                 SearchResult result = (SearchResult) iter.next();
@@ -104,6 +106,7 @@
                 fields.put( RepositoryIndex.FLD_SHA1, map.get( RepositoryIndex.FLD_SHA1 ) );
                 fields.put( RepositoryIndex.FLD_MD5, map.get( RepositoryIndex.FLD_MD5 ) );
 
+                // TODO! this doesn't seem like the correct way to determine what matched
                 result.setFieldMatches( fields );
                 searchResults.add( result );
             }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java Mon Jul 24 23:02:19 2006
@@ -118,15 +118,8 @@
         return docs;
     }
 
-    /**
-     * Method for creating the object to be returned for the search
-     *
-     * @param doc        the index document where the object field values will be retrieved from
-     * @param repository
-     * @return Object
-     */
-    protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc,
-                                                                              ArtifactRepository repository )
+    private RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc,
+                                                                            ArtifactRepository repository )
         throws RepositoryIndexSearchException
     {
         RepositoryIndexSearchHit searchHit = null;
@@ -142,6 +135,7 @@
 
             artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
 
+            // TODO: introduce strongly types search result!
             Map map = new HashMap();
             map.put( RepositoryIndex.ARTIFACT, artifact );
             map.put( RepositoryIndex.FLD_CLASSES, doc.get( RepositoryIndex.FLD_CLASSES ) );
@@ -159,6 +153,7 @@
         {
             Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );
 
+            // TODO: introduce strongly types search result! Don't read the POM here, though - populate with the data from the index
             searchHit = new RepositoryIndexSearchHit( false, false, true );
             searchHit.setObject( readPom( pomArtifact, repository ) );
         }
@@ -180,18 +175,19 @@
             if ( tmpDir.equals( version ) )
             {
                 repoMetadata = new SnapshotArtifactRepositoryMetadata(
-                    factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
+                    factory.createProjectArtifact( groupId, artifactId, version ) );
             }
             else if ( tmpDir.equals( artifactId ) )
             {
-                repoMetadata = new ArtifactRepositoryMetadata(
-                    factory.createBuildArtifact( groupId, artifactId, version, "jar" ) );
+                repoMetadata =
+                    new ArtifactRepositoryMetadata( factory.createProjectArtifact( groupId, artifactId, version ) );
             }
             else
             {
                 repoMetadata = new GroupRepositoryMetadata( groupId );
             }
 
+            // TODO: introduce strongly types search result! Don't read the metadata here, though - populate with the data from the index
             repoMetadata.setMetadata( readMetadata( repoMetadata, repository ) );
 
             searchHit = new RepositoryIndexSearchHit( false, true, false );
@@ -201,11 +197,6 @@
         return searchHit;
     }
 
-    /**
-     * Create RepositoryMetadata object.
-     *
-     * @return RepositoryMetadata
-     */
     private Metadata readMetadata( RepositoryMetadata repoMetadata, ArtifactRepository repository )
         throws RepositoryIndexSearchException
     {
@@ -237,11 +228,6 @@
         }
     }
 
-    /**
-     * Create RepositoryMetadata object.
-     *
-     * @return RepositoryMetadata
-     */
     private Model readPom( Artifact pomArtifact, ArtifactRepository repository )
         throws RepositoryIndexSearchException
     {

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java Mon Jul 24 23:02:19 2006
@@ -87,6 +87,8 @@
 
     /**
      * Method to encapsulate the optimize() method for lucene
+     *
+     * @throws RepositoryIndexException if there is a problem optimizing the index.
      */
     void optimize()
         throws RepositoryIndexException;

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java Mon Jul 24 23:02:19 2006
@@ -32,47 +32,69 @@
 public class CompoundQuery
     implements Query
 {
-    protected List queries;
+    /**
+     * The query terms.
+     */
+    private final List compoundQueryTerms = new ArrayList();
+
+    /**
+     * Appends a required term to this query.
+     *
+     * @param term the term to be appended to this query
+     */
+    public void and( QueryTerm term )
+    {
+        compoundQueryTerms.add( CompoundQueryTerm.and( new SingleTermQuery( term ) ) );
+    }
 
     /**
-     * Class constructor
+     * Appends an optional term to this query.
+     *
+     * @param term the term to be appended to this query
+     */
+    public void or( QueryTerm term )
+    {
+        compoundQueryTerms.add( CompoundQueryTerm.or( new SingleTermQuery( term ) ) );
+    }
+
+    /**
+     * Appends a prohibited term to this query.
+     *
+     * @param term the term to be appended to this query
      */
-    public CompoundQuery()
+    public void not( QueryTerm term )
     {
-        queries = new ArrayList();
+        compoundQueryTerms.add( CompoundQueryTerm.not( new SingleTermQuery( term ) ) );
     }
 
     /**
-     * Appends a required Query object to this Query object. The Query object will be encapsulated inside an
-     * AndQueryTerm object.
+     * Appends a required subquery to this query.
      *
-     * @param query the Query object to be appended to this Query object
+     * @param query the subquery to be appended to this query
      */
     public void and( Query query )
     {
-        queries.add( new AndQueryTerm( query ) );
+        compoundQueryTerms.add( CompoundQueryTerm.and( query ) );
     }
 
     /**
-     * Appends an optional Query object to this Query object. The Query object will be encapsulated inside an
-     * OrQueryTerm object.
+     * Appends an optional subquery to this query.
      *
-     * @param query the Query object to be appended to this Query object
+     * @param query the subquery to be appended to this query
      */
     public void or( Query query )
     {
-        queries.add( new OrQueryTerm( query ) );
+        compoundQueryTerms.add( CompoundQueryTerm.or( query ) );
     }
 
     /**
-     * Appends a prohibited Query object to this Query object. The Query object will be encapsulated inside an
-     * NotQueryTerm object.
+     * Appends a prohibited subquery to this query.
      *
-     * @param query the Query object to be appended to this Query object
+     * @param query the subquery to be appended to this query
      */
     public void not( Query query )
     {
-        queries.add( new NotQueryTerm( query ) );
+        compoundQueryTerms.add( CompoundQueryTerm.not( query ) );
     }
 
     /**
@@ -80,23 +102,23 @@
      *
      * @return List of all Queries added to this Query
      */
-    public List getQueries()
+    public List getCompoundQueryTerms()
     {
-        return queries;
+        return compoundQueryTerms;
     }
 
+    // TODO! relocate
     public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )
         throws ParseException
     {
         BooleanQuery booleanQuery = new BooleanQuery();
-        List queries = this.queries;
+        List queries = this.compoundQueryTerms;
         for ( Iterator i = queries.iterator(); i.hasNext(); )
         {
-            CompoundQueryTerm subquery = (CompoundQueryTerm) i.next();
-
-            org.apache.lucene.search.Query luceneQuery = subquery.getQuery().createLuceneQuery( index );
+            CompoundQueryTerm queryTerm = (CompoundQueryTerm) i.next();
 
-            booleanQuery.add( luceneQuery, subquery.isRequired(), subquery.isProhibited() );
+            booleanQuery.add( queryTerm.getQuery().createLuceneQuery( index ), queryTerm.isRequired(),
+                              queryTerm.isProhibited() );
         }
         return booleanQuery;
     }

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java?rev=425298&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 Mon Jul 24 23:02:19 2006
@@ -0,0 +1,100 @@
+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:brett@apache.org">Brett Porter</a>
+ */
+class CompoundQueryTerm
+{
+    /**
+     * The query to add to the compound query.
+     */
+    private final Query query;
+
+    /**
+     * Whether the term is required (an AND).
+     */
+    private final boolean required;
+
+    /**
+     * Whether the term is prohibited (a NOT).
+     */
+    private final boolean prohibited;
+
+    /**
+     * Class constructor
+     *
+     * @param query      the subquery to add
+     * @param required   whether the term is required (an AND)
+     * @param prohibited whether the term is prohibited (a NOT)
+     */
+    private CompoundQueryTerm( Query query, boolean required, boolean prohibited )
+    {
+        this.query = query;
+        this.prohibited = prohibited;
+        this.required = required;
+    }
+
+    /**
+     * Method to test if the Query is a search requirement
+     *
+     * @return true if this Query is a search requirement, otherwise returns false
+     */
+    boolean isRequired()
+    {
+        return required;
+    }
+
+    /**
+     * Method to test if the Query is prohibited in the search result
+     *
+     * @return true if this Query is prohibited in the search result
+     */
+    boolean isProhibited()
+    {
+        return prohibited;
+    }
+
+
+    /**
+     * The subquery to execute.
+     *
+     * @return the query
+     */
+    Query getQuery()
+    {
+        return query;
+    }
+
+    static CompoundQueryTerm and( Query query )
+    {
+        return new CompoundQueryTerm( query, true, false );
+    }
+
+    static CompoundQueryTerm or( Query query )
+    {
+        return new CompoundQueryTerm( query, false, false );
+    }
+
+    static CompoundQueryTerm not( Query query )
+    {
+        return new CompoundQueryTerm( query, false, true );
+    }
+}

Copied: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java (from r425040, maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SinglePhraseQuery.java)
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java?p2=maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java&p1=maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SinglePhraseQuery.java&r1=425040&r2=425298&rev=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SinglePhraseQuery.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java Mon Jul 24 23:02:19 2006
@@ -16,19 +16,12 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.TermQuery;
-import org.apache.maven.repository.indexing.RepositoryIndex;
-
 /**
  * Class to hold a single field search condition
  *
  * @author Edwin Punzalan
  */
-public class SinglePhraseQuery
-    implements Query
+public class QueryTerm
 {
     private String field;
 
@@ -40,7 +33,7 @@
      * @param field the index field to search
      * @param value the index value requirement
      */
-    public SinglePhraseQuery( String field, String value )
+    public QueryTerm( String field, String value )
     {
         this.field = field;
         this.value = value;
@@ -64,22 +57,5 @@
     public String getValue()
     {
         return value;
-    }
-
-    public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )
-        throws ParseException
-    {
-        org.apache.lucene.search.Query qry;
-        if ( index.isKeywordField( this.field ) )
-        {
-            Term term = new Term( this.field, this.value );
-            qry = new TermQuery( term );
-        }
-        else
-        {
-            QueryParser parser = new QueryParser( this.field, index.getAnalyzer() );
-            qry = parser.parse( this.value );
-        }
-        return qry;
     }
 }

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

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

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java Mon Jul 24 23:02:19 2006
@@ -19,35 +19,122 @@
 import org.apache.lucene.index.Term;
 import org.apache.maven.repository.indexing.RepositoryIndex;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 /**
- * Query object that handles range queries for dates.
+ * Query object that handles range queries (presently used for dates).
  *
  * @author Maria Odea Ching
+ * @author Brett Porter
  */
 public class RangeQuery
     implements Query
 {
-    private List queries = new ArrayList();
+    /**
+     * Whether values equal to the boundaries are included in the query results.
+     */
+    private final boolean inclusive;
+
+    /**
+     * The lower bound.
+     */
+    private final QueryTerm begin;
+
+    /**
+     * The upper bound.
+     */
+    private final QueryTerm end;
+
+    /**
+     * Constructor.
+     *
+     * @param begin     the lower bound
+     * @param end       the upper bound
+     * @param inclusive whether to include the boundaries in the query
+     */
+    private RangeQuery( QueryTerm begin, QueryTerm end, boolean inclusive )
+    {
+        this.begin = begin;
+        this.end = end;
+        this.inclusive = inclusive;
+    }
+
+    /**
+     * Create an open range, including all results.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createOpenRange()
+    {
+        return new RangeQuery( null, null, false );
+    }
 
-    private boolean inclusive;
+    /**
+     * Create a bounded range, excluding the endpoints.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createExclusiveRange( QueryTerm begin, QueryTerm end )
+    {
+        return new RangeQuery( begin, end, false );
+    }
 
-    public RangeQuery( boolean inclusive )
+    /**
+     * Create a bounded range, including the endpoints.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createInclusiveRange( QueryTerm begin, QueryTerm end )
     {
-        this.inclusive = inclusive;
+        return new RangeQuery( begin, end, true );
+    }
+
+    /**
+     * Create a range that is greater than or equal to a given term.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createGreaterThanOrEqualToRange( QueryTerm begin )
+    {
+        return new RangeQuery( begin, null, true );
+    }
+
+    /**
+     * Create a range that is greater than a given term.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createGreaterThanRange( QueryTerm begin )
+    {
+        return new RangeQuery( begin, null, false );
+    }
+
+    /**
+     * Create a range that is less than or equal to a given term.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createLessThanOrEqualToRange( QueryTerm end )
+    {
+        return new RangeQuery( null, end, true );
+    }
+
+    /**
+     * Create a range that is less than a given term.
+     *
+     * @return the query object
+     */
+    public static RangeQuery createLessThanRange( QueryTerm end )
+    {
+        return new RangeQuery( null, end, false );
     }
 
-    public void addQuery( Query qry )
+    public QueryTerm getBegin()
     {
-        queries.add( qry );
+        return begin;
     }
 
-    public List getQueries()
+    public QueryTerm getEnd()
     {
-        return queries;
+        return end;
     }
 
     public boolean isInclusive()
@@ -55,19 +142,21 @@
         return inclusive;
     }
 
+    /**
+     * @todo! this seems like the wrong place for this (it's back to front - create the query from the index
+     */
     public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )
     {
-        List queries = this.queries;
-        Iterator iter = queries.iterator();
-        Term begin = null;
-        Term end = null;
-        if ( queries.size() == 2 )
+        Term beginTerm = null;
+        if ( begin != null )
+        {
+            beginTerm = new Term( begin.getField(), begin.getValue() );
+        }
+        Term endTerm = null;
+        if ( end != null )
         {
-            SinglePhraseQuery qry = (SinglePhraseQuery) iter.next();
-            begin = new Term( qry.getField(), qry.getValue() );
-            qry = (SinglePhraseQuery) iter.next();
-            end = new Term( qry.getField(), qry.getValue() );
+            endTerm = new Term( end.getField(), end.getValue() );
         }
-        return new org.apache.lucene.search.RangeQuery( begin, end, this.inclusive );
+        return new org.apache.lucene.search.RangeQuery( beginTerm, endTerm, inclusive );
     }
 }

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java?rev=425298&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java Mon Jul 24 23:02:19 2006
@@ -0,0 +1,88 @@
+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.
+ */
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.TermQuery;
+import org.apache.maven.repository.indexing.RepositoryIndex;
+
+/**
+ * Query for a single term.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class SingleTermQuery
+    implements Query
+{
+    /**
+     * The term to query for.
+     */
+    private final QueryTerm term;
+
+    /**
+     * Constructor.
+     *
+     * @param term the term to query
+     */
+    public SingleTermQuery( QueryTerm term )
+    {
+        this.term = term;
+    }
+
+    /**
+     * Shorthand constructor - create a single term query from a field and value
+     *
+     * @param field the field name
+     * @param value the value to check for
+     */
+    public SingleTermQuery( String field, String value )
+    {
+        this.term = new QueryTerm( field, value );
+    }
+
+    /**
+     * @todo! this seems like the wrong place for this (it's back to front - create the query from the index
+     */
+    public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )
+        throws ParseException
+    {
+        org.apache.lucene.search.Query qry;
+        if ( index.isKeywordField( term.getField() ) )
+        {
+            qry = new TermQuery( new Term( term.getField(), term.getValue() ) );
+        }
+        else
+        {
+            // TODO: doesn't seem like the right place for this here!
+            QueryParser parser = new QueryParser( term.getField(), index.getAnalyzer() );
+            qry = parser.parse( term.getValue() );
+        }
+        return qry;
+    }
+
+    public String getField()
+    {
+        return term.getField();
+    }
+
+    public String getValue()
+    {
+        return term.getValue();
+    }
+}

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

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.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/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java?rev=425298&r1=425297&r2=425298&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 Mon Jul 24 23:02:19 2006
@@ -25,8 +25,8 @@
 import org.apache.maven.repository.digest.Digester;
 import org.apache.maven.repository.digest.DigesterException;
 import org.apache.maven.repository.indexing.query.CompoundQuery;
-import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
+import org.apache.maven.repository.indexing.query.QueryTerm;
+import org.apache.maven.repository.indexing.query.SingleTermQuery;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 
@@ -80,8 +80,8 @@
             (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
 
         // search version
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0.15" );
-        List artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_VERSION, "1.0.15" );
+        List artifactList = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifactList.size() );
         for ( Iterator iter = artifactList.iterator(); iter.hasNext(); )
         {
@@ -91,8 +91,8 @@
         }
 
         // search group id
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "test.inherited" );
-        artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_GROUPID, "test.inherited" );
+        artifactList = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifactList.size() );
         Iterator artifacts = artifactList.iterator();
         if ( artifacts.hasNext() )
@@ -219,8 +219,8 @@
         ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
 
         // search version
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
-        List artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_VERSION, "1.0" );
+        List artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 2, artifacts.size() );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -230,8 +230,8 @@
         }
 
         // search group id
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 4, artifacts.size() );
         Iterator iter = artifacts.iterator();
         if ( iter.hasNext() )
@@ -242,8 +242,8 @@
         }
 
         // search artifact id
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 2, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -253,8 +253,8 @@
         }
 
         // search version
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_VERSION, "2" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 4, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -264,8 +264,8 @@
         }
 
         // search classes
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_CLASSES, "App" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_CLASSES, "App" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -275,8 +275,8 @@
         }
 
         // search packages
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGES, "groupId" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_PACKAGES, "groupId" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -286,8 +286,8 @@
         }
 
         // search files
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_FILES, "pom.xml" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_FILES, "pom.xml" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 3, artifacts.size() );
         iter = artifacts.iterator();
         if ( iter.hasNext() )
@@ -298,8 +298,8 @@
         }
 
         // search packaging
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGING, "jar" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_PACKAGING, "jar" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 3, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -309,9 +309,8 @@
         }
 
         //search license url
-        qry =
-            new SinglePhraseQuery( RepositoryIndex.FLD_LICENSE_URLS, "http://www.apache.org/licenses/LICENSE-2.0.txt" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_LICENSE_URLS, "http://www.apache.org/licenses/LICENSE-2.0.txt" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 2, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -325,8 +324,8 @@
         }
 
         //search dependencies
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 2, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -348,9 +347,8 @@
         }
 
         //search build plugin
-        qry =
-            new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_BUILD, "org.codehaus.modello:modello-maven-plugin:2.0" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_PLUGINS_BUILD, "org.codehaus.modello:modello-maven-plugin:2.0" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -372,9 +370,9 @@
         }
 
         //search reporting plugin
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_REPORT,
-                                     "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" );
-        artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm =
+            new QueryTerm( RepositoryIndex.FLD_PLUGINS_REPORT, "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" );
+        artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifacts.size() );
         for ( iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -412,8 +410,8 @@
     {
         String sha1 = digester.createChecksum( artifact.getFile(), algorithm );
 
-        Query qry = new SinglePhraseQuery( field, sha1.trim() );
-        List artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( field, sha1.trim() );
+        List artifacts = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 1, artifacts.size() );
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
         {
@@ -442,8 +440,8 @@
 
         // Criteria 1: required query
         // ex. artifactId=maven-artifact AND groupId=org.apache.maven
-        Query qry1 = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
-        Query qry2 = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
+        QueryTerm qry1 = new QueryTerm( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
+        QueryTerm qry2 = new QueryTerm( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
         CompoundQuery rQry = new CompoundQuery();
         rQry.and( qry1 );
         rQry.and( qry2 );
@@ -460,7 +458,7 @@
         // Criteria 2: nested required query
         // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) OR
         // version=2.0.3
-        Query qry3 = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2.0.3" );
+        QueryTerm qry3 = new QueryTerm( RepositoryIndex.FLD_VERSION, "2.0.3" );
         CompoundQuery oQry = new CompoundQuery();
         oQry.or( rQry );
         oQry.or( qry3 );
@@ -478,14 +476,14 @@
         // ex. (artifactId=maven-artifact AND groupId=org.apache.maven) AND
         // (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( RepositoryIndex.FLD_VERSION, "2.0.1" );
+        QueryTerm qry4 = new QueryTerm( RepositoryIndex.FLD_VERSION, "2.0.1" );
         oQry = new CompoundQuery();
         oQry.or( qry3 );
         oQry.or( qry4 );
 
         CompoundQuery oQry5 = new CompoundQuery();
-        Query qry9 = new SinglePhraseQuery( RepositoryIndex.FLD_NAME, "maven-artifact-2.0.1.jar" );
-        Query qry10 = new SinglePhraseQuery( RepositoryIndex.FLD_NAME, "maven-artifact" );
+        QueryTerm qry9 = new QueryTerm( RepositoryIndex.FLD_NAME, "maven-artifact-2.0.1.jar" );
+        QueryTerm qry10 = new QueryTerm( RepositoryIndex.FLD_NAME, "maven-artifact" );
         oQry5.or( qry9 );
         oQry5.or( qry10 );
 
@@ -505,10 +503,9 @@
         }
 
         CompoundQuery oQry6 = new CompoundQuery();
-        Query qry11 =
-            new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
-        Query qry12 = new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES,
-                                             "org.codehaus.plexus:plexus-container-defualt:1.0-alpha-9" );
+        QueryTerm qry11 = new QueryTerm( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
+        QueryTerm qry12 = new QueryTerm( RepositoryIndex.FLD_DEPENDENCIES,
+                                         "org.codehaus.plexus:plexus-container-defualt:1.0-alpha-9" );
         oQry6.or( qry11 );
         oQry6.or( qry12 );
 
@@ -533,8 +530,8 @@
         // AND (name=maven-artifact-2.0.1.jar OR name=maven-artifact)]
         // OR [(artifactId=sample AND groupId=test)]
         CompoundQuery rQry4 = new CompoundQuery();
-        Query qry5 = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "sample" );
-        Query qry6 = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "test" );
+        QueryTerm qry5 = new QueryTerm( RepositoryIndex.FLD_ARTIFACTID, "sample" );
+        QueryTerm qry6 = new QueryTerm( RepositoryIndex.FLD_GROUPID, "test" );
         rQry4.and( qry5 );
         rQry4.and( qry6 );
         CompoundQuery oQry2 = new CompoundQuery();
@@ -558,8 +555,8 @@
         // [(artifactId=sample AND groupId=test)] OR
         // [(artifactId=sample2 AND groupId=test)]
         CompoundQuery rQry5 = new CompoundQuery();
-        Query qry7 = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "sample2" );
-        Query qry8 = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "test" );
+        QueryTerm qry7 = new QueryTerm( RepositoryIndex.FLD_ARTIFACTID, "sample2" );
+        QueryTerm qry8 = new QueryTerm( RepositoryIndex.FLD_GROUPID, "test" );
         rQry5.and( qry7 );
         rQry5.and( qry8 );
         oQry2.and( rQry5 );
@@ -592,8 +589,8 @@
 
         try
         {
-            Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" );
-            repoSearchLayer.searchAdvanced( qry, indexer );
+            QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_VERSION, "~~~~~" );
+            repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
             fail( "Must throw an exception on unparseable query." );
         }
         catch ( RepositoryIndexSearchException re )
@@ -605,8 +602,8 @@
 
         try
         {
-            Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
-            repoSearchLayer.searchAdvanced( qry, indexer );
+            QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_VERSION, "1.0" );
+            repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
             fail( "Must throw an exception on invalid index location." );
         }
         catch ( RepositoryIndexSearchException re )
@@ -635,23 +632,24 @@
         Artifact pomArtifact =
             createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom" );
 
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + ":" + artifact.getId() );
-        List results = repoSearcher.search( qry, indexer );
+        QueryTerm queryTerm =
+            new QueryTerm( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + ":" + artifact.getId() );
+        List results = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertFalse( results.isEmpty() );
 
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + ":" + pomArtifact.getId() );
-        results = repoSearcher.search( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_ID, RepositoryIndex.POM + ":" + pomArtifact.getId() );
+        results = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertFalse( results.isEmpty() );
 
         indexer.deleteArtifact( artifact );
         indexer.deleteArtifact( pomArtifact );
 
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + ":" + artifact.getId() );
-        results = repoSearcher.search( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + ":" + artifact.getId() );
+        results = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertTrue( results.isEmpty() );
 
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + ":" + pomArtifact.getId() );
-        results = repoSearcher.search( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_ID, RepositoryIndex.POM + ":" + pomArtifact.getId() );
+        results = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertTrue( results.isEmpty() );
     }
 
@@ -673,8 +671,8 @@
         Artifact artifact = createArtifact( "org.apache.maven", "maven-corrupt-jar", "2.0" );
         indexer.indexArtifact( artifact );
 
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
-        List artifacts = repoSearcher.search( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
+        List artifacts = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 0, artifacts.size() );
     }
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/MetadataRepositoryIndexingTest.java Mon Jul 24 23:02:19 2006
@@ -29,9 +29,9 @@
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.Versioning;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.apache.maven.repository.indexing.query.Query;
+import org.apache.maven.repository.indexing.query.QueryTerm;
 import org.apache.maven.repository.indexing.query.RangeQuery;
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
+import org.apache.maven.repository.indexing.query.SingleTermQuery;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
@@ -41,9 +41,9 @@
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.ArrayList;
 
 /**
  * This class tests the MetadataRepositoryIndex.
@@ -141,8 +141,8 @@
         MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
 
         // search last update
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );
-        List metadataList = repoSearchLayer.searchAdvanced( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );
+        List metadataList = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         //assertEquals( 1, metadataList.size() );
         for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
         {
@@ -157,8 +157,8 @@
         }
 
         // search plugin prefix
-        qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" );
-        metadataList = repoSearchLayer.searchAdvanced( qry, indexer );
+        queryTerm = new QueryTerm( RepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" );
+        metadataList = repoSearchLayer.searchAdvanced( new SingleTermQuery( queryTerm ), indexer );
         //assertEquals( 1, metadataList.size() );
         for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
         {
@@ -177,11 +177,9 @@
         }
 
         // search last update using INCLUSIVE Range Query
-        Query qry1 = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212000000" );
-        Query qry2 = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212235959" );
-        RangeQuery rQry = new RangeQuery( true );
-        rQry.addQuery( qry1 );
-        rQry.addQuery( qry2 );
+        QueryTerm qry1 = new QueryTerm( RepositoryIndex.FLD_LASTUPDATE, "20051212000000" );
+        QueryTerm qry2 = new QueryTerm( RepositoryIndex.FLD_LASTUPDATE, "20051212235959" );
+        RangeQuery rQry = RangeQuery.createInclusiveRange( qry1, qry2 );
 
         metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );
         for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
@@ -197,11 +195,10 @@
         }
 
         // search last update using EXCLUSIVE Range Query
-        qry1 = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212000000" );
-        qry2 = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );
-        rQry = new RangeQuery( false );
-        rQry.addQuery( qry1 );
-        rQry.addQuery( qry2 );
+        qry1 = new QueryTerm( RepositoryIndex.FLD_LASTUPDATE, "20051212000000" );
+        qry2 = new QueryTerm( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );
+
+        rQry = RangeQuery.createExclusiveRange( qry1, qry2 );
 
         metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );
         assertEquals( 0, metadataList.size() );
@@ -226,8 +223,8 @@
         repoMetadata.setMetadata( readMetadata( repoMetadata ) );
         indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
 
-        Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
-        List metadataList = repoSearcher.search( qry, indexer );
+        QueryTerm queryTerm = new QueryTerm( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
+        List metadataList = repoSearcher.search( new SingleTermQuery( queryTerm ), indexer );
         assertEquals( 0, metadataList.size() );
     }
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java?rev=425298&r1=425297&r2=425298&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 Mon Jul 24 23:02:19 2006
@@ -18,58 +18,139 @@
 
 import junit.framework.TestCase;
 
+import java.util.Iterator;
+
 /**
- * @author Edwin Punzalan
+ * @author Brett Porter
  */
 public class QueryTest
     extends TestCase
 {
-    public void testSinglePhraseQueryObject()
+    private QueryTerm term1 = new QueryTerm( "field1", "value1" );
+
+    private QueryTerm term2 = new QueryTerm( "field2", "value2" );
+
+    private QueryTerm term3 = new QueryTerm( "field3", "value3" );
+
+    public void testQueryTerm()
     {
-        SinglePhraseQuery query = new SinglePhraseQuery( "Field", "Value" );
-        assertEquals( "Field", query.getField() );
-        assertEquals( "Value", query.getValue() );
-    }
-
-    public void testCompoundQueries()
-    {
-        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() );
+        QueryTerm query = new QueryTerm( "Field", "Value" );
+        assertEquals( "check field setting", "Field", query.getField() );
+        assertEquals( "check value setting", "Value", query.getValue() );
+    }
 
+    public void testSingleTermQuery()
+    {
+        SingleTermQuery query = new SingleTermQuery( "Field", "Value" );
+        assertEquals( "check field setting", "Field", query.getField() );
+        assertEquals( "check value setting", "Value", query.getValue() );
+
+        query = new SingleTermQuery( term1 );
+        assertEquals( "check field setting", "field1", query.getField() );
+        assertEquals( "check value setting", "value1", query.getValue() );
+    }
+
+    public void testRangeQueryOpen()
+    {
+        RangeQuery rangeQuery = RangeQuery.createOpenRange();
+        assertNull( "Check range has no start", rangeQuery.getBegin() );
+        assertNull( "Check range has no end", rangeQuery.getEnd() );
+    }
+
+    public void testRangeQueryExclusive()
+    {
+        RangeQuery rangeQuery = RangeQuery.createExclusiveRange( term1, term2 );
+        assertEquals( "Check range start", term1, rangeQuery.getBegin() );
+        assertEquals( "Check range end", term2, rangeQuery.getEnd() );
+        assertFalse( "Check exclusive", rangeQuery.isInclusive() );
+    }
+
+    public void testRangeQueryInclusive()
+    {
+        RangeQuery rangeQuery = RangeQuery.createInclusiveRange( term1, term2 );
+        assertEquals( "Check range start", term1, rangeQuery.getBegin() );
+        assertEquals( "Check range end", term2, rangeQuery.getEnd() );
+        assertTrue( "Check inclusive", rangeQuery.isInclusive() );
+    }
+
+    public void testRangeQueryOpenEnded()
+    {
+        RangeQuery rangeQuery = RangeQuery.createGreaterThanOrEqualToRange( term1 );
+        assertEquals( "Check range start", term1, rangeQuery.getBegin() );
+        assertNull( "Check range end", rangeQuery.getEnd() );
+        assertTrue( "Check inclusive", rangeQuery.isInclusive() );
+
+        rangeQuery = RangeQuery.createGreaterThanRange( term1 );
+        assertEquals( "Check range start", term1, rangeQuery.getBegin() );
+        assertNull( "Check range end", rangeQuery.getEnd() );
+        assertFalse( "Check exclusive", rangeQuery.isInclusive() );
+
+        rangeQuery = RangeQuery.createLessThanOrEqualToRange( term1 );
+        assertNull( "Check range start", rangeQuery.getBegin() );
+        assertEquals( "Check range end", term1, rangeQuery.getEnd() );
+        assertTrue( "Check inclusive", rangeQuery.isInclusive() );
+
+        rangeQuery = RangeQuery.createLessThanRange( term1 );
+        assertNull( "Check range start", rangeQuery.getBegin() );
+        assertEquals( "Check range end", term1, rangeQuery.getEnd() );
+        assertFalse( "Check exclusive", rangeQuery.isInclusive() );
+    }
+
+    public void testCompundQuery()
+    {
+        CompoundQuery query = new CompoundQuery();
+        assertTrue( "check query is empty", query.getCompoundQueryTerms().isEmpty() );
+
+        query.and( term1 );
+        query.or( term2 );
+        query.not( term3 );
+
+        Iterator i = query.getCompoundQueryTerms().iterator();
+        CompoundQueryTerm term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check first term", "field1", getQuery( term ).getField() );
+        assertEquals( "Check first term", "value1", getQuery( term ).getValue() );
+        assertTrue( "Check first term", term.isRequired() );
+        assertFalse( "Check first term", term.isProhibited() );
+
+        term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check second term", "field2", getQuery( term ).getField() );
+        assertEquals( "Check second term", "value2", getQuery( term ).getValue() );
+        assertFalse( "Check second term", term.isRequired() );
+        assertFalse( "Check second term", term.isProhibited() );
+
+        term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check third term", "field3", getQuery( term ).getField() );
+        assertEquals( "Check third term", "value3", getQuery( term ).getValue() );
+        assertFalse( "Check third term", term.isRequired() );
+        assertTrue( "Check third term", term.isProhibited() );
+
+        CompoundQuery query2 = new CompoundQuery();
+        query2.and( query );
+        query2.or( new SingleTermQuery( term2 ) );
+        query2.not( new SingleTermQuery( term3 ) );
+
+        i = query2.getCompoundQueryTerms().iterator();
+        term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check first term", query, term.getQuery() );
+        assertTrue( "Check first term", term.isRequired() );
+        assertFalse( "Check first term", term.isProhibited() );
+
+        term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check second term", "field2", getQuery( term ).getField() );
+        assertEquals( "Check second term", "value2", getQuery( term ).getValue() );
+        assertFalse( "Check second term", term.isRequired() );
+        assertFalse( "Check second term", term.isProhibited() );
+
+        term = (CompoundQueryTerm) i.next();
+        assertEquals( "Check third term", "field3", getQuery( term ).getField() );
+        assertEquals( "Check third term", "value3", getQuery( term ).getValue() );
+        assertFalse( "Check third term", term.isRequired() );
+        assertTrue( "Check third term", term.isProhibited() );
+    }
+
+    private static SingleTermQuery getQuery( CompoundQueryTerm term )
+    {
+        return (SingleTermQuery) term.getQuery();
     }
 }
 

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java Mon Jul 24 23:02:19 2006
@@ -27,8 +27,7 @@
 import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
 import org.apache.maven.repository.indexing.SearchResult;
-import org.apache.maven.repository.indexing.query.Query;
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
+import org.apache.maven.repository.indexing.query.SingleTermQuery;
 
 import java.io.File;
 import java.util.Iterator;
@@ -92,11 +91,9 @@
                 throw new ReportProcessorException( "Failed to generate checksum", e );
             }
 
-            Query query = new SinglePhraseQuery( algorithm, checksum.trim() );
-
             try
             {
-                List results = searchLayer.searchAdvanced( query, index );
+                List results = searchLayer.searchAdvanced( new SingleTermQuery( algorithm, checksum.trim() ), index );
 
                 if ( results.isEmpty() )
                 {

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java?rev=425298&r1=425297&r2=425298&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java Mon Jul 24 23:02:19 2006
@@ -27,7 +27,7 @@
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
 import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
+import org.apache.maven.repository.indexing.query.SingleTermQuery;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -112,7 +112,7 @@
             return ERROR;
         }
 
-        searchResults = searchLayer.searchAdvanced( new SinglePhraseQuery( "md5", md5 ), index );
+        searchResults = searchLayer.searchAdvanced( new SingleTermQuery( "md5", md5 ), index );
 
         return SUCCESS;
     }



Mime
View raw message