PHP code example of werkbot / werkbot-search

1. Go to this page and download the library: Download werkbot/werkbot-search library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

werkbot / werkbot-search example snippets


Page::add_extension(SearchableExtension::class);
PageController::add_extension(SearchControllerExtension::class);

/**
 * getIndexQuery
 * This query is used when building the index
 *
 * @return string|boolean - FALSE if not set
 */
public function getIndexQuery()
{
  return "SELECT
      concat(\"Page_\", SiteTree.ID) AS ID,
      SiteTree.ClassName,
      SiteTree.Title,
      SiteTree.Content
    FROM
      Page
    LEFT JOIN
      SiteTree
    ON
      SiteTree.ID = Page.ID
    WHERE
      SiteTree.ShowInSearch = '1'"
    AND
      SiteTree.Content IS NOT NULL;
}

SearchableDataObject::add_extension(SearchableExtension::class);  // MUST BE APPLIED FIRST for getIndexQuery to return SQL Query string.
SearchableDataObject::add_extension(SearchableDataObjectExtension::class); // Defines getIndexQuery SQL Query string.