diff --git a/core/src/main/java/hudson/model/AbstractModelObject.java b/core/src/main/java/hudson/model/AbstractModelObject.java index 6214af95d16d6989df8158ff5e456838ea6a19e2..c104a3179c1ac7e087d75a240e888c1802d1947a 100644 --- a/core/src/main/java/hudson/model/AbstractModelObject.java +++ b/core/src/main/java/hudson/model/AbstractModelObject.java @@ -23,6 +23,7 @@ */ package hudson.model; +import hudson.search.SearchFactory; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.Stapler; @@ -99,6 +100,11 @@ public abstract class AbstractModelObject implements SearchableModelObject { } public Search getSearch() { + for (SearchFactory sf : SearchFactory.all()) { + Search s = sf.createFor(this); + if (s!=null) + return s; + } return new Search(); } diff --git a/core/src/main/java/hudson/search/SearchFactory.java b/core/src/main/java/hudson/search/SearchFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..5f01917dba77a0b7cd2c034071b826fe8aa05d94 --- /dev/null +++ b/core/src/main/java/hudson/search/SearchFactory.java @@ -0,0 +1,45 @@ +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}. + * + *
+ * 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. + * + *
+ * 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