Skip to content

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

Open
@mindy-jump

Description

@mindy-jump

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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions