PHP code example of open-csp / wiki-search

1. Go to this page and download the library: Download open-csp/wiki-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/ */

    

open-csp / wiki-search example snippets


$response = json_decode($response, true);

$result = $response["result"];

$hits = json_decode($result["hits"], true);

foreach ($hits as $hit) {
    $namespace_name = $hit["subject"]["namespacename"];
    $page_title = $hit["subject"]["title"];

    $page_name = sprintf("%s:%s", $namespace_name, $page_title);

    echo $page_name;
}

$hits = json_decode($result["hits"], true);

foreach ($hits as $hit) {
    $highlights = $hit["highlight"];
    
    foreach ($highlights as $highlight) {
        // $highlight is an array of highlighted snippets

        $highlight_string = implode("", $highlight);
    
        echo $highlight_string;
    }
}

function onWikiSearchBeforeElasticQuery( array &$query, array &$hosts ) {}

function onWikiSearchApplyResultTranslations( array &$results ) {}

function onWikiSearchOnLoadFrontend( 
    string &$result, 
    \WikiSearch\SearchEngineConfig $config, 
    Parser $parser, 
    array $parameters 
) {}

{{#WikiSearchConfig:
  |Version
  |Tag
  |Space
  |?Title
  |?Version
}}