Difference between revisions of "Creating a Smart Search plug-in"

From Joomla! Documentation

(Minor improvements.)
Line 25: Line 25:
 
For a complete Smart Search plug-in there are a number of other methods you may need to override.
 
For a complete Smart Search plug-in there are a number of other methods you may need to override.
  
* _getStateQuery
+
* translateState
*: This method must return a JDatabaseQuery object that will form the basis of a query that will return the state and access level of the given content type.  There are constraints on this query to ensure that it is compatible with other methods used by the indexer.  This method is described in more detail later.
+
*: Given a content item this method translates the native state of the content item into a state that the indexer can useIt must return an integer 0 if the content item is not to appear in search results, or an integer 1 if the content item can appear in search results.
  
 
==Event methods==
 
==Event methods==
Line 40: Line 40:
 
* onFinderCategoryChangeState
 
* onFinderCategoryChangeState
 
*: Called in response to an onCategoryChangeState event.
 
*: Called in response to an onCategoryChangeState event.
 +
 +
==Methods in more details==
 +
 +
===getListQuery===
 +
This method must return a JDatabaseQuery object that will form the basis of a query that will return a list of objects of the given content type.  There are constraints on this query to ensure that it is compatible with other methods used by the indexer.  If the following conditions are not true then you will need to override other methods in the FinderIndexerAdapter class.
 +
* The primary database table that is being indexed must have an alias of "a".<ref>If this condition is not true you will also have to override the getItem, getUpdateQueryByTime and getUpdateQueryByIds methods</ref>
 +
 +
===index===
 +
This method is called whenever a content item needs to be indexed (or re-indexed).  It is passed an object of type FinderIndexerResult and its purpose is to make adjustments to that object and to add metadata before handing control to FinderIndexer::index method to do the indexing proper.
 +
 +
==FinderIndexerResult properties==
 +
* url
 +
* route
 +
* title
 +
* description
 +
* published
 +
* state
 +
* access
 +
* language
 +
* publish_start_date
 +
* publish_end_date
 +
 +
==Notes==
 +
<references/>
  
 
[[Category:Smart Search]]
 
[[Category:Smart Search]]

Revision as of 11:19, 8 January 2012

Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Chris Davenport (talk| contribs) 12 years ago. (Purge)

Smart Search plug-ins are gathered together for convenience into a plug-in group called "finder". Take a look in the plugins/finder directory and you will see the plug-ins that support the core Joomla content types. It is best to create your own plug-in by taking a copy of one of these plug-ins and adapting it to meet your specific needs.

All Smart Search plug-ins extend the FinderIndexerAdapter class which contains a good many methods to deal with maintaining the index. For the vast majority of custom content requirements you will only need to override a few of these methods.

The principle properties[edit]

Before looking at the methods, there are a few properties that need to be set up correctly:

  • $context
    This should be a unique identifier for the plug-in and establishes the context that the plug-in will respond to (eg. "Content").
  • $extension
    The name of the extension (component) that handles the content type (eg. "com_content").
  • $layout
    The sublayout to use when rendering search results. For example, of $layout is set to "article" then the default view will look for a layout file called default_article.php when it needs to render a search result of this type. If no such file is found then the layout file called default_result.php will be used instead.

The principle methods[edit]

The first methods you will want to override when developing a new Smart Search plug-in are the setup, index and getListQuery methods. In the vast majority of cases those three methods will be enough to get your content indexed, although the plug-in will not be complete as there are other methods that must be implemented to deal with issues such as updating the index when the content changes. But those three methods are the working core of the plug-in.

  • setup
    This method is called by the indexer once before an indexing run begins. It can be used to load libraries or initialise variables for the plug-in. Must return true.
  • index
    This is the main method called by the indexer. It is called once for each content item that is to be indexed (or the index updated). The index method essentially describes the content to the indexer by telling the indexer which fields to parse for terms/phrases and their relative weights, which fields to map into branches of the content map and what data to include in the index as "payload". This method is described in more detail later.
  • getListQuery
    This method must return a JDatabaseQuery object that will form the basis of a query that will return a list of objects of the given content type. There are constraints on this query to ensure that it is compatible with other methods used by the indexer. This method is described in more detail later.

Some other methods[edit]

For a complete Smart Search plug-in there are a number of other methods you may need to override.

  • translateState
    Given a content item this method translates the native state of the content item into a state that the indexer can use. It must return an integer 0 if the content item is not to appear in search results, or an integer 1 if the content item can appear in search results.

Event methods[edit]

The following methods are called via the Smart Search content plug-in in response to specific trigger events in Joomla.

  • onFinderBeforeSave
    Called in response to an onContentBeforeSave event.
  • onFinderAfterSave
    Called in response to an onContentAfterSave event.
  • onFinderAfterDelete
    Called in response to an onContentDelete event.
  • onFinderChangeState
    Called in response to an onContentChangeState event.
  • onFinderCategoryChangeState
    Called in response to an onCategoryChangeState event.

Methods in more details[edit]

getListQuery[edit]

This method must return a JDatabaseQuery object that will form the basis of a query that will return a list of objects of the given content type. There are constraints on this query to ensure that it is compatible with other methods used by the indexer. If the following conditions are not true then you will need to override other methods in the FinderIndexerAdapter class.

  • The primary database table that is being indexed must have an alias of "a".[1]

index[edit]

This method is called whenever a content item needs to be indexed (or re-indexed). It is passed an object of type FinderIndexerResult and its purpose is to make adjustments to that object and to add metadata before handing control to FinderIndexer::index method to do the indexing proper.

FinderIndexerResult properties[edit]

  • url
  • route
  • title
  • description
  • published
  • state
  • access
  • language
  • publish_start_date
  • publish_end_date

Notes[edit]

  1. If this condition is not true you will also have to override the getItem, getUpdateQueryByTime and getUpdateQueryByIds methods