提交 658fd226 编写于 作者: K Kohsuke Kawaguchi

allowed plugins to implement subtypes of the Search class to provide different...

allowed plugins to implement subtypes of the Search class to provide different search implementations
上级 e334748c
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package hudson.model; package hudson.model;
import hudson.search.SearchFactory;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.Stapler;
...@@ -99,6 +100,11 @@ public abstract class AbstractModelObject implements SearchableModelObject { ...@@ -99,6 +100,11 @@ public abstract class AbstractModelObject implements SearchableModelObject {
} }
public Search getSearch() { public Search getSearch() {
for (SearchFactory sf : SearchFactory.all()) {
Search s = sf.createFor(this);
if (s!=null)
return s;
}
return new Search(); return new Search();
} }
......
package hudson.search;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import jenkins.model.Jenkins;
/**
* Creates a {@link Search} instance for a {@link SearchableModelObject}.
*
* <p>
* This allows you to plug in different backends to the search, such as full-text search,
* or more intelligent user-sensitive search, etc. Puts @{@link Extension} annotation
* on your implementation to have it registered.
*
* <p>
* Right now, there's no user control over which {@link SearchFactory} takes priority,
* but we may do so later.
*
* @author Kohsuke Kawaguchi
* @since 1.469
*/
public abstract class SearchFactory implements ExtensionPoint {
/**
* Creates a {@link Search} object.
*
* This method needs to execute quickly (without actually executing any search),
* since it is created per incoming HTTP response.
*
* @param owner
* The {@link SearchableModelObject} object for which we are creating the search.
* The returned object will provide the search for this object.
* @return
* null if your factory isn't interested in creating a {@link Search} object.
* The next factory will get a chance to act on it.
*/
public abstract Search createFor(SearchableModelObject owner);
/**
* Returns all the registered {@link SearchFactory} instances.
*/
public static ExtensionList<SearchFactory> all() {
return Jenkins.getInstance().getExtensionList(SearchFactory.class);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册