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

Is it possible to use Criteria API to query with Postgres functions such as to_tsquery and to_tsvector? #825

Open
mindy-jump opened this issue Apr 10, 2023 · 3 comments
Assignees
Labels
for: team-attention An issue we need to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged

Comments

@mindy-jump
Copy link

I am trying to implement full text search to one of my apis, here's an example postgres sql query:

SELECT *
FROM recipes
WHERE  to_tsvector('english', description || ' ' || name @@ to_tsquery('english', 'uni:*'); 

I've attempted to try and do the below within the code but noticed the where clause is only Critera.CriteriaStep type and needs to be chained with some operator to make it a Criteria:

Criteria criteria = Criteria.where("to_tsvector('english', " + VECTOR_FUNC + "@@ to_tsquery('english', 'sec:*');");
this.template
    .select(RecipeEntity.class)
    .matching(Query.query(criteria)).all();

Or would I have to do something like below? I am relatively new to using this framework and apologies if this has already gone answered.

databaseClient
    .sql("SELECT id, type FROM recipes WHERE  to_tsvector('english', description || ' ' || name @@ to_tsquery('english', :searchText")
    .bind("searchText", searchText)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 10, 2023
@mp911de
Copy link
Member

mp911de commented Apr 11, 2023

Right now, we do not support vendor-specific queries through the R2dbcEntityTemplate. The only way you could use this functionality is by using string-based queries on a repository, see https://docs.spring.io/spring-data/r2dbc/docs/current/reference/html/#r2dbc.repositories.queries

@mp911de mp911de self-assigned this Apr 11, 2023
@mp911de mp911de added the for: team-attention An issue we need to discuss as a team to make progress label Apr 11, 2023
@Rahul-Bukuwarung
Copy link

@mp911de Any update on this?

The query i am trying to make is below, I can't simply use a @query because i have a lot more criteria that need to be added depending on user input. Any idea on how I can get this to work

select * 
from atable
where (name_ft @@ to_tsquery('t')) 

@mindy-jump
Copy link
Author

@mp911de Any update on this?

The query i am trying to make is below, I can't simply use a @query because i have a lot more criteria that need to be added depending on user input. Any idea on how I can get this to work

select * 
from atable
where (name_ft @@ to_tsquery('t')) 

I had the same use case a year ago. We also had a couple of fields from a join table a user could also choose to filter from. I ended up just ditching the orm completely and just wrote a query builder specific to the search contract we had. Used the db client directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we need to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants