Indexing and Searching
Each content type in Speck gets its own database table and is defined with its own properties. Although this is very flexible, it makes things tricky for building a search index off the database, because there are multiple tables and no content properties that are shared among all content types.
The portal framework creates a separate content index table which can be used to build a searchable index of content on a web site (using an indexing engine like verity or full text indexing features of the DBMS). This table includes standard columns for title, description etc. and developers can decide which properties from their content types should be mapped to the columns in the content index. The cf_spIndex tag can be used within a content type definition to define how properties of a content type are mapped to columns in the content index table. This tag must be called within cf_spType tags and after all property definitions. Once the mapping is defined, Speck will take care of inserting, updating and deleting rows whenever content items are saved, deleted or removed/archived (when revisioning is enabled, "deleting" a content item doesn't actually delete it from the database).
The following table list the attributes of the cf_spIndex tag:
|title||List||Yes||List of properties, whose values will be concatenated and used as the value of the title field in the content index.|
|description||List||Yes||List of properties, whose values will be concatenated and used as the value of the description field in the content index.|
|body||List||Yes||List of properties, whose values will be concatenated and used as the value of the body field in the content index.|
|date||String||No||Name of the property to use as the date/timestamp field in the content index. Defaults to the value of the spCreated system field for a content item.|
Both the Article and Event content types included with Speck provide examples of how to use the cf_spIndex tag. An example script to create a verity index from the content index table is included in the speck/www/portal directory. We also use the content index with PostgreSQL's full text index. There is no example search template at the moment, but building a search form is simple enough.
In addtion to title, description, body and ts (timestamp) columns, the content index table includes id and keyword columns, which can be used to build a URL to view a content item from a search results page (the request.speck.getDisplayMethodUrl() function can be used to build the URL). The content index assumes that each indexable item of content has at least one keyword (on the basis that keywords are used to place content items in particular locations on a site developed using the portal framework). Content items that don't have keywords won't get saved into the content index and at the moment, the content index only stores one row per content item, so items that appear in multiple locations on the web site will only be indexed in one of those locations (usually just the first one).