Making custom content types searchable

In order to add content types to Universe Search, they must be registered in the Jadu system. This is done by adding a record to the JaduContentTypes database table.

Field name Description Example value
id Unique identifier. Use numbers above 1000 for Custom types to avoid collisions with core types. 1001
singularName Name for a single item of this type of content. Car
pluralName Name for a group of items of this type of content. Cars
tableName Name of the table storing main record. CustomCars
icon Image file representing this content type. document.png
createURL unused
editURLTemplate unused
categoriesTable Name of table storing category information. CustomCarsCategories
appliedCategoriesTable Name of table storing applied category information. CustomCarsAppliedCategories
createNewPriority Position in default Create New menu 1001
groupLabel Determines label colour. Choose from the following: assetLabel, contentLabel, dataLabel, formLabel, galaxyLabel, languageLabel, widgetLabel contentLabel
itemWrapperClass Name of ItemWrapper class (see below for details) Custom_ItemWrapper_Car
itemWrapperFile File containing ItemWrapper class custom/ItemWrapper/Car.php

ItemWrapper

This is a class which provides a common interface for Universe Search to interact with a content type item.

ItemWrapper exposes methods to retrieve URLs for editing and preview of the content item, as well as methods to carry out actions such as delete, change ownership, lock and unlock.

The class will need to extend the base class Jadu_ContentType_ItemWrapper and must, as a minimum, implement all of the abstract methods in that class.

Sample implementations from the News ItemWrapper:

public function getLiveURL ()
{
  $url = "";
  if ($this->canViewLive()) {
    $url = buildNewsArticleURL($this->getID(), true, $this->getTitle());
  }
  return $url;
}

public function getPreviewURL ()
{
  $url = "";
  if ($this->canPreview()) {
      $url = SECURE_JADU_PATH . "/preview/redirect.php?contentType=news&newsID=" .
        (int)$this->getID();
  }
  return $url;
}

public function loadItem ($itemID)
{
  $this->contentItem = getNews($itemID);
}

The static function getInstance() must also be implemented. This will be used to instantiate the ItemWrapper:

public static function getInstance(ADOConnection $db, Jadu_ContentType $contentType, $itemID)
{
  $news = getNews($itemID);
  return new Jadu_Websections_ItemWrapper_NewsArticle($db, $contentType, $news);
}

SearchProvider

The SearchProvider class is required to determine the mapping between the content type’s database tables and Universe Search. It will provide a list of fields to search, identify which fields are titles, modification dates and owner IDs and specify mappings to other tables if necessary (e.g. Documents to Document Headers and Document Pages).

The class should extends the base class Jadu_Search_Provider and should implement the loadTables() method.

All of the content types available to the current administrator are made available to this method. It is suggested that one SearchProvider is written per module and handles mappings for all types in that module. The example below shows only News, but all of the publishing content types are handled by the full version of this class.

class Jadu_Websections_SearchProvider extends Jadu_Search_Provider
{
  protected function loadTables ()
  {
    foreach ($this->getContentTypes() as $contentType) {
      /* @var $contentType Jadu_ContentType */
      $table = new Jadu_Search_TableMapping($this->db);
      $table->setContentType($contentType);

      switch ($contentType->getTableName()) {
        case "JaduNews":
          $table->setSearchFields(array("main.title", "main.summary", "main.content"));
          $table->setOwnerField("main.adminID");
          $table->setModDateField("main.modDate");
          $table->setMetadataTable("JaduNewsMetadata");
          $this->addTableMapping($table);
          break;
      }
    }
  }
}

JaduSearchProviderEntries

Once complete, a record referencing the SearchProvider will need to be added to JaduSearchProviderEntries.

Field name Description Example value
id Unique identifier. Use values above 100 for custom SearchProviders to avoid collisions with core classes. 101
className Name of SearchProvider class Jadu_Custom_SearchProvider
classFile Name of php file containing class. custom/SearchProvider.php

results matching ""

    No results matching ""