SearchPackageDevNotes
Developer notes for the Search Package
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 ...
//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"];
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 ...
$this->mInfo["no_index"] = true ; } //
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:
if( $gBitSystem->isPackageActive( 'search' ) ) { include_once( SEARCH_PKG_PATH.'refresh_functions.php' ); if ($pStatusId == ARTICLE_STATUS_APPROVED) { refresh_index($this); } //
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:
- add appropriate fields yourself to the $pParamHash->mInfo['index_data'] element to prevent the default behavior from occurring.
- 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).
- 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.
Related Items
Documentation
most of our documentation is nicely sorted into categories, making it eaier to access and find
More Developer Documenation • setiawan's Blog • Archived Picture Upload with Fisheye under Windows • AuthenticationPlugins • bitweaver Documentation Project • bitweaverFeatures • bitweaverLogo03 • bitweaverOverview • CamelCase • content • DataPluginLibrary • InstallbitweaverDoc • layout • Screenshots • SearchPackageDevNotes • StyleLayouts • 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
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
Comments