You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/05/25 17:05:54 UTC
svn commit: r541680 [1/2] - in /maven/archiva/trunk:
archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/
archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consum...
Author: joakime
Date: Fri May 25 08:05:51 2007
New Revision: 541680
URL: http://svn.apache.org/viewvc?view=rev&rev=541680
Log:
[MRM-330]: Searching gives an HTTP 500
Next phase of work towards a search/find fix.
Many improvements in indexer / configuration
Added:
maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultLimits.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/AllTests.java (with props)
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/resources/log4j.xml (with props)
maven/archiva/trunk/archiva-base/archiva-model/src/main/java/org/apache/maven/archiva/model/functors/ManagedRepositoryPredicate.java (with props)
Modified:
maven/archiva/trunk/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/ArtifactKeys.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeEntryConverter.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeRecord.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentConverter.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentRecord.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesEntryConverter.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesRecord.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneDocumentMaker.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneQuery.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentRecord.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/CrossRepositorySearch.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AbstractSearchTestCase.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/AllTests.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/bytecode/BytecodeSearchTest.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesIndexTest.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesSearchTest.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/BytecodeIndexPopulator.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/FileContentIndexPopulator.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/HashcodesIndexPopulator.java
maven/archiva/trunk/archiva-base/archiva-indexer/src/test/resources/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.xml
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
Added: maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java Fri May 25 08:05:51 2007
@@ -0,0 +1,53 @@
+package org.apache.maven.archiva.configuration.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Predicate;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+
+/**
+ * Predicate for Repositories with their Indexed setting set to true.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class IndexedRepositoryPredicate
+ implements Predicate
+{
+ private static IndexedRepositoryPredicate INSTANCE = new IndexedRepositoryPredicate();
+
+ public static IndexedRepositoryPredicate getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public boolean evaluate( Object object )
+ {
+ boolean satisfies = false;
+
+ if ( object instanceof RepositoryConfiguration )
+ {
+ RepositoryConfiguration repoconfig = (RepositoryConfiguration) object;
+ return repoconfig.isIndexed();
+ }
+
+ return satisfies;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/IndexedRepositoryPredicate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java Fri May 25 08:05:51 2007
@@ -135,7 +135,7 @@
try
{
File file = new File( repositoryDir, path );
- record.setFile( file );
+ record.setFilename( path );
record.setContents( FileUtils.readFileToString( file, null ) );
index.modifyRecord( record );
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/ArtifactKeys.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/ArtifactKeys.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/ArtifactKeys.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/ArtifactKeys.java Fri May 25 08:05:51 2007
@@ -1,5 +1,30 @@
package org.apache.maven.archiva.indexer;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * ArtifactKeys
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
public class ArtifactKeys
{
public static final String GROUPID = "groupId";
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java Fri May 25 08:05:51 2007
@@ -19,13 +19,15 @@
* under the License.
*/
+import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Searchable;
+import org.apache.maven.archiva.indexer.lucene.LuceneEntryConverter;
import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord;
-import org.apache.maven.archiva.indexer.query.Query;
+import org.apache.maven.archiva.model.ArchivaRepository;
import java.io.File;
import java.util.Collection;
-import java.util.List;
/**
* Common access methods for a Repository Content index.
@@ -62,17 +64,6 @@
throws RepositoryIndexException;
/**
- * Search the index based on the search criteria specified. Returns a list of index records.
- *
- * @param query The query that contains the search criteria
- * @return the index records found
- * @throws RepositoryIndexSearchException if there is a problem searching
- * @todo should it return "SearchResult" instances that contain the index record and other search data (like score?)
- */
- List search( Query query )
- throws RepositoryIndexSearchException;
-
- /**
* Check if the index already exists.
*
* @return true if the index already exists
@@ -91,15 +82,6 @@
throws RepositoryIndexException;
/**
- * Retrieve all records in the index.
- *
- * @return the collection of {@link LuceneRepositoryContentRecord} objects.
- * @throws RepositoryIndexSearchException if there was an error searching the index
- */
- Collection getAllRecords()
- throws RepositoryIndexSearchException;
-
- /**
* Retrieve all primary keys of records in the index.
*
* @return the keys
@@ -128,4 +110,34 @@
* @return the id of index.
*/
String getId();
+
+ /**
+ * Get the repository that this index belongs to.
+ *
+ * @return the repository that this index belongs to.
+ */
+ ArchivaRepository getRepository();
+
+ /**
+ * Get the analyzer in use for this index.
+ *
+ * @return the analyzer in use.
+ */
+ Analyzer getAnalyzer();
+
+ /**
+ * Get the document to record (and back again) converter.
+ *
+ * @return the converter in use.
+ */
+ LuceneEntryConverter getEntryConverter();
+
+ /**
+ * Create a Searchable for this index.
+ *
+ * @return the Searchable.
+ * @throws RepositoryIndexSearchException if there was a problem creating the searchable.
+ */
+ Searchable getSearchable()
+ throws RepositoryIndexSearchException;
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeEntryConverter.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeEntryConverter.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeEntryConverter.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeEntryConverter.java Fri May 25 08:05:51 2007
@@ -76,6 +76,8 @@
{
BytecodeRecord record = new BytecodeRecord();
+ record.setRepositoryId( document.get( LuceneDocumentMaker.REPOSITORY_ID ) );
+
// Artifact Reference
String groupId = document.get( ArtifactKeys.GROUPID );
String artifactId = document.get( ArtifactKeys.ARTIFACTID );
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeRecord.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeRecord.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeRecord.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/bytecode/BytecodeRecord.java Fri May 25 08:05:51 2007
@@ -30,8 +30,11 @@
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public class BytecodeRecord implements LuceneRepositoryContentRecord
+public class BytecodeRecord
+ implements LuceneRepositoryContentRecord
{
+ private String repositoryId;
+
private ArchivaArtifact artifact;
private String filename;
@@ -62,6 +65,11 @@
return methods;
}
+ public String getRepositoryId()
+ {
+ return repositoryId;
+ }
+
public String getPrimaryKey()
{
StringBuffer id = new StringBuffer();
@@ -99,6 +107,11 @@
this.methods = methods;
}
+ public void setRepositoryId( String repositoryId )
+ {
+ this.repositoryId = repositoryId;
+ }
+
public int hashCode()
{
final int PRIME = 31;
@@ -161,4 +174,5 @@
sb.append( "]" );
return sb.toString();
}
+
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentConverter.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentConverter.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentConverter.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentConverter.java Fri May 25 08:05:51 2007
@@ -24,7 +24,6 @@
import org.apache.maven.archiva.indexer.lucene.LuceneEntryConverter;
import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord;
-import java.io.File;
import java.text.ParseException;
/**
@@ -33,7 +32,8 @@
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public class FileContentConverter implements LuceneEntryConverter
+public class FileContentConverter
+ implements LuceneEntryConverter
{
public Document convert( LuceneRepositoryContentRecord record )
@@ -41,24 +41,26 @@
if ( !( record instanceof FileContentRecord ) )
{
throw new ClassCastException( "Unable to convert type " + record.getClass().getName() + " to "
- + FileContentRecord.class.getName() + "." );
+ + FileContentRecord.class.getName() + "." );
}
FileContentRecord filecontent = (FileContentRecord) record;
LuceneDocumentMaker doc = new LuceneDocumentMaker( filecontent );
- doc.addFieldTokenized( FileContentKeys.FILENAME, filecontent.getFile().getAbsolutePath() );
+ doc.addFieldTokenized( FileContentKeys.FILENAME, filecontent.getFilename() );
doc.addFieldTokenized( FileContentKeys.CONTENT, filecontent.getContents() );
return doc.getDocument();
}
- public LuceneRepositoryContentRecord convert( Document document ) throws ParseException
+ public LuceneRepositoryContentRecord convert( Document document )
+ throws ParseException
{
FileContentRecord record = new FileContentRecord();
- record.setFile( new File( document.get( FileContentKeys.FILENAME ) ) );
+ record.setRepositoryId( document.get( LuceneDocumentMaker.REPOSITORY_ID ) );
+ record.setFilename( document.get( FileContentKeys.FILENAME ) );
record.setContents( document.get( FileContentKeys.CONTENT ) );
return record;
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentRecord.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentRecord.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentRecord.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/filecontent/FileContentRecord.java Fri May 25 08:05:51 2007
@@ -29,42 +29,45 @@
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public class FileContentRecord implements LuceneRepositoryContentRecord
+public class FileContentRecord
+ implements LuceneRepositoryContentRecord
{
- private File file;
+ private String repositoryId;
+
+ private String filename;
private String contents;
- public String getContents()
+ public String getRepositoryId()
{
- return contents;
+ return repositoryId;
}
- public void setContents( String contents )
+ public void setRepositoryId( String repositoryId )
{
- this.contents = contents;
+ this.repositoryId = repositoryId;
}
- public File getFile()
+ public String getContents()
{
- return file;
+ return contents;
}
- public void setFile( File file )
+ public void setContents( String contents )
{
- this.file = file;
+ this.contents = contents;
}
public String getPrimaryKey()
{
- return file.getAbsolutePath();
+ return filename;
}
public int hashCode()
{
final int PRIME = 31;
int result = 1;
- result = PRIME * result + ( ( file == null ) ? 0 : file.hashCode() );
+ result = PRIME * result + ( ( filename == null ) ? 0 : filename.hashCode() );
return result;
}
@@ -74,31 +77,40 @@
{
return true;
}
-
+
if ( obj == null )
{
return false;
}
-
+
if ( getClass() != obj.getClass() )
{
return false;
}
-
+
final FileContentRecord other = (FileContentRecord) obj;
-
- if ( file == null )
+
+ if ( filename == null )
{
- if ( other.file != null )
+ if ( other.filename != null )
{
return false;
}
}
- else if ( !file.equals( other.file ) )
+ else if ( !filename.equals( other.filename ) )
{
return false;
}
return true;
}
+ public String getFilename()
+ {
+ return filename;
+ }
+
+ public void setFilename( String filename )
+ {
+ this.filename = filename;
+ }
}
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java Fri May 25 08:05:51 2007
@@ -0,0 +1,51 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Transformer;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.model.ArchivaRepository;
+
+/**
+ * BytecodeIndexTransformer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.commons.collections.Transformer" role-hint="bytecode"
+ */
+public class BytecodeIndexTransformer
+ implements Transformer
+{
+ /**
+ * @plexus.requirement role-hint="lucene"
+ */
+ private RepositoryContentIndexFactory indexFactory;
+
+ public Object transform( Object input )
+ {
+ if ( input instanceof ArchivaRepository )
+ {
+ return indexFactory.createBytecodeIndex( (ArchivaRepository) input );
+ }
+
+ return input;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/BytecodeIndexTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java Fri May 25 08:05:51 2007
@@ -0,0 +1,51 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Transformer;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.model.ArchivaRepository;
+
+/**
+ * FileContentIndexTransformer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.commons.collections.Transformer" role-hint="filecontent"
+ */
+public class FileContentIndexTransformer
+ implements Transformer
+{
+ /**
+ * @plexus.requirement role-hint="lucene"
+ */
+ private RepositoryContentIndexFactory indexFactory;
+
+ public Object transform( Object input )
+ {
+ if ( input instanceof ArchivaRepository )
+ {
+ return indexFactory.createFileContentIndex( (ArchivaRepository) input );
+ }
+
+ return input;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/FileContentIndexTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java Fri May 25 08:05:51 2007
@@ -0,0 +1,51 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Transformer;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.model.ArchivaRepository;
+
+/**
+ * HashcodesIndexTransformer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.commons.collections.Transformer" role-hint="hashcodes"
+ */
+public class HashcodesIndexTransformer
+ implements Transformer
+{
+ /**
+ * @plexus.requirement role-hint="lucene"
+ */
+ private RepositoryContentIndexFactory indexFactory;
+
+ public Object transform( Object input )
+ {
+ if ( input instanceof ArchivaRepository )
+ {
+ return indexFactory.createHashcodeIndex( (ArchivaRepository) input );
+ }
+
+ return input;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/HashcodesIndexTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java Fri May 25 08:05:51 2007
@@ -0,0 +1,63 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Predicate;
+import org.apache.maven.archiva.indexer.RepositoryContentIndex;
+import org.apache.maven.archiva.indexer.RepositoryIndexException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * Test the {@link RepositoryContentIndex} object for the existance of an index.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component
+ * role="org.apache.commons.collections.Predicate"
+ * role-hint="index-exists"
+ */
+public class IndexExistsPredicate
+ extends AbstractLogEnabled
+ implements Predicate
+{
+ public boolean evaluate( Object object )
+ {
+ boolean satisfies = false;
+
+ if ( object instanceof RepositoryContentIndex )
+ {
+ RepositoryContentIndex index = (RepositoryContentIndex) object;
+ try
+ {
+ satisfies = index.exists();
+ }
+ catch ( RepositoryIndexException e )
+ {
+ getLogger().info(
+ "Repository Content Index [" + index.getId() + "] for repository ["
+ + index.getRepository().getId() + "] does not exist yet in ["
+ + index.getIndexDirectory().getAbsolutePath() + "]." );
+ }
+ }
+
+ return satisfies;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/IndexExistsPredicate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java Fri May 25 08:05:51 2007
@@ -0,0 +1,56 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Transformer;
+import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
+import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentIndex;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * SearchableTransformer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.commons.collections.Transformer" role-hint="searchable"
+ */
+public class SearchableTransformer
+ extends AbstractLogEnabled
+ implements Transformer
+{
+ public Object transform( Object input )
+ {
+ if ( input instanceof LuceneRepositoryContentIndex )
+ {
+ try
+ {
+ LuceneRepositoryContentIndex index = (LuceneRepositoryContentIndex) input;
+ return index.getSearchable();
+ }
+ catch ( RepositoryIndexSearchException e )
+ {
+ getLogger().warn("Unable to get searchable for index:" + e.getMessage(), e);
+ }
+ }
+
+ return input;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/SearchableTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java Fri May 25 08:05:51 2007
@@ -0,0 +1,48 @@
+package org.apache.maven.archiva.indexer.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.collections.Predicate;
+import org.apache.maven.archiva.model.ArchivaRepository;
+
+/**
+ * UserAllowedToSearchRepositoryPredicate
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class UserAllowedToSearchRepositoryPredicate
+ implements Predicate
+{
+ public boolean evaluate( Object object )
+ {
+ boolean satisfies = false;
+
+ if ( object instanceof ArchivaRepository )
+ {
+ // TODO: perform check here.
+ satisfies = true; // Everyone is allowed! (for now)
+ }
+
+ System.out.println( "AllowedToSearchRepo: " + satisfies );
+
+ return satisfies;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/functors/UserAllowedToSearchRepositoryPredicate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesEntryConverter.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesEntryConverter.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesEntryConverter.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesEntryConverter.java Fri May 25 08:05:51 2007
@@ -48,7 +48,7 @@
HashcodesRecord hashcodes = (HashcodesRecord) record;
LuceneDocumentMaker doc = new LuceneDocumentMaker( hashcodes );
-
+
// Artifact Reference
doc.addFieldTokenized( ArtifactKeys.GROUPID, hashcodes.getArtifact().getGroupId() );
doc.addFieldExact( ArtifactKeys.GROUPID_EXACT, hashcodes.getArtifact().getGroupId() );
@@ -69,6 +69,8 @@
public LuceneRepositoryContentRecord convert( Document document ) throws ParseException
{
HashcodesRecord record = new HashcodesRecord();
+
+ record.setRepositoryId( document.get( LuceneDocumentMaker.REPOSITORY_ID ) );
// Artifact Reference
String groupId = document.get( ArtifactKeys.GROUPID );
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesRecord.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesRecord.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesRecord.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/hashcodes/HashcodesRecord.java Fri May 25 08:05:51 2007
@@ -28,8 +28,11 @@
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
-public class HashcodesRecord implements LuceneRepositoryContentRecord
+public class HashcodesRecord
+ implements LuceneRepositoryContentRecord
{
+ private String repositoryId;
+
private ArchivaArtifact artifact;
private String filename;
@@ -60,7 +63,7 @@
return id.toString();
}
-
+
public int hashCode()
{
final int PRIME = 31;
@@ -75,19 +78,19 @@
{
return true;
}
-
+
if ( obj == null )
{
return false;
}
-
+
if ( getClass() != obj.getClass() )
{
return false;
}
-
+
final HashcodesRecord other = (HashcodesRecord) obj;
-
+
if ( artifact == null )
{
if ( other.artifact != null )
@@ -103,6 +106,16 @@
return true;
}
+ public String getRepositoryId()
+ {
+ return this.repositoryId;
+ }
+
+ public void setRepositoryId( String repositoryId )
+ {
+ this.repositoryId = repositoryId;
+ }
+
public String getFilename()
{
return filename;
@@ -112,7 +125,7 @@
{
this.filename = filename;
}
-
+
public String toString()
{
StringBuffer sb = new StringBuffer();
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneDocumentMaker.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneDocumentMaker.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneDocumentMaker.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneDocumentMaker.java Fri May 25 08:05:51 2007
@@ -34,6 +34,8 @@
public class LuceneDocumentMaker
{
public static final String PRIMARY_KEY = "pk";
+
+ public static final String REPOSITORY_ID = "repoId";
private Document document;
@@ -52,19 +54,22 @@
String primaryKey = record.getPrimaryKey();
- if ( primaryKey == null )
+ if ( StringUtils.isBlank( primaryKey ) )
{
- throw new IllegalArgumentException( "Not allowed to have a null primary key." );
+ throw new IllegalArgumentException( "Not allowed to have a blank primary key." );
}
- if ( primaryKey.trim().length() <= 0 )
+ String repositoryId = record.getRepositoryId();
+
+ if ( StringUtils.isBlank( repositoryId ) )
{
- throw new IllegalArgumentException( "Not allowed to have an empty primary key." );
+ throw new IllegalArgumentException( "Not allowed to have a blank repository id." );
}
document = new Document();
document.add( new Field( PRIMARY_KEY, primaryKey, Field.Store.NO, Field.Index.UN_TOKENIZED ) );
+ document.add( new Field( REPOSITORY_ID, repositoryId, Field.Store.YES, Field.Index.UN_TOKENIZED ) );
}
public LuceneDocumentMaker addFieldTokenized( String key, String value )
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneQuery.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneQuery.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneQuery.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneQuery.java Fri May 25 08:05:51 2007
@@ -36,7 +36,7 @@
this.query = query;
}
- org.apache.lucene.search.Query getLuceneQuery()
+ public org.apache.lucene.search.Query getLuceneQuery()
{
return query;
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java Fri May 25 08:05:51 2007
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexModifier;
import org.apache.lucene.index.IndexReader;
@@ -26,17 +27,15 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Searchable;
import org.apache.maven.archiva.indexer.RepositoryContentIndex;
import org.apache.maven.archiva.indexer.RepositoryIndexException;
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
-import org.apache.maven.archiva.indexer.query.Query;
+import org.apache.maven.archiva.model.ArchivaRepository;
import java.io.File;
import java.io.IOException;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -64,9 +63,12 @@
* The Lucene Index Handlers
*/
private LuceneIndexHandlers indexHandlers;
+
+ private ArchivaRepository repository;
- public LuceneRepositoryContentIndex( File indexDir, LuceneIndexHandlers handlers )
+ public LuceneRepositoryContentIndex( ArchivaRepository repository, File indexDir, LuceneIndexHandlers handlers )
{
+ this.repository = repository;
this.indexLocation = indexDir;
this.indexHandlers = handlers;
}
@@ -219,12 +221,6 @@
}
}
- public Collection getAllRecords()
- throws RepositoryIndexSearchException
- {
- return search( new LuceneQuery( new MatchAllDocsQuery() ) );
- }
-
public Collection getAllRecordKeys()
throws RepositoryIndexException
{
@@ -267,64 +263,20 @@
}
return keys;
}
-
- // public List getAllGroupIds() throws RepositoryIndexException
- // {
- // return getAllFieldValues( StandardIndexRecordFields.GROUPID_EXACT );
- // }
- //
- // public List getArtifactIds( String groupId ) throws RepositoryIndexSearchException
- // {
- // return searchField( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ),
- // StandardIndexRecordFields.ARTIFACTID );
- // }
- //
- // public List getVersions( String groupId, String artifactId ) throws RepositoryIndexSearchException
- // {
- // BooleanQuery query = new BooleanQuery();
- // query.add( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ),
- // BooleanClause.Occur.MUST );
- // query.add( new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, artifactId ) ),
- // BooleanClause.Occur.MUST );
- //
- // return searchField( query, StandardIndexRecordFields.VERSION );
- // }
-
- // private List searchField( org.apache.lucene.search.Query luceneQuery, String fieldName )
- // throws RepositoryIndexSearchException
- // {
- // Set results = new LinkedHashSet();
- //
- // IndexSearcher searcher;
- // try
- // {
- // searcher = new IndexSearcher( indexLocation.getAbsolutePath() );
- // }
- // catch ( IOException e )
- // {
- // throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
- // }
- //
- // try
- // {
- // Hits hits = searcher.search( luceneQuery );
- // for ( int i = 0; i < hits.length(); i++ )
- // {
- // Document doc = hits.doc( i );
- //
- // results.add( doc.get( fieldName ) );
- // }
- // }
- // catch ( IOException e )
- // {
- // throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
- // }
- // finally
- // {
- // closeQuietly( searcher );
- // }
- // return new ArrayList( results );
- // }
+
+ public Searchable getSearchable()
+ throws RepositoryIndexSearchException
+ {
+ try
+ {
+ IndexSearcher searcher = new IndexSearcher( indexLocation.getAbsolutePath() );
+ return searcher;
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
+ }
+ }
public boolean exists()
throws RepositoryIndexException
@@ -354,70 +306,26 @@
}
}
- public List search( Query query )
- throws RepositoryIndexSearchException
- {
- LuceneQuery lQuery = (LuceneQuery) query;
-
- org.apache.lucene.search.Query luceneQuery = lQuery.getLuceneQuery();
-
- IndexSearcher searcher;
- try
- {
- searcher = new IndexSearcher( indexLocation.getAbsolutePath() );
- }
- catch ( IOException e )
- {
- throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
- }
-
- List records = new ArrayList();
- try
- {
- Hits hits = searcher.search( luceneQuery );
- for ( int i = 0; i < hits.length(); i++ )
- {
- Document doc = hits.doc( i );
-
- records.add( indexHandlers.getConverter().convert( doc ) );
- }
- }
- catch ( IOException e )
- {
- throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
- }
- catch ( ParseException e )
- {
- throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
- }
- finally
- {
- closeQuietly( searcher );
- }
-
- return records;
- }
-
public QueryParser getQueryParser()
{
return this.indexHandlers.getQueryParser();
}
- private static void closeQuietly( IndexSearcher searcher )
+ public static void closeSearchable( Searchable searchable )
{
- try
+ if( searchable != null )
{
- if ( searcher != null )
+ try
{
- searcher.close();
+ searchable.close();
+ }
+ catch ( IOException e )
+ {
+ // Ignore
}
- }
- catch ( IOException e )
- {
- // ignore
}
}
-
+
private static void closeQuietly( TermEnum terms )
throws RepositoryIndexException
{
@@ -489,5 +397,20 @@
public String getId()
{
return this.indexHandlers.getId();
+ }
+
+ public ArchivaRepository getRepository()
+ {
+ return repository;
+ }
+
+ public Analyzer getAnalyzer()
+ {
+ return this.indexHandlers.getAnalyzer();
+ }
+
+ public LuceneEntryConverter getEntryConverter()
+ {
+ return this.indexHandlers.getConverter();
}
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndexFactory.java Fri May 25 08:05:51 2007
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
import org.apache.maven.archiva.indexer.RepositoryContentIndex;
@@ -38,7 +39,8 @@
*
* @plexus.component role="org.apache.maven.archiva.indexer.RepositoryContentIndexFactory" role-hint="lucene"
*/
-public class LuceneRepositoryContentIndexFactory implements RepositoryContentIndexFactory
+public class LuceneRepositoryContentIndexFactory
+ implements RepositoryContentIndexFactory
{
/**
* @plexus.requirement
@@ -48,19 +50,19 @@
public RepositoryContentIndex createBytecodeIndex( ArchivaRepository repository )
{
File indexDir = toIndexDir( repository, "bytecode" );
- return new LuceneRepositoryContentIndex( indexDir, new BytecodeHandlers() );
+ return new LuceneRepositoryContentIndex( repository, indexDir, new BytecodeHandlers() );
}
public RepositoryContentIndex createFileContentIndex( ArchivaRepository repository )
{
File indexDir = toIndexDir( repository, "filecontent" );
- return new LuceneRepositoryContentIndex( indexDir, new FileContentHandlers() );
+ return new LuceneRepositoryContentIndex( repository, indexDir, new FileContentHandlers() );
}
public RepositoryContentIndex createHashcodeIndex( ArchivaRepository repository )
{
File indexDir = toIndexDir( repository, "hashcodes" );
- return new LuceneRepositoryContentIndex( indexDir, new HashcodesHandlers() );
+ return new LuceneRepositoryContentIndex( repository, indexDir, new HashcodesHandlers() );
}
/**
@@ -91,6 +93,15 @@
{
// Use configured index dir.
String repoPath = repoConfig.getIndexDir();
+ if ( StringUtils.isBlank( repoPath ) )
+ {
+ repoPath = repository.getUrl().getPath();
+ if ( !repoPath.endsWith( "/" ) )
+ {
+ repoPath += "/";
+ }
+ repoPath += ".index";
+ }
indexDir = new File( repoPath, "/" + indexId + "/" );
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentRecord.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentRecord.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentRecord.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentRecord.java Fri May 25 08:05:51 2007
@@ -32,4 +32,11 @@
* @return the primary key
*/
public String getPrimaryKey();
+
+ /**
+ * Get the repository that this record belongs to.
+ *
+ * @return the repository id for this record.
+ */
+ public String getRepositoryId();
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/CrossRepositorySearch.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/CrossRepositorySearch.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/CrossRepositorySearch.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/CrossRepositorySearch.java Fri May 25 08:05:51 2007
@@ -1,7 +1,26 @@
package org.apache.maven.archiva.indexer.search;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
/**
- * Search across repositories for specified term.
+ * Search across repositories in lucene indexes.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
@@ -13,15 +32,26 @@
* Search for the specific term across all repositories.
*
* @param term the term to search for.
+ * @param limits the limits to apply to the search results.
+ * @return the results.
+ */
+ public SearchResults searchForTerm( String term, SearchResultLimits limits );
+
+ /**
+ * Search for the specific bytecode across all repositories.
+ *
+ * @param term the term to search for.
+ * @param limits the limits to apply to the search results.
* @return the results.
*/
- public SearchResults searchForTerm( String term );
+ public SearchResults searchForBytecode( String term, SearchResultLimits limits );
/**
- * Search for the specific MD5 string across all repositories.
+ * Search for the specific checksum string across all repositories.
*
- * @param md5 the md5 string to search for.
+ * @param checksum the checksum string to search for.
+ * @param limits the limits to apply to the search results.
* @return the results.
*/
- public SearchResults searchForMd5( String md5 );
+ public SearchResults searchForChecksum( String checksum, SearchResultLimits limits );
}
Modified: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java?view=diff&rev=541680&r1=541679&r2=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java Fri May 25 08:05:51 2007
@@ -19,19 +19,31 @@
* under the License.
*/
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.functors.AndPredicate;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.MultiSearcher;
+import org.apache.lucene.search.Searchable;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.configuration.functors.IndexedRepositoryPredicate;
+import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate;
import org.apache.maven.archiva.indexer.RepositoryContentIndex;
-import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
-import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
-import org.apache.maven.archiva.indexer.bytecode.BytecodeKeys;
-import org.apache.maven.archiva.indexer.filecontent.FileContentKeys;
+import org.apache.maven.archiva.indexer.bytecode.BytecodeHandlers;
+import org.apache.maven.archiva.indexer.filecontent.FileContentHandlers;
+import org.apache.maven.archiva.indexer.functors.UserAllowedToSearchRepositoryPredicate;
+import org.apache.maven.archiva.indexer.hashcodes.HashcodesHandlers;
import org.apache.maven.archiva.indexer.hashcodes.HashcodesKeys;
+import org.apache.maven.archiva.indexer.lucene.LuceneEntryConverter;
import org.apache.maven.archiva.indexer.lucene.LuceneQuery;
-import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord;
import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -39,12 +51,10 @@
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
+import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
/**
* DefaultCrossRepositorySearch
@@ -57,184 +67,237 @@
extends AbstractLogEnabled
implements CrossRepositorySearch, RegistryListener, Initializable
{
+ /**
+ * @plexus.requirement role-hint="bytecode"
+ */
+ private Transformer bytecodeIndexTransformer;
- private static final int UNKNOWN = 0;
-
- private static final int FILE_CONTENT = 1;
+ /**
+ * @plexus.requirement role-hint="filecontent"
+ */
+ private Transformer filecontentIndexTransformer;
- private static final int BYTECODE = 2;
+ /**
+ * @plexus.requirement role-hint="hashcodes"
+ */
+ private Transformer hashcodesIndexTransformer;
- private static final int HASHCODE = 3;
+ /**
+ * @plexus.requirement role-hint="searchable"
+ */
+ private Transformer searchableTransformer;
/**
- * @plexus.requirement role-hint="lucene"
+ * @plexus.requirement role-hint="index-exists"
*/
- private RepositoryContentIndexFactory indexFactory;
+ private Predicate indexExistsPredicate;
/**
* @plexus.requirement
*/
private ArchivaConfiguration configuration;
- private Map repositoryMap = new HashMap();
+ private List localIndexedRepositories = new ArrayList();
- public SearchResults searchForMd5( String md5 )
+ public SearchResults searchForChecksum( String checksum, SearchResultLimits limits )
{
- // TODO Auto-generated method stub
- return null;
- }
+ List indexes = getHashcodeIndexes();
- public SearchResults searchForTerm( String term )
- {
- List indexes = new ArrayList();
+ try
+ {
+ QueryParser parser = new MultiFieldQueryParser( new String[] { HashcodesKeys.MD5, HashcodesKeys.SHA1 },
+ new HashcodesHandlers().getAnalyzer() );
+ LuceneQuery query = new LuceneQuery( parser.parse( checksum ) );
+ SearchResults results = searchAll( query, limits, indexes );
+ results.getRepositories().addAll( this.localIndexedRepositories );
- indexes.addAll( getBytecodeIndexes() );
- indexes.addAll( getFileContentIndexes() );
- indexes.addAll( getHashcodeIndexes() );
+ return results;
+ }
+ catch ( ParseException e )
+ {
+ getLogger().warn( "Unable to parse query [" + checksum + "]: " + e.getMessage(), e );
+ }
- SearchResults results = new SearchResults();
+ // empty results.
+ return new SearchResults();
+ }
- results.getRepositories().addAll( this.repositoryMap.values() );
+ public SearchResults searchForBytecode( String term, SearchResultLimits limits )
+ {
+ List indexes = getHashcodeIndexes();
- Iterator it = indexes.iterator();
- while ( it.hasNext() )
+ try
{
- RepositoryContentIndex index = (RepositoryContentIndex) it.next();
+ QueryParser parser = new BytecodeHandlers().getQueryParser();
+ LuceneQuery query = new LuceneQuery( parser.parse( term ) );
+ SearchResults results = searchAll( query, limits, indexes );
+ results.getRepositories().addAll( this.localIndexedRepositories );
- try
- {
- QueryParser parser = index.getQueryParser();
- LuceneQuery query = new LuceneQuery( parser.parse( term ) );
- List hits = index.search( query );
-
- switch ( getIndexId( index ) )
- {
- case BYTECODE:
- results.getBytecodeHits().addAll( hits );
- break;
- case FILE_CONTENT:
- results.getContentHits().addAll( hits );
- break;
- case HASHCODE:
- results.getHashcodeHits().addAll( hits );
- break;
- }
- }
- catch ( ParseException e )
- {
- getLogger().warn( "Unable to parse query [" + term + "]: " + e.getMessage(), e );
- }
- catch ( RepositoryIndexSearchException e )
- {
- getLogger().warn( "Unable to search index [" + index + "] for term [" + term + "]: " + e.getMessage(),
- e );
- }
+ return results;
+ }
+ catch ( ParseException e )
+ {
+ getLogger().warn( "Unable to parse query [" + term + "]: " + e.getMessage(), e );
}
- return results;
+ // empty results.
+ return new SearchResults();
}
- private int getIndexId( RepositoryContentIndex index )
+ public SearchResults searchForTerm( String term, SearchResultLimits limits )
{
- if ( FileContentKeys.ID.equals( index.getId() ) )
- {
- return FILE_CONTENT;
- }
+ List indexes = getFileContentIndexes();
- if ( BytecodeKeys.ID.equals( index.getId() ) )
+ try
{
- return BYTECODE;
- }
+ QueryParser parser = new FileContentHandlers().getQueryParser();
+ LuceneQuery query = new LuceneQuery( parser.parse( term ) );
+ SearchResults results = searchAll( query, limits, indexes );
+ results.getRepositories().addAll( this.localIndexedRepositories );
- if ( HashcodesKeys.ID.equals( index.getId() ) )
+ return results;
+ }
+ catch ( ParseException e )
{
- return HASHCODE;
+ getLogger().warn( "Unable to parse query [" + term + "]: " + e.getMessage(), e );
}
- return UNKNOWN;
+ // empty results.
+ return new SearchResults();
}
- public List getBytecodeIndexes()
+ private SearchResults searchAll( LuceneQuery luceneQuery, SearchResultLimits limits, List indexes )
{
- List ret = new ArrayList();
+ org.apache.lucene.search.Query specificQuery = luceneQuery.getLuceneQuery();
+
+ SearchResults results = new SearchResults();
+
+ if ( indexes.isEmpty() )
+ {
+ // No point going any further.
+ return results;
+ }
+
+ // Setup the converter
+ LuceneEntryConverter converter = null;
+ RepositoryContentIndex index = (RepositoryContentIndex) indexes.get( 0 );
+ converter = index.getEntryConverter();
+
+ // Process indexes into an array of Searchables.
+ List searchableList = new ArrayList( indexes );
+ CollectionUtils.transform( searchableList, searchableTransformer );
+
+ Searchable searchables[] = new Searchable[searchableList.size()];
+ searchableList.toArray( searchables );
- synchronized ( this.repositoryMap )
+ try
{
- Iterator it = this.repositoryMap.values().iterator();
- while ( it.hasNext() )
+ // Create a multi-searcher for looking up the information.
+ MultiSearcher searcher = new MultiSearcher( searchables );
+
+ // Perform the search.
+ Hits hits = searcher.search( specificQuery );
+
+ int hitCount = hits.length();
+
+ // Now process the limits.
+ results.setLimits( limits );
+ results.setTotalHits( hitCount );
+
+ int fetchCount = limits.getPageSize();
+ int offset = ( limits.getSelectedPage() * limits.getPageSize() );
+
+ if ( limits.getSelectedPage() == SearchResultLimits.ALL_PAGES )
{
- ArchivaRepository repo = (ArchivaRepository) it.next();
+ fetchCount = hitCount;
+ offset = 0;
+ }
- if ( !isSearchAllowed( repo ) )
+ // Goto offset.
+ if ( offset < hitCount )
+ {
+ // only process if the offset is within the hit count.
+ for ( int i = 0; i <= fetchCount; i++ )
{
- continue;
- }
+ // Stop fetching if we are past the total # of available hits.
+ if ( offset + i >= hitCount )
+ {
+ break;
+ }
- ret.add( indexFactory.createBytecodeIndex( repo ) );
+ try
+ {
+ Document doc = hits.doc( offset + i );
+ LuceneRepositoryContentRecord record = converter.convert( doc );
+ results.addHit( record );
+ }
+ catch ( java.text.ParseException e )
+ {
+ getLogger().warn( "Unable to parse document into record: " + e.getMessage(), e );
+ }
+ }
}
}
+ catch ( IOException e )
+ {
+ getLogger().error( "Unable to setup multi-search: " + e.getMessage(), e );
+ }
- return ret;
+ return results;
}
- public List getFileContentIndexes()
+ private Predicate getAllowedToSearchReposPredicate()
+ {
+ return new UserAllowedToSearchRepositoryPredicate();
+ }
+
+ public List getBytecodeIndexes()
{
List ret = new ArrayList();
- synchronized ( this.repositoryMap )
+ synchronized ( this.localIndexedRepositories )
{
- Iterator it = this.repositoryMap.values().iterator();
- while ( it.hasNext() )
- {
- ArchivaRepository repo = (ArchivaRepository) it.next();
-
- if ( !isSearchAllowed( repo ) )
- {
- continue;
- }
-
- ret.add( indexFactory.createFileContentIndex( repo ) );
- }
+ ret.addAll( CollectionUtils.select( this.localIndexedRepositories, getAllowedToSearchReposPredicate() ) );
+ CollectionUtils.transform( ret, bytecodeIndexTransformer );
+ CollectionUtils.filter( ret, indexExistsPredicate );
}
return ret;
}
- public List getHashcodeIndexes()
+ public List getFileContentIndexes()
{
List ret = new ArrayList();
- synchronized ( this.repositoryMap )
+ synchronized ( this.localIndexedRepositories )
{
- Iterator it = this.repositoryMap.values().iterator();
- while ( it.hasNext() )
- {
- ArchivaRepository repo = (ArchivaRepository) it.next();
-
- if ( !isSearchAllowed( repo ) )
- {
- continue;
- }
-
- ret.add( indexFactory.createHashcodeIndex( repo ) );
- }
+ ret.addAll( CollectionUtils.select( this.localIndexedRepositories, getAllowedToSearchReposPredicate() ) );
+ CollectionUtils.transform( ret, filecontentIndexTransformer );
+ CollectionUtils.filter( ret, indexExistsPredicate );
}
return ret;
}
- public boolean isSearchAllowed( ArchivaRepository repo )
+ public List getHashcodeIndexes()
{
- // TODO: test if user has permissions to search in this repo.
+ List ret = new ArrayList();
- return true;
+ synchronized ( this.localIndexedRepositories )
+ {
+ ret.addAll( CollectionUtils.select( this.localIndexedRepositories, getAllowedToSearchReposPredicate() ) );
+ CollectionUtils.transform( ret, hashcodesIndexTransformer );
+ CollectionUtils.filter( ret, indexExistsPredicate );
+ }
+
+ return ret;
}
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
if ( ConfigurationNames.isRepositories( propertyName ) )
{
- initRepositoryMap();
+ initRepositories();
}
}
@@ -243,28 +306,41 @@
/* Nothing to do here */
}
- private void initRepositoryMap()
+ private void initRepositories()
{
- synchronized ( this.repositoryMap )
+ synchronized ( this.localIndexedRepositories )
{
- this.repositoryMap.clear();
+ this.localIndexedRepositories.clear();
+
+ Predicate localIndexedRepos = AndPredicate.getInstance( LocalRepositoryPredicate.getInstance(),
+ IndexedRepositoryPredicate.getInstance() );
- Iterator it = configuration.getConfiguration().createRepositoryMap().entrySet().iterator();
- while ( it.hasNext() )
+ Collection repos = CollectionUtils.select( configuration.getConfiguration().getRepositories(),
+ localIndexedRepos );
+
+ Transformer toArchivaRepository = new Transformer()
{
- Map.Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
- RepositoryConfiguration repoConfig = (RepositoryConfiguration) entry.getValue();
- ArchivaRepository repository = ArchivaConfigurationAdaptor.toArchivaRepository( repoConfig );
- this.repositoryMap.put( key, repository );
- }
+
+ public Object transform( Object input )
+ {
+ if ( input instanceof RepositoryConfiguration )
+ {
+ return ArchivaConfigurationAdaptor.toArchivaRepository( (RepositoryConfiguration) input );
+ }
+ return input;
+ }
+ };
+
+ CollectionUtils.transform( repos, toArchivaRepository );
+
+ this.localIndexedRepositories.addAll( repos );
}
}
public void initialize()
throws InitializationException
{
- initRepositoryMap();
+ initRepositories();
configuration.addChangeListener( this );
}
}
Added: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java?view=auto&rev=541680
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java Fri May 25 08:05:51 2007
@@ -0,0 +1,115 @@
+package org.apache.maven.archiva.indexer.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.commons.lang.StringUtils;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SearchResultHit
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class SearchResultHit
+{
+ // The (optional) context for this result.
+ private String context;
+
+ // Basic hit, direct to non-artifact resource.
+ private String url;
+
+ // Advanced hit, reference to groupId.
+ private String groupId;
+
+ // Advanced hit, reference to artifactId.
+ private String artifactId;
+
+ // Advanced hit, if artifact, all versions of artifact
+ private List artifacts = new ArrayList();
+
+ public String getContext()
+ {
+ return context;
+ }
+
+ public void setContext( String context )
+ {
+ this.context = context;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+
+ public void setUrl( String url )
+ {
+ this.url = url;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void addArtifact( ArchivaArtifact artifact )
+ {
+ this.artifacts.add( artifact );
+
+ if ( StringUtils.isBlank( this.groupId ) )
+ {
+ this.groupId = artifact.getGroupId();
+ }
+
+ if ( StringUtils.isBlank( this.artifactId ) )
+ {
+ this.artifactId = artifact.getArtifactId();
+ }
+ }
+
+ public List getArtifacts()
+ {
+ return artifacts;
+ }
+
+ public void setArtifacts( List artifacts )
+ {
+ this.artifacts = artifacts;
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+}
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/archiva/trunk/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResultHit.java
------------------------------------------------------------------------------
svn:mime-type = text/plain