Skip to content

Commit

Permalink
Final touches before SearchEngine removal.
Browse files Browse the repository at this point in the history
Api changes needed to express various search cases, but not yet done. Known to fail:
org.eclipse.m2e.tests.internal.index.NexusIndexManagerSearchTest.testPluginSearch()
org.eclipse.m2e.tests.internal.index.NexusIndexManagerTest.testWorkspaceIndex()
org.eclipse.m2e.tests.internal.index.NexusIndexManagerTest.testIndexedPublicArtifactGroups()
org.eclipse.m2e.tests.internal.index.NexusIndexManagerTest.testPublicMirror()
  • Loading branch information
cstamas authored and Pascal Rapicault committed Dec 3, 2010
1 parent 61abf54 commit 3fffb0c
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 177 deletions.
Expand Up @@ -95,14 +95,14 @@ public interface IIndex {
* @return
* @throws CoreException
*/
public Collection<IndexedArtifact> find(String groupId, String artifactId, String version, String packaging)
public Collection<IndexedArtifact> find(SearchExpression groupId, SearchExpression artifactId, SearchExpression version, SearchExpression packaging)
throws CoreException;

/**
* Convenience method to search in all indexes enabled for repositories defined in settings.xml. This method always
* performs "scored" search.
*/
public Map<String, IndexedArtifact> search(String term, String searchType) throws CoreException;
public Map<String, IndexedArtifact> search(SearchExpression expression, String searchType) throws CoreException;

/**
* Convenience method to search in all indexes enabled for repositories defined in settings.xml. This method always
Expand All @@ -113,5 +113,5 @@ public Collection<IndexedArtifact> find(String groupId, String artifactId, Strin
* @param classifier - the type of classifiers to search for, SEARCH_ALL, SEARCH_JAVADOCS, SEARCH_SOURCES,
* SEARCH_TESTS
*/
public Map<String, IndexedArtifact> search(String term, String searchType, int classifier) throws CoreException;
public Map<String, IndexedArtifact> search(SearchExpression expression, String searchType, int classifier) throws CoreException;
}
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* MatchTyped is a interface that describes the wanted match type to be used.
*
* @author cstamas
*/
public interface MatchTyped {

public enum MatchType {
/** Exact match wanted */
EXACT,
/** Partial match wanted, like prefix, contains, etc. */
PARTIAL;
};

MatchType getMatchType();

}
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* MatchTypedStringSearchExpression
*
* @author cstamas
*/
public class MatchTypedStringSearchExpression extends StringSearchExpression implements MatchTyped {

private final MatchType matchType;

public MatchTypedStringSearchExpression(final String expression, final MatchType matchType) {
super(expression);
this.matchType = matchType;
}

public MatchType getMatchType() {
return matchType;
}

}
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* SearchExpression is a wrapper interface for expressions representable as plain strings to be used within searches.
*
* @author cstamas
*/
public interface SearchExpression {

/**
* Returns the expression value as plain java String.
*
* @return
*/
String getStringValue();

}
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* SourcedSearchExpression is a search expression usually "sourced" from some programmatic source, and we already know
* it is complete, exact value that we want to search for. Indexer will try to match exactly the provided string value,
* no more no less.
*
* @author cstamas
*/
public class SourcedSearchExpression extends MatchTypedStringSearchExpression {

public SourcedSearchExpression(String expression) {
super(expression, MatchType.EXACT);
}
}
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* StringSearchExpression is a SearchExpression that has String value.
*
* @author cstamas
*/
public class StringSearchExpression implements SearchExpression {

private final String expression;

public StringSearchExpression(String expression) {
assert expression != null && expression.trim().length() > 0 : "The expression cannot be empty!";
this.expression = expression;
}

public String getStringValue() {
return expression;
}

}
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.eclipse.m2e.core.index;

/**
* UserInputSearchExpression is a search expression usually coming from user input (like some UI dialogue, element or
* CLI). It will be normalized and tokenized and then a search will happen against it. Search expressions of this type
* will always provide "broader" results, since it defaults to prefix searches.
*
* @author cstamas
*/
public class UserInputSearchExpression extends MatchTypedStringSearchExpression {

public UserInputSearchExpression(String expression) {
super(expression, MatchType.PARTIAL);
}
}
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.m2e.core.index.IIndex;
import org.eclipse.m2e.core.index.IndexedArtifact;
import org.eclipse.m2e.core.index.IndexedArtifactFile;
import org.eclipse.m2e.core.index.SearchExpression;


/**
Expand Down Expand Up @@ -66,7 +67,7 @@ public IndexedArtifactFile identify(File file) throws CoreException {
return null;
}

public Collection<IndexedArtifact> find(String groupId, String artifactId, String version, String packaging)
public Collection<IndexedArtifact> find(SearchExpression groupId, SearchExpression artifactId, SearchExpression version, SearchExpression packaging)
throws CoreException {
Set<IndexedArtifact> result = new LinkedHashSet<IndexedArtifact>();
for(IIndex index : indexes) {
Expand All @@ -78,7 +79,7 @@ public Collection<IndexedArtifact> find(String groupId, String artifactId, Strin
return result;
}

public Map<String, IndexedArtifact> search(String term, String searchType) throws CoreException {
public Map<String, IndexedArtifact> search(SearchExpression term, String searchType) throws CoreException {
Map<String, IndexedArtifact> result = new HashMap<String, IndexedArtifact>();
for(IIndex index : indexes) {
Map<String, IndexedArtifact> iresult = index.search(term, searchType);
Expand All @@ -89,7 +90,7 @@ public Map<String, IndexedArtifact> search(String term, String searchType) throw
return result;
}

public Map<String, IndexedArtifact> search(String term, String searchType, int classifier) throws CoreException {
public Map<String, IndexedArtifact> search(SearchExpression term, String searchType, int classifier) throws CoreException {
Map<String, IndexedArtifact> result = new HashMap<String, IndexedArtifact>();
for(IIndex index : indexes) {
Map<String, IndexedArtifact> iresult = index.search(term, searchType, classifier);
Expand Down
Expand Up @@ -22,13 +22,13 @@
import org.apache.lucene.search.BooleanQuery;

import org.apache.maven.index.MAVEN;
import org.apache.maven.index.SearchType;

import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.index.IIndex;
import org.eclipse.m2e.core.index.IMutableIndex;
import org.eclipse.m2e.core.index.IndexedArtifact;
import org.eclipse.m2e.core.index.IndexedArtifactFile;
import org.eclipse.m2e.core.index.SearchExpression;
import org.eclipse.m2e.core.repository.IRepository;


Expand Down Expand Up @@ -82,24 +82,24 @@ public void removeArtifact(File pomFile, ArtifactKey artifactKey) {
indexManager.removeDocument(repository, pomFile, artifactKey);
}

public Collection<IndexedArtifact> find(String groupId, String artifactId, String version, String packaging)
throws CoreException {
public Collection<IndexedArtifact> find(SearchExpression groupId, SearchExpression artifactId,
SearchExpression version, SearchExpression packaging) throws CoreException {
BooleanQuery query = new BooleanQuery();

if(!isBlank(packaging)) {
query.add(indexManager.constructQuery(MAVEN.PACKAGING, packaging, SearchType.EXACT), Occur.MUST);
if(packaging != null) {
query.add(indexManager.constructQuery(MAVEN.PACKAGING, packaging), Occur.MUST);
}

if(!isBlank(groupId)) {
query.add(indexManager.constructQuery(MAVEN.GROUP_ID, groupId, SearchType.SCORED), Occur.MUST);
if(groupId != null) {
query.add(indexManager.constructQuery(MAVEN.GROUP_ID, groupId), Occur.MUST);
}

if(!isBlank(artifactId)) {
query.add(indexManager.constructQuery(MAVEN.ARTIFACT_ID, artifactId, SearchType.SCORED), Occur.MUST);
if(artifactId != null) {
query.add(indexManager.constructQuery(MAVEN.ARTIFACT_ID, artifactId), Occur.MUST);
}

if(!isBlank(version)) {
query.add(indexManager.constructQuery(MAVEN.VERSION, version, SearchType.SCORED), Occur.MUST);
if(version != null) {
query.add(indexManager.constructQuery(MAVEN.VERSION, version), Occur.MUST);
}

return indexManager.search(repository, query).values();
Expand Down Expand Up @@ -145,11 +145,12 @@ public void setIndexDetails(String details) throws CoreException {
indexManager.setIndexDetails(repository, details, null/*async*/);
}

public Map<String, IndexedArtifact> search(String term, String searchType) throws CoreException {
public Map<String, IndexedArtifact> search(SearchExpression term, String searchType) throws CoreException {
return indexManager.search(getRepository(), term, searchType);
}

public Map<String, IndexedArtifact> search(String term, String searchType, int classifier) throws CoreException {
public Map<String, IndexedArtifact> search(SearchExpression term, String searchType, int classifier)
throws CoreException {
return indexManager.search(getRepository(), term, searchType, classifier);
}
}

0 comments on commit 3fffb0c

Please sign in to comment.