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
@github-actions
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
@github-actions
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 a team and adriendupuis October 8, 2025 09:20
@ezrobot ezrobot requested review from dabrt and julitafalcondusza and removed request for a team October 8, 2025 09:20
@mnocon mnocon requested a review from a team October 30, 2025 10:02
@ezrobot ezrobot requested review from Steveb-p, ViniTou, adamwojs, alongosz, barw4, ciastektk, konradoboza, mikadamczyk, tbialcz and wiewiurdp and removed request for a team October 30, 2025 10:02

The [`CustomField` Search Criterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Query-Criterion-CustomField.html) searches for content or locations based on the contents of the search index fields.

The allowed syntax and operator support might differ between search engines and the type of queried field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support might differ between search engines
The `CustomField` Criterion isn't available in Repository filtering

I assume you got this information from Konrad, as it does not derive directly from the description in API reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The regex query look different, for example, I've also verified it manually by using the Command I've shared
  2. Repository filtering uses the database, this criterion is only for querying the search index (and it does not implement the special marker interface)

@mnocon mnocon merged commit 48ca379 into 5.0 Nov 6, 2025
21 of 22 checks passed
@mnocon mnocon deleted the custom-field-missing branch November 6, 2025 08:27
mnocon added a commit that referenced this pull request Nov 6, 2025
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.

3 participants