PHP code example of pennebaker / craft-searchwithelastic

1. Go to this page and download the library: Download pennebaker/craft-searchwithelastic 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/ */

    

pennebaker / craft-searchwithelastic example snippets



return [
    'elasticsearchEndpoint' => 'localhost:9200',
    'isAuthEnabled' => false,
    
    // Basic indexing settings
    'assetKinds' => ['pdf', 'text', 'html'],
    'indexableEntryStatuses' => ['live'],
];


return [
    'elasticsearchEndpoint' => '$ELASTICSEARCH_ENDPOINT',
    'isAuthEnabled' => true,
    'username' => '$ELASTICSEARCH_USERNAME',
    'password' => '$ELASTICSEARCH_PASSWORD',
    
    // Rate limiting
    'rateLimitingEnabled' => true,
    'rateLimitRequestsPerMinute' => 60,
    'rateLimitBurstSize' => 10,
    
    // Basic indexing settings
    'assetKinds' => ['pdf', 'text', 'html'],
    'indexableEntryStatuses' => ['live'],
];

// Secure template execution
$results = SearchWithElastic::getInstance()->searchTemplate->executeTemplate(
    SearchTemplates::TEMPLATE_BASIC_SEARCH,
    ['query_text' => $userInput, 'search_fields' => ['title', 'content']],
    $indexName
);