*/\r
\r
import org.apache.lucene.document.Document;\r
-import org.apache.lucene.index.Term;\r
import org.apache.lucene.queryParser.ParseException;\r
-import org.apache.lucene.queryParser.QueryParser;\r
-import org.apache.lucene.search.BooleanQuery;\r
import org.apache.lucene.search.Hits;\r
import org.apache.lucene.search.IndexSearcher;\r
-import org.apache.lucene.search.TermQuery;\r
import org.apache.maven.artifact.Artifact;\r
import org.apache.maven.artifact.factory.ArtifactFactory;\r
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;\r
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;\r
-import org.apache.maven.repository.indexing.query.CompoundQuery;\r
-import org.apache.maven.repository.indexing.query.CompoundQueryTerm;\r
import org.apache.maven.repository.indexing.query.Query;\r
-import org.apache.maven.repository.indexing.query.RangeQuery;\r
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;\r
import org.codehaus.plexus.logging.AbstractLogEnabled;\r
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;\r
\r
return docs;\r
}\r
\r
- /**\r
- * Method to create a lucene Query object from a single query phrase\r
- *\r
- * @param field the index field name to search into\r
- * @param value the index field value to match the field with\r
- * @return a lucene Query object representing the query phrase field = value\r
- * @throws ParseException\r
- */\r
- private org.apache.lucene.search.Query createLuceneQuery( String field, String value )\r
- throws ParseException\r
- {\r
- org.apache.lucene.search.Query qry;\r
- if ( index.isKeywordField( field ) )\r
- {\r
- Term term = new Term( field, value );\r
- qry = new TermQuery( term );\r
- }\r
- else\r
- {\r
- QueryParser parser = new QueryParser( field, index.getAnalyzer() );\r
- qry = parser.parse( value );\r
- }\r
- return qry;\r
- }\r
-\r
/**\r
* Method to create a lucene Query object by converting a prepared Query object\r
*\r
private org.apache.lucene.search.Query createLuceneQuery( Query query )\r
throws ParseException\r
{\r
- org.apache.lucene.search.Query retVal;\r
-\r
- if ( query instanceof CompoundQuery )\r
- {\r
- BooleanQuery booleanQuery = new BooleanQuery();\r
- CompoundQuery compoundQuery = (CompoundQuery) query;\r
- List queries = compoundQuery.getQueries();\r
- for ( Iterator i = queries.iterator(); i.hasNext(); )\r
- {\r
- CompoundQueryTerm subquery = (CompoundQueryTerm) i.next();\r
-\r
- org.apache.lucene.search.Query luceneQuery = createLuceneQuery( subquery.getQuery() );\r
-\r
- booleanQuery.add( luceneQuery, subquery.isRequired(), subquery.isProhibited() );\r
- }\r
- retVal = booleanQuery;\r
- }\r
- else if ( query instanceof RangeQuery )\r
- {\r
- RangeQuery rq = (RangeQuery) query;\r
- List queries = rq.getQueries();\r
- Iterator iter = queries.iterator();\r
- Term begin = null, end = null;\r
- if ( queries.size() == 2 )\r
- {\r
- SinglePhraseQuery qry = (SinglePhraseQuery) iter.next();\r
- begin = new Term( qry.getField(), qry.getValue() );\r
- qry = (SinglePhraseQuery) iter.next();\r
- end = new Term( qry.getField(), qry.getValue() );\r
- }\r
- retVal = new org.apache.lucene.search.RangeQuery( begin, end, rq.isInclusive() );\r
- }\r
- else\r
- {\r
- SinglePhraseQuery singlePhraseQuery = (SinglePhraseQuery) query;\r
- retVal = createLuceneQuery( singlePhraseQuery.getField(), singlePhraseQuery.getValue() );\r
- }\r
- return retVal;\r
+ return query.createLuceneQuery( index );\r
}\r
\r
/**\r
* limitations under the License.
*/
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.maven.repository.indexing.RepositoryIndex;
+
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
{
return queries;
}
+
+ public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )
+ throws ParseException
+ {
+ BooleanQuery booleanQuery = new BooleanQuery();
+ List queries = this.queries;
+ for ( Iterator i = queries.iterator(); i.hasNext(); )
+ {
+ CompoundQueryTerm subquery = (CompoundQueryTerm) i.next();
+
+ org.apache.lucene.search.Query luceneQuery = subquery.getQuery().createLuceneQuery( index );
+
+ booleanQuery.add( luceneQuery, subquery.isRequired(), subquery.isProhibited() );
+ }
+ return booleanQuery;
+ }
}
* limitations under the License.\r
*/\r
\r
+import org.apache.lucene.index.Term;\r
+import org.apache.maven.repository.indexing.RepositoryIndex;\r
+\r
import java.util.ArrayList;\r
+import java.util.Iterator;\r
import java.util.List;\r
\r
/**\r
public class RangeQuery\r
implements Query\r
{\r
- List queries = new ArrayList();\r
+ private List queries = new ArrayList();\r
\r
private boolean inclusive;\r
\r
{\r
return inclusive;\r
}\r
+\r
+ public org.apache.lucene.search.Query createLuceneQuery( RepositoryIndex index )\r
+ {\r
+ List queries = this.queries;\r
+ Iterator iter = queries.iterator();\r
+ Term begin = null;\r
+ Term end = null;\r
+ if ( queries.size() == 2 )\r
+ {\r
+ SinglePhraseQuery qry = (SinglePhraseQuery) iter.next();\r
+ begin = new Term( qry.getField(), qry.getValue() );\r
+ qry = (SinglePhraseQuery) iter.next();\r
+ end = new Term( qry.getField(), qry.getValue() );\r
+ }\r
+ return new org.apache.lucene.search.RangeQuery( begin, end, this.inclusive );\r
+ }\r
}\r
package org.apache.maven.repository.indexing.query;
+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;
+
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
{
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;
+ }
}