documentation-developer icon indicating copy to clipboard operation
documentation-developer copied to clipboard

Documented CustomField criterion

Open mnocon opened this issue 5 months ago • 2 comments

Target: 5.0, 4.6

As reported on Slack - https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Query-Criterion-CustomField.html is missing from the list

Tested on Solr and Elasticsearch with the following command:

<?php

namespace App;

use DateTimeImmutable;
use Ibexa\Collaboration\SessionService;
use Ibexa\Contracts\Collaboration\Session\SessionQuery;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Collaboration\Session\Query\Criterion;
use Ibexa\Contracts\Collaboration\Session\Query\SortClause;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
use Ibexa\Contracts\CoreSearch\Values\Query\SortClause\FieldValueSortClause;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Ibexa\Contracts\CoreSearch\Values\Query\Criterion\FieldValueCriterion;

class SearchCommand extends Command
{
    protected static $defaultName = 'app:search';

    private SearchService $searchService;
    private PermissionResolver $permissionResolver;
    private UserService $userService;
    private ContentService $contentService;
    private SessionService $sessionService;

    public function __construct(
        SearchService  $searchService,
        PermissionResolver $permissionResolver,
        UserService  $userService,
        ContentService $contentService,
        SessionService  $sessionService
)
    {
        parent::__construct();
        $this->searchService = $searchService;
        $this->permissionResolver = $permissionResolver;
        $this->userService = $userService;
        $this->contentService = $contentService;

        $this->sessionService = $sessionService;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin('admin'));

        $query = new Query();
        $query->query = new Query\Criterion\CustomField('content_translated_name_s', Operator::EQ, 'Default');
        $query->offset = 0;
        $query->limit = 10;
        $query->sortClauses = [new Query\SortClause\ContentId()];

        $output->writeln('Searching content!');
        $result = $this->searchService->findContent($query);

        foreach ($result->searchHits as $searchHit) {
            /** @var Content $content */
            $content = $searchHit->valueObject;
                $output->writeln('Found content: ' . $content->getName() . 'Section: ' . $content->getContentInfo()->getSection()->name);
        }
        return 0;
    }
}

mnocon avatar Jun 02 '25 09:06 mnocon

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/search/content/customfield_criterion.php


code_samples/search/content/customfield_criterion.php

docs/search/criteria_reference/customfield_criterion.md@25:``` php
docs/search/criteria_reference/customfield_criterion.md@26:[[= include_file('code_samples/search/content/customfield_criterion.php') =]]
docs/search/criteria_reference/customfield_criterion.md@27:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query;
004⫶use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
005⫶
006⫶$query = new Query();
007⫶
008⫶// Example Solr query: find content items with "content_name_s" starting with "Ibexa"
009⫶$query->query = new Query\Criterion\CustomField('content_name_s', Operator::EQ, '/Ibexa.*/');
010⫶
011⫶/** @var \Ibexa\Contracts\Core\Repository\SearchService $searchService */
012⫶$searchService->findContent($query);

Download colorized diff

github-actions[bot] avatar Oct 07 '25 20:10 github-actions[bot]