contextualcode / ibexa-solr-search-query-boost
Implements query boosting for the Solr search query.
v2.0.0
2024-08-21 16:14 UTC
Requires
- php: >=7.4
- ext-dom: *
- ezsystems/ezplatform-solr-search-engine: ^3.0
- symfony/config: ^5.0
- symfony/dependency-injection: ^5.0
- symfony/http-kernel: ^5.0
This package is not auto-updated.
Last update: 2024-12-11 17:46:50 UTC
README
This package implements query boosting for the Solr search query in Ibexa DXP.
Installation
Require via composer:
composer require contextualcode/ibexa-solr-search-query-boost
Usage
You need to use
ContextualCode\IbexaSolrSearchQueryBoost\Query\Criterion\FullText
instead ofeZ\Publish\API\Repository\Values\Content\Query\Criterion\FullText
:<?php ... - use eZ\Publish\API\Repository\Values\Content\Query\Criterion\FullText; + use ContextualCode\IbexaSolrSearchQueryBoost\Query\Criterion\FullText; ...
New
queryBoost
parameter is available for the updatedFullText
criteria. It expects to havefields
and/ortypes
parameters:<?php ... - $fullTextQuery = new FullText('test'); + $fullTextQuery = new FullText('test', ['queryBoost' => $queryBoost]); ...
The example src/Controller/CustomSearch.php
controller with implemented query boost:
<?php
namespace App\Controller;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\Query;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use ContextualCode\IbexaSolrSearchQueryBoost\Query\Criterion\FullText;
class CustomSearch extends AbstractController
{
private $searchService;
public function __construct(SearchService $searchService) {
$this->searchService = $searchService;
}
public function search(Request $request): JsonResponse
{
$queryBoost = [
'fields' => [
'article' => ['title' => 5, 'intro' => 2],
'folder' => ['name' => 3],
],
'types' => ['article' => 10, 'folder' => 0.8],
];
$query = new Query([
'query' => new FullText('test', ['queryBoost' => $queryBoost])
]);
$results = $this->searchService->findContent($query);
return new JsonResponse($results);
}
}