mirror of https://github.com/apache/archiva.git
[MRM-127] start refactoring by clarifying terminology (this is more inline with what Lucene has). Take some additional notes.
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b344120221
commit
725cc4350e
|
@ -24,7 +24,8 @@ import org.apache.maven.model.Model;
|
|||
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 @@ public class DefaultRepositoryIndexSearchLayer
|
|||
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 @@ public class DefaultRepositoryIndexSearchLayer
|
|||
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 );
|
||||
}
|
||||
|
|
|
@ -118,15 +118,8 @@ public class DefaultRepositoryIndexSearcher
|
|||
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 @@ public class DefaultRepositoryIndexSearcher
|
|||
|
||||
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 @@ public class DefaultRepositoryIndexSearcher
|
|||
{
|
||||
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 @@ public class DefaultRepositoryIndexSearcher
|
|||
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 @@ public class DefaultRepositoryIndexSearcher
|
|||
return searchHit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create RepositoryMetadata object.
|
||||
*
|
||||
* @return RepositoryMetadata
|
||||
*/
|
||||
private Metadata readMetadata( RepositoryMetadata repoMetadata, ArtifactRepository repository )
|
||||
throws RepositoryIndexSearchException
|
||||
{
|
||||
|
@ -237,11 +228,6 @@ public class DefaultRepositoryIndexSearcher
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create RepositoryMetadata object.
|
||||
*
|
||||
* @return RepositoryMetadata
|
||||
*/
|
||||
private Model readPom( Artifact pomArtifact, ArtifactRepository repository )
|
||||
throws RepositoryIndexSearchException
|
||||
{
|
||||
|
|
|
@ -87,6 +87,8 @@ public interface RepositoryIndex
|
|||
|
||||
/**
|
||||
* Method to encapsulate the optimize() method for lucene
|
||||
*
|
||||
* @throws RepositoryIndexException if there is a problem optimizing the index.
|
||||
*/
|
||||
void optimize()
|
||||
throws RepositoryIndexException;
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
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>
|
||||
*/
|
||||
public abstract class AbstractCompoundQueryTerm
|
||||
implements CompoundQueryTerm
|
||||
{
|
||||
/**
|
||||
* The query being added.
|
||||
*/
|
||||
private Query query;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param query the query represented by this object
|
||||
*/
|
||||
protected AbstractCompoundQueryTerm( Query query )
|
||||
{
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CompoundQueryTerm#isRequired()
|
||||
*/
|
||||
public boolean isRequired()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CompoundQueryTerm#isProhibited()
|
||||
*/
|
||||
public boolean isProhibited()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CompoundQueryTerm#getQuery()
|
||||
*/
|
||||
public Query getQuery()
|
||||
{
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
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:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public class AndQueryTerm
|
||||
extends AbstractCompoundQueryTerm
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param query the Query object represented by this object
|
||||
*/
|
||||
public AndQueryTerm( Query query )
|
||||
{
|
||||
super( query );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractCompoundQueryTerm#isRequired()
|
||||
*/
|
||||
public boolean isRequired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -32,47 +32,69 @@ import java.util.List;
|
|||
public class CompoundQuery
|
||||
implements Query
|
||||
{
|
||||
protected List queries;
|
||||
/**
|
||||
* The query terms.
|
||||
*/
|
||||
private final List compoundQueryTerms = new ArrayList();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* Appends a required term to this query.
|
||||
*
|
||||
* @param term the term to be appended to this query
|
||||
*/
|
||||
public CompoundQuery()
|
||||
public void and( QueryTerm term )
|
||||
{
|
||||
queries = new ArrayList();
|
||||
compoundQueryTerms.add( CompoundQueryTerm.and( new SingleTermQuery( term ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a required Query object to this Query object. The Query object will be encapsulated inside an
|
||||
* AndQueryTerm object.
|
||||
* Appends an optional term to this query.
|
||||
*
|
||||
* @param query the Query object to be appended to this Query object
|
||||
* @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 void not( QueryTerm term )
|
||||
{
|
||||
compoundQueryTerms.add( CompoundQueryTerm.not( new SingleTermQuery( term ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a required subquery to this query.
|
||||
*
|
||||
* @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 @@ public class CompoundQuery
|
|||
*
|
||||
* @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();
|
||||
CompoundQueryTerm queryTerm = (CompoundQueryTerm) i.next();
|
||||
|
||||
org.apache.lucene.search.Query luceneQuery = subquery.getQuery().createLuceneQuery( index );
|
||||
|
||||
booleanQuery.add( luceneQuery, subquery.isRequired(), subquery.isProhibited() );
|
||||
booleanQuery.add( queryTerm.getQuery().createLuceneQuery( index ), queryTerm.isRequired(),
|
||||
queryTerm.isProhibited() );
|
||||
}
|
||||
return booleanQuery;
|
||||
}
|
||||
|
|
|
@ -17,30 +17,84 @@ package org.apache.maven.repository.indexing.query;
|
|||
*/
|
||||
|
||||
/**
|
||||
* Term in a compound query.
|
||||
* Base of all query terms.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public interface CompoundQueryTerm
|
||||
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();
|
||||
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();
|
||||
boolean isProhibited()
|
||||
{
|
||||
return prohibited;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to get the Query object represented by this object
|
||||
* The subquery to execute.
|
||||
*
|
||||
* @return the Query object represented by this object
|
||||
* @return the query
|
||||
*/
|
||||
Query getQuery();
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
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:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public class NotQueryTerm
|
||||
extends AbstractCompoundQueryTerm
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param query the Query object represented by this Query object
|
||||
*/
|
||||
public NotQueryTerm( Query query )
|
||||
{
|
||||
super( query );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CompoundQueryTerm#isProhibited()
|
||||
*/
|
||||
public boolean isProhibited()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
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:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
public class OrQueryTerm
|
||||
extends AbstractCompoundQueryTerm
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param query the Query object represented by this Query object
|
||||
*/
|
||||
public OrQueryTerm( Query query )
|
||||
{
|
||||
super( query );
|
||||
}
|
||||
}
|
|
@ -16,19 +16,12 @@ package org.apache.maven.repository.indexing.query;
|
|||
* 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 @@ public class SinglePhraseQuery
|
|||
* @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;
|
||||
|
@ -65,21 +58,4 @@ public class SinglePhraseQuery
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -19,35 +19,122 @@ package org.apache.maven.repository.indexing.query;
|
|||
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;
|
||||
|
||||
private boolean inclusive;
|
||||
/**
|
||||
* The lower bound.
|
||||
*/
|
||||
private final QueryTerm begin;
|
||||
|
||||
public RangeQuery( boolean inclusive )
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public void addQuery( Query qry )
|
||||
/**
|
||||
* Create an open range, including all results.
|
||||
*
|
||||
* @return the query object
|
||||
*/
|
||||
public static RangeQuery createOpenRange()
|
||||
{
|
||||
queries.add( qry );
|
||||
return new RangeQuery( null, null, false );
|
||||
}
|
||||
|
||||
public List getQueries()
|
||||
/**
|
||||
* Create a bounded range, excluding the endpoints.
|
||||
*
|
||||
* @return the query object
|
||||
*/
|
||||
public static RangeQuery createExclusiveRange( QueryTerm begin, QueryTerm end )
|
||||
{
|
||||
return queries;
|
||||
return new RangeQuery( begin, end, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a bounded range, including the endpoints.
|
||||
*
|
||||
* @return the query object
|
||||
*/
|
||||
public static RangeQuery createInclusiveRange( QueryTerm begin, QueryTerm end )
|
||||
{
|
||||
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 QueryTerm getBegin()
|
||||
{
|
||||
return begin;
|
||||
}
|
||||
|
||||
public QueryTerm getEnd()
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
public boolean isInclusive()
|
||||
|
@ -55,19 +142,21 @@ public class RangeQuery
|
|||
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 )
|
||||
{
|
||||
SinglePhraseQuery qry = (SinglePhraseQuery) iter.next();
|
||||
begin = new Term( qry.getField(), qry.getValue() );
|
||||
qry = (SinglePhraseQuery) iter.next();
|
||||
end = new Term( qry.getField(), qry.getValue() );
|
||||
beginTerm = new Term( begin.getField(), begin.getValue() );
|
||||
}
|
||||
return new org.apache.lucene.search.RangeQuery( begin, end, this.inclusive );
|
||||
Term endTerm = null;
|
||||
if ( end != null )
|
||||
{
|
||||
endTerm = new Term( end.getField(), end.getValue() );
|
||||
}
|
||||
return new org.apache.lucene.search.RangeQuery( beginTerm, endTerm, inclusive );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ import org.apache.maven.repository.digest.DefaultDigester;
|
|||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
(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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
//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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
//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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
//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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
//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 @@ public class ArtifactRepositoryIndexingTest
|
|||
{
|
||||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
|
||||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
}
|
||||
|
||||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
// 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 @@ public class ArtifactRepositoryIndexingTest
|
|||
// [(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 @@ public class ArtifactRepositoryIndexingTest
|
|||
|
||||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
|
||||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
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 @@ public class ArtifactRepositoryIndexingTest
|
|||
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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
|||
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.File;
|
|||
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 @@ public class MetadataRepositoryIndexingTest
|
|||
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 @@ public class MetadataRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class MetadataRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class MetadataRepositoryIndexingTest
|
|||
}
|
||||
|
||||
// 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 @@ public class MetadataRepositoryIndexingTest
|
|||
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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -18,58 +18,139 @@ package org.apache.maven.repository.indexing.query;
|
|||
|
||||
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() );
|
||||
QueryTerm query = new QueryTerm( "Field", "Value" );
|
||||
assertEquals( "check field setting", "Field", query.getField() );
|
||||
assertEquals( "check value setting", "Value", query.getValue() );
|
||||
}
|
||||
|
||||
public void testCompoundQueries()
|
||||
public void testSingleTermQuery()
|
||||
{
|
||||
CompoundQuery rQuery = new CompoundQuery();
|
||||
rQuery.and( new SinglePhraseQuery( "r1Field", "r1Value" ) );
|
||||
rQuery.and( new SinglePhraseQuery( "r2Field", "r2Value" ) );
|
||||
SingleTermQuery query = new SingleTermQuery( "Field", "Value" );
|
||||
assertEquals( "check field setting", "Field", query.getField() );
|
||||
assertEquals( "check value setting", "Value", query.getValue() );
|
||||
|
||||
CompoundQuery oQuery = new CompoundQuery();
|
||||
oQuery.or( new SinglePhraseQuery( "oField", "oValue" ) );
|
||||
query = new SingleTermQuery( term1 );
|
||||
assertEquals( "check field setting", "field1", query.getField() );
|
||||
assertEquals( "check value setting", "value1", query.getValue() );
|
||||
}
|
||||
|
||||
CompoundQuery all = new CompoundQuery();
|
||||
all.and( rQuery );
|
||||
all.or( oQuery );
|
||||
assertEquals( 2, all.getQueries().size() );
|
||||
public void testRangeQueryOpen()
|
||||
{
|
||||
RangeQuery rangeQuery = RangeQuery.createOpenRange();
|
||||
assertNull( "Check range has no start", rangeQuery.getBegin() );
|
||||
assertNull( "Check range has no end", rangeQuery.getEnd() );
|
||||
}
|
||||
|
||||
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() );
|
||||
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() );
|
||||
}
|
||||
|
||||
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() );
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +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.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 @@ public class DuplicateArtifactFileReportProcessor
|
|||
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() )
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.maven.repository.indexing.RepositoryIndexException;
|
|||
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 @@ public class SearchAction
|
|||
return ERROR;
|
||||
}
|
||||
|
||||
searchResults = searchLayer.searchAdvanced( new SinglePhraseQuery( "md5", md5 ), index );
|
||||
searchResults = searchLayer.searchAdvanced( new SingleTermQuery( "md5", md5 ), index );
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue