login | register
Mon 13 of Oct, 2008 (01:58 UTC)

bitweaver - Web Application Framework and CMS

Web Application Framework and CMS

Refresh cacheHistoryPrint

SearchPackageDevNotes

Developer notes for the Search Package

Created by: Sean Lee, Last modification: Mon 20 of Feb, 2006 (03:06 UTC)

Overview

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.

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.

How to index more fields

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 last couple of lines of the Wiki packages BitPage::Verify( ) function, you will see what I mean ...
  1. //override default index words because wiki pages have data in non-liberty tables (description in this case)
  2. $this->mInfo['index_data'] = $pParamHash["title"] . ' ' . ' ' . $pParamHash["edit"] . ' ' . $pParamHash["description"];
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.

Additionally, in BitPage we need to override the setIndexData() function (in LibertyContent) since the default function won't pick up the descriptions. The purpose of setIndexData is to populate the mInfo['index_data'] hash when the admin reindex or cmd_line_reindex is invoked. Normal indexing alreay happened with the store() function. This is for rebuilding the index long after the store was done. You can compare the two pieces of code (BitPage::setIndexData and LibertyContent::setIndexData) yourself

How to conditionally index data

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::Verify( ) function ...
  1. if ( array_search($pParamHash['article_store']['status_id'],
  2. array(ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING))) {
  3. $this->mInfo["no_index"] = true ;
  4. } //
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.

The next thing to do here is to fire off the index function after the article gets approved.
This is accomplished in the BitArticle::setStatus( ) function. Here is a snippet:
  1. if( $gBitSystem->isPackageActive( 'search' ) ) {
  2. include_once( SEARCH_PKG_PATH.'refresh_functions.php' );
  3. if ($pStatusId == ARTICLE_STATUS_APPROVED) {
  4. refresh_index($this);
  5. } //
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.

Summary

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 Verify() 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).

If you need more than the default functionality ("title", "author_name" and "edit"), you should:
  1. add appropriate fields yourself to the $pParamHash->mInfo['index_data'] element to prevent the default behavior from occurring.
  2. 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).
  3. 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.

Comments

Related Items

Documentation

More Developer Documenation  •  Archived Picture Upload with Fisheye under Windows  •  AuthenticationPlugins  •  bitweaver Documentation Project  •  bitweaverFeatures  •  bitweaverOverview  •  CamelCase  •  content  •  DataPluginLibrary  •  InstallbitweaverDoc  •  layout  •  Screenshots  •  SearchPackageDevNotes  •  StyleLayouts  •  Top 10 mistakes after installing Bitweaver  •  wiki syntax

Documentation » Tutorials

Tutorials to help you work out how something in bitweaver is done

Archived Picture Upload with Fisheye under Windows  •  Configuring multisites  •  Creating Screencasts  •  DatabaseTestsAndFixes-Firebird  •  GalaxiaTutorial  •  Groups and Permissions  •  Home Page Tutorial  •  Install pspell on Windows  •  IntegrationTutorial  •  JavaScript Module Tutorial  •  Migrating Users Between Bitweaver Sites  •  phpBB to Boards Upgrade  •  phpbbTutorial  •  Schema tutorial  •  SearchPackageDevNotes  •  Speed optimisation  •  Squirrel Mail Integration Tutorial  •  theme compliance with MSIE  •  ThemeTutorial  •  TopBarTutorial  •  TranslationTutorial  •  Tutorial_Custom_Module  •  Tutorial - Liberty Plugins  •  Tutorial - Liberty Plugins II  •  Tutorial - Native Theme  •  Tutorials  •  Use bitweaver to build a web site that is very nice  •  Wiki Plugin Tutorial  •  wiki syntax  •  Screencasts  •  InstallShots  •  Video: Installation of Bitweaver

Documentation » Technical Documentation

Documentation geared towards developers and people who want to learn about the core processes of bitweaver

HEAD ON! Support has been added for Pear::DB!  •  Oracle Reservations for Two  •  ReleaseTwo: Shedding that last bits of our roots, finding the core of our being  •  getContentList  •  How to add a pagination to an object list  •  Moving bw in another directory  •  pma and mysql  •  safe mode on / open_base_dir  •  sequence and auto  •  The package I am currently developping is suddenly desactivated  •  APIDocumentation  •  Archived Picture Upload with Fisheye under Windows  •  Bitweaver and Browser Cookies  •  bitweaverCVS  •  bitweaverFeatures  •  bitweaverPerformance  •  CodingGuidelines  •  CreatingServices  •  CssSchema  •  InstallbitweaverDoc  •  IntegrationTutorial  •  LibertyFormats  •  LibertyMime  •  LibertyServices  •  phpdoc content status  •  PortingTikiWikiPackages  •  PrototypeAjaxObject  •  PrototypeReference  •  SamplePackage  •  SearchPackageDevNotes  •  TUTORIAL - Displaying Icons ONLY to AUTHORS of the page  •  Tutorial - Liberty Plugins  •  Tutorial - Liberty Plugins II  •  UsersDoc