1 package org.apache.maven.index;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import junit.framework.Assert;
25
26 import org.apache.lucene.search.BooleanClause.Occur;
27 import org.apache.lucene.search.BooleanQuery;
28 import org.apache.lucene.search.Query;
29
30 public class Nexus3881NexusIndexerTest
31 extends AbstractNexusIndexerTest
32 {
33 protected File repo = new File( getBasedir(), "src/test/nexus-3881" );
34
35 @Override
36 protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
37 throws Exception
38 {
39 context =
40 nexusIndexer.addIndexingContext( "nexus-3881", "nexus-3881", repo, indexDir, null, null, DEFAULT_CREATORS );
41 nexusIndexer.scan( context );
42 }
43
44 public void testRelevances()
45 throws Exception
46 {
47 Query q1 = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "solution", SearchType.SCORED );
48 Query q2 = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "solution", SearchType.SCORED );
49
50 BooleanQuery bq = new BooleanQuery();
51 bq.add( q1, Occur.SHOULD );
52 bq.add( q2, Occur.SHOULD );
53
54 IteratorSearchRequest request = new IteratorSearchRequest( bq );
55 request.setLuceneExplain( true );
56
57 IteratorSearchResponse response = nexusIndexer.searchIterator( request );
58
59 Assert.assertEquals( "All artifacts has 'solution' in their GA!", 4, response.getTotalHits() );
60
61
62
63
64
65
66
67
68 float firstRel = response.getResults().next().getLuceneScore();
69
70 float lastRel = 0;
71 for ( ArtifactInfo ai : response )
72 {
73 lastRel = ai.getLuceneScore();
74 }
75
76 Assert.assertTrue(
77 String.format( "The relevance span should be small! (%s)",
78 new Object[] { Float.valueOf( firstRel - lastRel ) } ), firstRel - lastRel < 0.35 );
79 }
80 }