Skip to content
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

Cannot be used with PostgreSQL #87

Open
EdouardCourty opened this issue Aug 29, 2023 · 5 comments
Open

Cannot be used with PostgreSQL #87

EdouardCourty opened this issue Aug 29, 2023 · 5 comments

Comments

@EdouardCourty
Copy link

Describe the bug
Hi, when using TypesenseBundle with a PostgreSQL database, it is impossible to use the query method from CollectionFinderInterface, that is supposed to return hydrated Doctrine Entities.
The bundle uses the ORDER BY FIELD directive, which is specific to MySQL.

To Reproduce
Steps to reproduce the behavior:

  1. Start a Symfony 6.3 project, with a PostgreSQL database, and TypesenseBundle enabled
  2. Configure the bundle properly to persist an entity (like a topic with an author and a content)
  3. Persist at least one entity
  4. Use the query method

Expected behavior
Should return the hydrated objects instead of crashing (from the SQL server).

Screenshots
image
image
image

Desktop (please complete the following information):

  • OS: Ubuntu 22.04 LTS
  • Docker

Additional context

  • PostgreSQL version: postgres:14.2 (postgres:14.2-alpine docker image)
  • Typesense version: 0.25.0 (typesense/typesense:0.25.0 docker image)
@EdouardCourty
Copy link
Author

I suggest to add a configuration key 'database', which accepts either 'mysql' or 'postgresql' (or gets it from the Doctrine configuration automatically), to then customize the request according to which engine is used.

@EdouardCourty
Copy link
Author

Also, could you not use Doctrine to query the database? It would be much simpler!

@npotier
Copy link
Member

npotier commented Aug 31, 2023

Hello @EdouardCourty thank you for reporting this issue.

This is indeed a problem, I will have a look at it this week.

@npotier
Copy link
Member

npotier commented Aug 31, 2023

Quick update on this subject

As you can see if you read the code, the hydrate() function load entities from the database, based on the results given by Typesense.

In order to be sure that the hydrated collection is in the same order than the given result by typesense (eg : ids (3,1,6)), we add a SORT instruction with FIELD in our request.

We use it in a native SQL request. it could be done using the beberlei/DoctrineExtensions, to use Doctrine Query Builder, but after some research it appears that FIELD instruction is not available in PostGreSQL.

So, I don't see how to get a sorted collection with PostGreSQL that respects the Typesense order.

I think we should refactor the code in order to sort the entities in PHP.

@EdouardCourty
Copy link
Author

EdouardCourty commented Sep 16, 2023

Hi, thanks for your reply :)

For now I'm using the RawQuery method and I deserialize the documents myself.
Also I had a few commands idea that could make the bundle even easier to use.

I would be more than happy to contribute to the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants