mirror of https://github.com/apache/archiva.git
[MRM-151] test dependency index, fix tokenization
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437192 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8c3eb496f9
commit
4abbe9f5ca
|
@ -17,6 +17,8 @@ package org.apache.maven.archiva.indexer.lucene;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.CharTokenizer;
|
||||||
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
|
@ -30,9 +32,11 @@ import org.apache.maven.archiva.indexer.RepositoryIndexException;
|
||||||
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
|
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
|
||||||
import org.apache.maven.archiva.indexer.query.Query;
|
import org.apache.maven.archiva.indexer.query.Query;
|
||||||
import org.apache.maven.archiva.indexer.record.RepositoryIndexRecord;
|
import org.apache.maven.archiva.indexer.record.RepositoryIndexRecord;
|
||||||
|
import org.apache.maven.archiva.indexer.record.StandardIndexRecordFields;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -130,10 +134,35 @@ public class LuceneRepositoryArtifactIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Analyzer getAnalyzer()
|
public Analyzer getAnalyzer()
|
||||||
{
|
{
|
||||||
// TODO: investigate why changed in original! Probably for MD5 and number querying.
|
return new MyAnalyzer();
|
||||||
return new StandardAnalyzer();
|
}
|
||||||
|
|
||||||
|
private static class MyAnalyzer
|
||||||
|
extends Analyzer
|
||||||
|
{
|
||||||
|
private static final Analyzer STANDARD = new StandardAnalyzer();
|
||||||
|
|
||||||
|
public TokenStream tokenStream( String field, final Reader reader )
|
||||||
|
{
|
||||||
|
// do not tokenize field called 'element'
|
||||||
|
if ( StandardIndexRecordFields.DEPENDENCIES.equals( field ) )
|
||||||
|
{
|
||||||
|
return new CharTokenizer( reader )
|
||||||
|
{
|
||||||
|
protected boolean isTokenChar( char c )
|
||||||
|
{
|
||||||
|
return c != '\n';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// use standard analyzer
|
||||||
|
return STANDARD.tokenStream( field, reader );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteRecords( Collection records )
|
public void deleteRecords( Collection records )
|
||||||
|
|
|
@ -635,6 +635,23 @@ public class LuceneStandardArtifactIndexSearchTest
|
||||||
assertTrue( "Check results size", results.isEmpty() );
|
assertTrue( "Check results size", results.isEmpty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExactMatchDependency()
|
||||||
|
throws RepositoryIndexSearchException
|
||||||
|
{
|
||||||
|
Query query = new TermQuery(
|
||||||
|
new Term( StandardIndexRecordFields.DEPENDENCIES, "org.apache.maven:maven-plugin-api:2.0" ) );
|
||||||
|
List results = index.search( new LuceneQuery( query ) );
|
||||||
|
|
||||||
|
assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
|
||||||
|
assertEquals( "Check results size", 1, results.size() );
|
||||||
|
|
||||||
|
// test non-match fails
|
||||||
|
query = new TermQuery( new Term( StandardIndexRecordFields.DEPENDENCIES, "foo" ) );
|
||||||
|
results = index.search( new LuceneQuery( query ) );
|
||||||
|
|
||||||
|
assertTrue( "Check results size", results.isEmpty() );
|
||||||
|
}
|
||||||
|
|
||||||
public void testMatchProjectName()
|
public void testMatchProjectName()
|
||||||
throws RepositoryIndexSearchException
|
throws RepositoryIndexSearchException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue