Skip to content

Conversation

mnocon
Copy link
Contributor

@mnocon mnocon commented Jun 2, 2025

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 mnocon changed the title CustomField [WIP] CustomField Jun 2, 2025
Copy link

github-actions bot commented Jun 2, 2025

@mnocon mnocon force-pushed the custom-field-missing branch from 2fe3c4a to be729c0 Compare October 7, 2025 07:09
@mnocon mnocon force-pushed the custom-field-missing branch from be729c0 to 5027f1a Compare October 7, 2025 20:11
Copy link

github-actions bot commented Oct 7, 2025

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

@mnocon mnocon marked this pull request as ready for review October 8, 2025 09:18
@mnocon mnocon changed the title [WIP] CustomField Documented CustomField criterion Oct 8, 2025
@mnocon mnocon requested review from adriendupuis and a team October 8, 2025 09:20
@ezrobot ezrobot requested review from dabrt and julitafalcondusza and removed request for a team October 8, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant