{maketoc}
<h1>Overview</h1>
Search is now a Liberty Service. What this means is all liberty content is automatically indexed when content is stored. The $_REQUEST fields that are stored automaticlly are: "title", "author_name", and "edit". "edit" is usually the main edit box. So, if your liberty package contains no more than that, you are all set. No more coding required.<BR><BR>

I'd like to cover a couple of scenarios where you might want to go beyond the default functionality: The need to index more fields than title, author_name and edit - and the need to index conditionally - like only after some event happens, such as article approval.<BR><BR>

<h1>How to index more fields</h1>
If your package has ancillary tables that contain data you want to have indexed, you will need to provide the "index words" to the index function. An example of this is Wiki page descriptions. While the bulk of the Wiki data is stored in liberty_content (formerly tiki_content in R1) the descriptions are stored in wiki_pages (tiki_pages in R1). The default index routine will miss this. So - all you need to do is to provide this extra field by setting the BitPackage->mInfo['index_data'] hash element. If you look at the first couple of lines of the Wiki packages BitPage::Store( ) function, you will see what I mean ...
{code source='Php' num=111}function store( &$pParamHash ) {
//override default index words because wiki pages have data in non-liberty tables (description in this case)
$this->mInfo['index_data'] = $pParamHash["title"] . ' ' . ' ' . $pParamHash["edit"] . ' ' . $pParamHash["description"];{/code}
Notice that there is no author_name and "description" has been added. If the mInfo['index_data'] value is set, it will be used instead of the default.<BR><BR>

Additionally, in BitPage we need to override the setIndexData() function (in LibertyContent) since the default function won't pick up the descriptions. You can compare the two pieces of code (BitPage::setIndexData and LibertyContent::setIndexData) yourself<BR><BR>

<h1>How to conditionally index data</h1>
You can prevent the index routines from doing their work by setting the mInfo->["no_index"] = true. An example of this is in the articles BitArticle::Store( ) function ...
{code source='Php' num=150}
function store( &$pParamHash ) {
global $gBitSystem;
if( $this->verify( $pParamHash ) ) {
if ( array_search($pParamHash['article_store']['status_id'],
array(ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING))) {
$this->mInfo["no_index"] = true ;
}
if (LibertyAttachable::store( $pParamHash ) ) {
{/code}
Here you see that the "no_index" value is set if the article's status is DENIED, DRAFT or PENDING. Otherwise, the article will be indexed.<BR><BR>

The next thing to do here is to fire off the index function after the article gets approved.<BR>
This is accomplished in the BitArticle::setStatus( ) function. Here is a snippet:
{code num=760}
if( $gBitSystem->isPackageActive( 'search' ) ) {
include_once( SEARCH_PKG_PATH.'refresh_functions.php' );
if ($pStatusId == ARTICLE_STATUS_APPROVED) {
refresh_index($this);
{/code}
The setIndexData function is in the LibertyContent class, and adds the three default fields to the "index_data" hash element. Then, once this is set, the call to refresh_index passing the object reference to itself.<BR><BR>

<h1>Summary</h1>
The two pieces of code needed to call the index functions are the populating of the $pParamHash->mInfo['index_data'] element (used at the time Store() is called) - and a setIndexData function (called when indexing is demanded via the search admin screen, or by the command line reindex script (cmd_line_reindex.php).<BR><BR>
If you need more than the default functionality ("title", "author_name" and "edit"), you should:
<OL><LI>add appropriate fields yourself to the $pParamHash->mInfo['index_data'] element to prevent the default behavior from occurring.
<LI>Override the LibertyContent::setIndexData function in your BitPackage.php file, and use a more appropriate select statement for your needs (copy the one from LibertContent to get you started).
<LI>If you need to conditionally index data, set the mInfo->["no_index"] = true to prevent indexing, and call the search function refresh_index() directly when you need it.
</OL>
Page History
Date/CommentUserIPVersion
20 Feb 2006 (03:06 UTC)
Update after moving some code.
Sean Lee64.222.114.2254
Current • Source
Sean Lee64.222.114.2253
View • Compare • Difference • Source
Sean Lee64.222.114.2252
View • Compare • Difference • Source
Sean Lee64.222.114.2251
View • Compare • Difference • Source