PHP code example of fromholdio / silverstripe-fulltext-filters
1. Go to this page and download the library: Download fromholdio/silverstripe-fulltext-filters 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/ */
fromholdio / silverstripe-fulltext-filters example snippets
// Define your fulltext indexes:
private static $indexes = [
'TitleFields' => [
'type' => DBIndexable::TYPE_FULLTEXT,
'columns' => [
'Title',
'MenuTitle'
]
],
'ContentFields' => [
'type' => DBIndexable::TYPE_FULLTEXT,
'columns' => [
'Content',
'MetaDescription'
]
]
];
// Use in ORM filters:
// We're using BOOLEAN MODE matching
// Matches to the TitleFields index are weighted as five times more significant than ContentFields matches
// We're calculating the sum of relevance scores per matched record, and ordering the results by descending relevance score
public function getResults($value)
{
$objects = ObjectClass::get()
->filterAny([
'TitleFields:FulltextBooleanRelevance(5)' => $value,
'ContentFields:FulltextBooleanRelevance' => $value
])
->sort('@TitleFieldsScore + @ContentFieldsScore DESC');
}