New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the search to work with uuids #1962

Open
carakas opened this Issue Jan 28, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@carakas
Member

carakas commented Jan 28, 2017

Type

  • Enhancement

Problem description

You can now only use integers as id's for the search, if switched to strings we can use UUID's

Why?

When creating modules with Doctrine entities and UUID,
$id is char(36) in combination with (DC2Type:guid).

So using the current search module will not be possible anymore for these custom modules,
since it requires the $otherId to be an int and we have a char...

// save the tags
BackendSearchModel::saveIndex(string $module, int $otherId, array $fields, string $language = null)

@carakas carakas added this to the 5.0.0 milestone Jan 28, 2017

@jeroendesloovere jeroendesloovere self-assigned this Feb 21, 2017

@jeroendesloovere jeroendesloovere removed their assignment Jun 28, 2017

@carakas carakas removed the Nice to have 5 label Aug 1, 2017

@carakas carakas modified the milestones: 6.0.0, 5.0.0 Aug 1, 2017

@carakas

This comment has been minimized.

Show comment
Hide comment
@carakas

carakas Aug 2, 2017

Member

For now you can fix it with something like this

Entity

    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * we need this since the search index only works with integers
     *
     * @ORM\Column(type="integer")
     */
    private $searchId;

    /**
     * @param int $searchId
     *   …
     */
    public function __construct(
        $searchId
        
    ) {

Creating new instance of entity

        $myEntity = new MyEntity(
            $this->myEntityRepository->getNextSearchId(),

        );

Repository

    public function getNextSearchId(): int
    {
        return (int) $this->getEntityManager()->createQueryBuilder()
            ->select('(COALESCE(MAX(e.searchId), 0) + 1) AS searchId')
            ->from(MyEntity::class, 'e')
            ->getQuery()
            ->getSingleScalarResult();
    }
Member

carakas commented Aug 2, 2017

For now you can fix it with something like this

Entity

    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * we need this since the search index only works with integers
     *
     * @ORM\Column(type="integer")
     */
    private $searchId;

    /**
     * @param int $searchId
     *   …
     */
    public function __construct(
        $searchId
        
    ) {

Creating new instance of entity

        $myEntity = new MyEntity(
            $this->myEntityRepository->getNextSearchId(),

        );

Repository

    public function getNextSearchId(): int
    {
        return (int) $this->getEntityManager()->createQueryBuilder()
            ->select('(COALESCE(MAX(e.searchId), 0) + 1) AS searchId')
            ->from(MyEntity::class, 'e')
            ->getQuery()
            ->getSingleScalarResult();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment