-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSearch.java
More file actions
96 lines (84 loc) · 3.72 KB
/
Search.java
File metadata and controls
96 lines (84 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.codejive.jpm.search;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.eclipse.aether.artifact.Artifact;
public interface Search {
/**
* Find artifacts matching the given pattern. This will return the first page of results. If the
* pattern to search for is a simple name (there are no colons in the string), the search will
* match any part of an artifact's group or name. If there's a single colon, the search will
* match any part of the group id and artifact id separately. If there are two colons, the
* search will match the group id and artifact id exactly, and will return the artifact's
* versions.
*
* @param artifactPattern The pattern to search for.
* @param count The maximum number of results to return.
* @return The search result as an instance of {@link SearchResult}.
* @throws IOException If an error occurred during the search.
*/
SearchResult findArtifacts(String artifactPattern, int count) throws IOException;
/**
* Find the next page of artifacts. This takes a {@link SearchResult} returned by a previous
* call to {@link #findArtifacts(String, int)} and returns the next page of results.
*
* @param prevResult The previous search result.
* @return The next search result as an instance of {@link SearchResult}.
* @throws IOException If an error occurred during the search.
*/
SearchResult findNextArtifacts(SearchResult prevResult) throws IOException;
enum Backends {
rest_smo,
rest_csc;
// smo_smo,
// smo_csc;
}
static Search getBackend(Backends backend) {
if (backend != null) {
switch (backend) {
case rest_smo:
return SearchSolrRestImpl.createSmo();
case rest_csc:
return SearchSolrRestImpl.createCsc();
// case smo_smo:
// return SearchSmoApiImpl.createSmo();
// case smo_csc:
// return SearchSmoApiImpl.createCsc();
}
}
return SearchSolrRestImpl.createSmo();
}
/**
* Hold the result of a search while also functioning as a kind of bookmark for paging purposes.
*/
class SearchResult {
/** The artifacts that matched the search query. */
public final List<? extends Artifact> artifacts;
/** The search query that produced this result. */
public final String query;
/** The index of the first artifact in this result relative to the total result set. */
public final int start;
/** The maximum number of results to return */
public final int count;
/** The total number of artifacts that matched the search query. */
public final int total;
/**
* Create a new search result.
*
* @param artifacts The artifacts that matched the search query.
* @param query The search query that produced this result.
* @param start The index of the first artifact in this result relative to the total result
* set.
* @param count The maximum number of results to return.
* @param total The total number of artifacts that matched the search query.
*/
public SearchResult(
List<? extends Artifact> artifacts, String query, int start, int count, int total) {
this.artifacts = Collections.unmodifiableList(artifacts);
this.query = query;
this.start = start;
this.count = count;
this.total = total;
}
}
}