zen-cms/Zen-Core — Issue #35: Unified Search API
Author: YorickPeterse
Created: 2011-10-15 22:00:41+00:00
State: open

Users need to be able to search content easily regardless of how dynamic it is.
For this a unified search API has to be put in place that would make it easy for
packages to register a model that would perform the actual search action. This
model should have a ``.search()`` method which would return a collection of
objects of which each object would be a single row.

Searching would be done by going to ``/search?package=X`` where X would be the
name of the package to search for. For example,
``/search?package=section_entries`` would search for a set of section entries.
The actual query would be stored in the ``query`` query string so the resulting
URL would be ``/search?package=section_entries&query=Hello%20World``.

Registering a model would be done along the lines of the following code:

Zen::Package.add do |package|
package.search_model = 'Sections::Model::SectionEntry'
end

class Sections::Model::SectionEntry
def self.search(query = nil)
# ....
end
end

The return value would have to be an array containing a set of objects. Each
object would require a title field, a body field, a URL and optionally some meta
data (such as a date). I'm not sure if these objects should be instances of
``Hash`` or a custom object, the latter doesn't seem to offer many benefits but
may make it easier to extend the functionality in the future.

The last problem would be the search box itself and detecting whether or not the
current package allows the user to search content. The latter isn't that hard as
I can simply check if the ``search_model`` attribute is set. The former is a bit
of an annoying issue as the current admin panel doesn't really have a nice spot
for a search box.