MINDEXER-108: lift the prefix restriction
Historically Lucene needed this, but latest versions
can cope with it. This is still OOM prone, so use with care,
but the possibility is here.
diff --git a/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java b/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java
index f47bead..4900bac 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/DefaultQueryCreator.java
@@ -200,11 +200,6 @@
return null;
}
- if ( query.startsWith( "*" ) || query.startsWith( "?" ) )
- {
- throw new ParseException( "Query cannot start with '*' or '?'!" );
- }
-
if ( Field.NOT_PRESENT.equals( query ) )
{
return new WildcardQuery( new Term( indexerField.getKey(), "*" ) );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
index 1af94e4..5b34d49 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
@@ -213,19 +213,10 @@
// "-" in the name
// New in 4.0! constructquery do throw error on wrong input! I left in old call and checking it fails,
// and then added "new" call with proper query syntax!
- Query q;
- try
- {
- q = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "*-logging", SearchType.SCORED );
- fail( "Input is invalid, query cannot start with *!" );
- }
- catch ( IllegalArgumentException e )
- {
- // good, now let's do it again with good input:
- // Note: since queries are really parsed now, the leading "-" is wrong too
- q = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "logging", SearchType.SCORED );
- }
+ // Since Lucene 5.x can cope with wildcard prefixes, this case is not valid anymore
+ // see https://issues.apache.org/jira/browse/MINDEXER-108
+ Query q = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "*-logging", SearchType.SCORED );
GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
@@ -565,4 +556,32 @@
}
}
+ public void testPrefixWildcard()
+ throws Exception
+ {
+ // see https://issues.apache.org/jira/browse/MINDEXER-108
+ IteratorSearchRequest request =
+ new IteratorSearchRequest( nexusIndexer.constructQuery( MAVEN.GROUP_ID, "*.forge", SearchType.EXACT ) );
+
+ // two candidates (see src/test/repo):
+ // org.terracotta.forge:forge-parent:1.0.5
+ // org.terracotta.forge:archetype-parent:1.0.1
+
+ IteratorSearchResponse response = nexusIndexer.searchIterator( request );
+
+ try
+ {
+ assertEquals( response.getResults().toString(), 2, response.getTotalHitsCount() );
+
+ for ( ArtifactInfo ai : response )
+ {
+ assertEquals( ai.getGroupId(), "org.terracotta.forge" );
+ }
+ }
+ finally
+ {
+ response.close();
+ }
+ }
+
}
diff --git a/pom.xml b/pom.xml
index 1ee9394..e2eff45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,7 +88,7 @@
<failsafe.redirectTestOutputToFile>true</failsafe.redirectTestOutputToFile>
<eclipse-sisu.version>0.3.3</eclipse-sisu.version>
- <lucene.version>5.5.4</lucene.version>
+ <lucene.version>5.5.5</lucene.version>
<maven.version>3.5.2</maven.version>
<resolver.version>1.1.0</resolver.version>
<truezip.version>7.7.10</truezip.version>