diff --git a/CHANGELOG.md b/CHANGELOG.md index 521df608..047e1815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ https://www.markdownguide.org/basic-syntax/ ## [Unreleased] +## [0.4.4] - 2025-10-19 +TODO +- Changed constructor com.github.starnowski.posjsonhelper.text.hibernate6.operators.TextOperatorFunction#TextOperatorFunction(org.hibernate.query.sqm.NodeBuilder, com.github.starnowski.posjsonhelper.text.hibernate6.functions.TSVectorFunction, org.hibernate.query.sqm.tree.expression.SqmExpression, com.github.starnowski.posjsonhelper.core.HibernateContext) to com.github.starnowski.posjsonhelper.text.hibernate6.operators.TextOperatorFunction#TextOperatorFunction(org.hibernate.query.sqm.NodeBuilder, org.hibernate.query.sqm.tree.expression.SqmExpression, org.hibernate.query.sqm.tree.expression.SqmExpression, com.github.starnowski.posjsonhelper.core.HibernateContext) [158](https://github.com/starnowski/posjsonhelper/issues/158) + + ## [0.4.3] - 2025-06-29 ### Added diff --git a/core/src/main/java/com/github/starnowski/posjsonhelper/core/Context.java b/core/src/main/java/com/github/starnowski/posjsonhelper/core/Context.java index a64831f1..87a7c605 100644 --- a/core/src/main/java/com/github/starnowski/posjsonhelper/core/Context.java +++ b/core/src/main/java/com/github/starnowski/posjsonhelper/core/Context.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/core/src/main/java/com/github/starnowski/posjsonhelper/core/HibernateContext.java b/core/src/main/java/com/github/starnowski/posjsonhelper/core/HibernateContext.java index 9b443070..0747eb94 100644 --- a/core/src/main/java/com/github/starnowski/posjsonhelper/core/HibernateContext.java +++ b/core/src/main/java/com/github/starnowski/posjsonhelper/core/HibernateContext.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/ISQLDefinition.java b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/ISQLDefinition.java index dd4a4f31..6952aff4 100644 --- a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/ISQLDefinition.java +++ b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/ISQLDefinition.java @@ -36,9 +36,9 @@ public interface ISQLDefinition { /** * Returns DDL statement that drops changes applied by statement returned by the {@link #getCreateScript()} method. - *

+ * * IMPORTANT! - *

+ * * By default, there is no assumption that statement has to contains the compensation operation for operation returned by the {@link #getCreateScript()} method. * This means that the operation can not be by default treated as a rollback operation, but an operation that removes changes applied by statement returned by the {@link #getCreateScript()} method. * @return DDL statement that drops changes applied by statement returned by the {@link #getCreateScript()} method. diff --git a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/AbstractFunctionDefinitionFactory.java b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/AbstractFunctionDefinitionFactory.java index 1d2b7aea..5d6142cb 100644 --- a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/AbstractFunctionDefinitionFactory.java +++ b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/AbstractFunctionDefinitionFactory.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/DefaultFunctionArgument.java b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/DefaultFunctionArgument.java index d4f3395f..c76afd6e 100644 --- a/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/DefaultFunctionArgument.java +++ b/core/src/main/java/com/github/starnowski/posjsonhelper/core/sql/functions/DefaultFunctionArgument.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/descriptor/CastOperatorFunctionDescriptor.java b/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/descriptor/CastOperatorFunctionDescriptor.java index 9f6b560d..1c1c77de 100644 --- a/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/descriptor/CastOperatorFunctionDescriptor.java +++ b/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/descriptor/CastOperatorFunctionDescriptor.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/operators/CastOperatorFunction.java b/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/operators/CastOperatorFunction.java index 0ace8079..2b04c3c7 100644 --- a/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/operators/CastOperatorFunction.java +++ b/hibernate6-core/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/operators/CastOperatorFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/Hibernate6JsonUpdateStatementBuilder.java b/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/Hibernate6JsonUpdateStatementBuilder.java index a29ec497..ac93792c 100644 --- a/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/Hibernate6JsonUpdateStatementBuilder.java +++ b/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/Hibernate6JsonUpdateStatementBuilder.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 @@ -73,7 +73,7 @@ * document = JsonPath.parse((Object) JsonPath.read(item.getJsonbContent(), "$")); * assertThat(document.jsonString()).isEqualTo("{\"child\":{\"pets\":[\"cat\"],\"birthday\":\"2021-11-23\"},\"parents\":[{\"name\":\"simone\",\"type\":\"mom\"}],\"inventory\":[\"fins\"],\"nicknames\":{\"school\":\"bambo\"}}"); * } - *

+ * * The above code is going to execute below sql statement for update: * *

{@code
@@ -95,8 +95,8 @@
  *     where
  *         id=?
  * }
- *

- *

+ * + * * As it can be observed based on generated SQL, by default, the first operation is going to be an operation that deletes JSON content. * The most nested jsonb_set operation is going to set property "parents" with value "[]". * @@ -243,7 +243,7 @@ public Hibernate6JsonUpdateStatementBuilder withPostSortFilter(JsonUpdateS * JsonUpdateStatementOperation{jsonTextArray={parents,0}, operation=JSONB_SET, value='{"type":"mom", "name":"simone"}'} * ] * } - *

+ * * The expression generated on such would be translated to below sql part: * *

{@code
diff --git a/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/predicates/AbstractJsonbArrayStringsExistPredicate.java b/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/predicates/AbstractJsonbArrayStringsExistPredicate.java
index 4692052a..5f6cf5b2 100644
--- a/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/predicates/AbstractJsonbArrayStringsExistPredicate.java
+++ b/hibernate6/src/main/java/com/github/starnowski/posjsonhelper/hibernate6/predicates/AbstractJsonbArrayStringsExistPredicate.java
@@ -44,7 +44,7 @@
  * 
{@code
  * {{main_func}}( jsonb_extract_path( generatedAlias0.jsonbContent , :param0 ) , json_function_json_array(:param1, :param2))
  * }
- *

+ * * where: * {{main_func}} - name of main function returned by method {@link #getFunctionName()} * jsonb_extract_path( generatedAlias0.jsonbContent , :param0 ) - json path part, with this example path has only one element normally this could part could contain more elements "param" diff --git a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/DefaultJsonUpdateStatementOperationSort.java b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/DefaultJsonUpdateStatementOperationSort.java index b0fee5ee..aee125b1 100644 --- a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/DefaultJsonUpdateStatementOperationSort.java +++ b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/DefaultJsonUpdateStatementOperationSort.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfiguration.java b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfiguration.java index 43184097..ef965144 100644 --- a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfiguration.java +++ b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfiguration.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfigurationBuilder.java b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfigurationBuilder.java index 04185b87..5c5580e4 100644 --- a/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfigurationBuilder.java +++ b/json-core/src/main/java/com/github/starnowski/posjsonhelper/json/core/sql/JsonUpdateStatementConfigurationBuilder.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 @@ -49,7 +49,7 @@ * result.operations * System.out.println(result.operations) * }

- *

+ * * It generates configuration with below operations: * *

{@code
@@ -60,7 +60,7 @@
  * JsonUpdateStatementOperation{jsonTextArray={parents,0}, operation=JSONB_SET, value='{"type":"mom", "name":"simone"}'}
  * ]
  * }
- *

+ * * Assuming that we have database table "item" and column that stores json is called "jsonb_content" the update statement * would like as below example: * @@ -79,10 +79,10 @@ * WHERE * id=? * } - *

+ * * In such a prepared statement, the top operation would set the "parents" property with an empty array. * The next operation will set the "child, birthday" property to "2021-11-23" and so on. - *

+ * * For more details please check {@link #build()} method. */ public class JsonUpdateStatementConfigurationBuilder { diff --git a/text/README.md b/text/README.md index 3e95f8e8..ca6a542c 100644 --- a/text/README.md +++ b/text/README.md @@ -15,6 +15,7 @@ * [Function 'phraseto_tsquery'](#function-phraseto_tsquery) * [Function 'websearch_to_tsquery'](#function-websearch_to_tsquery) * [Function 'to_tsquery'](#function-to_tsquery) +* [Text ranking with ts_rank and ts_rank_cd](#text-ranking-with-ts_rank-and-ts_rank_cd) * [Properties](#properties) * [Reporting issues](#reporting-issues) * [Project contribution](#project-contribution) @@ -25,6 +26,8 @@ The library is written in a java programming language. The project for this moment supports Hibernate in version 6. The required version of java is at least version 11. +# How to start using posjsonhelper + ### Setting maven dependency The project is available in the central maven repository. You can use it just by adding it as a dependency in the project descriptor file (pom.xml). @@ -327,6 +330,235 @@ And the same example but with HQL: } ``` +### Text ranking with ts_rank and ts_rank_cd + +PostgreSQL provides ranking functions that allow ordering search results based on the relevance of a match between a document and a search query. +Two most commonly used ranking functions are [`ts_rank`](https://www.postgresql.org/docs/current/textsearch-controls.html) and [`ts_rank_cd`](https://www.postgresql.org/docs/current/textsearch-controls.html). + +* **`ts_rank`** — calculates a rank based on term frequency and inverse document frequency (TF/IDF). +* **`ts_rank_cd`** — a variant that uses cover density ranking, which tends to favor documents where query terms appear close together. + +Currently, **posjsonhelper** does not provide direct wrappers for these ranking functions. +However, it is still possible to use them by leveraging the **Hibernate Criteria API** or **HQL**, as shown below. + +##### Example: Ranking using `ts_rank` + +The following example demonstrates how to calculate and sort results by the `ts_rank` function using Hibernate’s Criteria API: + +```java +public List findItemsByWebSearchToTSQuerySortedByTsRank(String phrase, boolean ascSort) { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Item.class); + Root root = cq.from(Item.class); + + // Build weighted tsvector using posjsonhelper functions + Expression shortNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("A") + ); + + Expression fullNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("B") + ); + + Expression shortDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("C") + ); + + Expression fullDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("D") + ); + + // Concatenate tsvectors (|| operator) + SqmExpression fullVector = (SqmExpression) cb.concat(cb.concat(shortNameVec, fullNameVec), cb.concat(shortDescriptionVec, fullDescriptionVec)); + + // Build tsquery + Expression queryExpr = new WebsearchToTSQueryFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, phrase); + + // WHERE clause using @@ operator + TextOperatorFunction matches = new TextOperatorFunction((NodeBuilder) cb, fullVector, new WebsearchToTSQueryFunction((NodeBuilder) cb, new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), phrase), hibernateContext); + + cq.where(matches); + + // Ranking + Expression rankExpr = cb.function( + "ts_rank", Double.class, + fullVector, + queryExpr + ); + + cq.orderBy(ascSort ? cb.asc(rankExpr) : cb.desc(rankExpr)); + + return entityManager.createQuery(cq).getResultList(); + } +``` + +This query produces SQL similar to: + +```sql +select + i1_0.id, + i1_0.full_description, + i1_0.full_name, + i1_0.short_description, + i1_0.short_name + from + item i1_0 + where + ( + ( + setweight(to_tsvector(?::regconfig, i1_0.short_name), 'A')||setweight( + to_tsvector(?::regconfig, i1_0.full_name), 'B' + ) + )||( + setweight(to_tsvector(?::regconfig, i1_0.short_description), 'C')||setweight( + to_tsvector(?::regconfig, i1_0.full_description), 'D' + ) + ) + ) @@ websearch_to_tsquery(?::regconfig, ?) + order by + ts_rank(((setweight(to_tsvector(?::regconfig, i1_0.short_name), 'A')||setweight(to_tsvector(?::regconfig, i1_0.full_name), 'B'))||(setweight(to_tsvector(?::regconfig, i1_0.short_description), 'C')||setweight(to_tsvector(?::regconfig, i1_0.full_description), 'D'))), websearch_to_tsquery('english', ?)) +``` + +Example: Ranking using ts_rank_cd + +To use the cover density ranking method, replace the ranking function name with ts_rank_cd: + +```java +public List findItemsByWebSearchToTSQuerySortedByTsRankCd(String phrase, boolean ascSort) { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Item.class); + Root root = cq.from(Item.class); + + // Build weighted tsvector using posjsonhelper functions + Expression shortNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("A") + ); + + Expression fullNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("B") + ); + + Expression shortDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("C") + ); + + Expression fullDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("D") + ); + + // Concatenate tsvectors (|| operator) + SqmExpression fullVector = (SqmExpression) cb.concat(cb.concat(shortNameVec, fullNameVec), cb.concat(shortDescriptionVec, fullDescriptionVec)); + + // Build tsquery + Expression queryExpr = new WebsearchToTSQueryFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, phrase); + + // WHERE clause using @@ operator + TextOperatorFunction matches = new TextOperatorFunction((NodeBuilder) cb, fullVector, new WebsearchToTSQueryFunction((NodeBuilder) cb, new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), phrase), hibernateContext); + + cq.where(matches); + + // Ranking + Expression rankExpr = cb.function( + "ts_rank_cd", Double.class, + fullVector, + queryExpr + ); + + cq.orderBy(ascSort ? cb.asc(rankExpr) : cb.desc(rankExpr)); + + return entityManager.createQuery(cq).getResultList(); + } +``` + +This query produces SQL similar to: + +```sql +select + i1_0.id, + i1_0.full_description, + i1_0.full_name, + i1_0.short_description, + i1_0.short_name + from + item i1_0 + where + ( + ( + setweight(to_tsvector(?::regconfig, i1_0.short_name), 'A')||setweight( + to_tsvector(?::regconfig, i1_0.full_name), 'B' + ) + )||( + setweight(to_tsvector(?::regconfig, i1_0.short_description), 'C')||setweight( + to_tsvector(?::regconfig, i1_0.full_description), 'D' + ) + ) + ) @@ websearch_to_tsquery(?::regconfig, ?) + order by + ts_rank_cd(((setweight(to_tsvector(?::regconfig, i1_0.short_name), 'A')||setweight(to_tsvector(?::regconfig, i1_0.full_name), 'B'))||(setweight(to_tsvector(?::regconfig, i1_0.short_description), 'C')||setweight(to_tsvector(?::regconfig, i1_0.full_description), 'D'))), websearch_to_tsquery('english', ?)) +``` + +Similar code but implemented with usage of HQL language: + +```java +public List findItemsByWebSearchToTSQuerySortedByTsRankInHQL(String phrase, boolean ascSort) { + String statement = "from Item as item where " + + "text_operator_function(" + // text_operator_function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // text_operator_function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // text_operator_function - end + " order by " + // order - start + + + "function('ts_rank', " + // ts_rank function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // ts_rank function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // ts_rank function - end + (ascSort ? " asc" : "desc"); + + TypedQuery query = entityManager.createQuery(statement.formatted(ENGLISH_CONFIGURATION), Item.class); + query.setParameter("phrase", phrase); + return query.getResultList(); + } +``` + Component has also constructor to which developer can pass [the cast operator](#cast-operator-and-text-search-configuration) ### Properties diff --git a/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/Application.java b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/Application.java index 23d0f5b3..e9d3dcb4 100644 --- a/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/Application.java +++ b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/Application.java @@ -11,6 +11,7 @@ public class Application { public static final String CLEAR_DATABASE_SCRIPT_PATH = "clean-database.sql"; public static final String TWEETS_SCRIPT_PATH = "tweets.sql"; public static final String TWEETS_WITH_LOCALE_SCRIPT_PATH = "tweets-with-locale.sql"; + public static final String ITEMS_SCRIPT_PATH = "items.sql"; public static final String TEXT_INDEX_SCRIPT_PATH = "text-index.sql"; public static final String ENGLISH_CONFIGURATION = "english"; public static final String POLISH_CONFIGURATION = "pl_ispell"; diff --git a/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDao.java b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDao.java new file mode 100644 index 00000000..358512d0 --- /dev/null +++ b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDao.java @@ -0,0 +1,230 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.dao; + +import com.github.starnowski.posjsonhelper.core.HibernateContext; +import com.github.starnowski.posjsonhelper.text.hibernate6.functions.TSVectorFunction; +import com.github.starnowski.posjsonhelper.text.hibernate6.functions.WebsearchToTSQueryFunction; +import com.github.starnowski.posjsonhelper.text.hibernate6.model.Item; +import com.github.starnowski.posjsonhelper.text.hibernate6.operators.RegconfigTypeCastOperatorFunction; +import com.github.starnowski.posjsonhelper.text.hibernate6.operators.TextOperatorFunction; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.Root; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.tree.expression.SqmExpression; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +import static com.github.starnowski.posjsonhelper.text.hibernate6.Application.ENGLISH_CONFIGURATION; + +@Repository +public class ItemDao { + + @Autowired + private EntityManager entityManager; + @Autowired + private HibernateContext hibernateContext; + + + public List findItemsByWebSearchToTSQuerySortedByTsRank(String phrase, boolean ascSort) { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Item.class); + Root root = cq.from(Item.class); + + // Build weighted tsvector using posjsonhelper functions + Expression shortNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("A") + ); + + Expression fullNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("B") + ); + + Expression shortDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("C") + ); + + Expression fullDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("D") + ); + + // Concatenate tsvectors (|| operator) + SqmExpression fullVector = (SqmExpression) cb.concat(cb.concat(shortNameVec, fullNameVec), cb.concat(shortDescriptionVec, fullDescriptionVec)); + + // Build tsquery + Expression queryExpr = new WebsearchToTSQueryFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, phrase); + + // WHERE clause using @@ operator + TextOperatorFunction matches = new TextOperatorFunction((NodeBuilder) cb, fullVector, new WebsearchToTSQueryFunction((NodeBuilder) cb, new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), phrase), hibernateContext); + + cq.where(matches); + + // Ranking + Expression rankExpr = cb.function( + "ts_rank", Double.class, + fullVector, + queryExpr + ); + + cq.orderBy(ascSort ? cb.asc(rankExpr) : cb.desc(rankExpr)); + + return entityManager.createQuery(cq).getResultList(); + } + + public List findItemsByWebSearchToTSQuerySortedByTsRankInHQL(String phrase, boolean ascSort) { + String statement = "from Item as item where " + + "text_operator_function(" + // text_operator_function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // text_operator_function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // text_operator_function - end + " order by " + // order - start + + + "function('ts_rank', " + // ts_rank function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // ts_rank function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // ts_rank function - end + (ascSort ? " asc" : "desc"); + + TypedQuery query = entityManager.createQuery(statement.formatted(ENGLISH_CONFIGURATION), Item.class); + query.setParameter("phrase", phrase); + return query.getResultList(); + } + + public List findItemsByWebSearchToTSQuerySortedByTsRankCd(String phrase, boolean ascSort) { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Item.class); + Root root = cq.from(Item.class); + + // Build weighted tsvector using posjsonhelper functions + Expression shortNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("A") + ); + + Expression fullNameVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullName"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("B") + ); + + Expression shortDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("shortDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("C") + ); + + Expression fullDescriptionVec = cb.function("setweight", String.class, + new TSVectorFunction(root.get("fullDescription"), new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), (NodeBuilder) cb), + cb.literal("D") + ); + + // Concatenate tsvectors (|| operator) + SqmExpression fullVector = (SqmExpression) cb.concat(cb.concat(shortNameVec, fullNameVec), cb.concat(shortDescriptionVec, fullDescriptionVec)); + + // Build tsquery + Expression queryExpr = new WebsearchToTSQueryFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, phrase); + + // WHERE clause using @@ operator + TextOperatorFunction matches = new TextOperatorFunction((NodeBuilder) cb, fullVector, new WebsearchToTSQueryFunction((NodeBuilder) cb, new RegconfigTypeCastOperatorFunction((NodeBuilder) cb, ENGLISH_CONFIGURATION, hibernateContext), phrase), hibernateContext); + + cq.where(matches); + + // Ranking + Expression rankExpr = cb.function( + "ts_rank_cd", Double.class, + fullVector, + queryExpr + ); + + cq.orderBy(ascSort ? cb.asc(rankExpr) : cb.desc(rankExpr)); + + return entityManager.createQuery(cq).getResultList(); + } + + public List findItemsByWebSearchToTSQuerySortedByTsRankCdInHQL(String phrase, boolean ascSort) { + String statement = "from Item as item where " + + "text_operator_function(" + // text_operator_function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // text_operator_function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // text_operator_function - end + " order by " + // order - start + + + "function('ts_rank_cd', " + // ts_rank function - start + "concat(" + // main concat - start + "concat(" + // first concat - start + "function('setweight', to_tsvector('%1$s', item.shortName), 'A')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullName), 'B')" + + ")" + // first concat - end + "," + // main concat - separator + "concat(" + // second concat - start + "function('setweight', to_tsvector('%1$s', item.shortDescription), 'C')" + + "," + + "function('setweight', to_tsvector('%1$s', item.fullDescription), 'D')" + + ")" + // first second - end + ")" + // main concat - end + "," + // ts_rank function - separator + + "websearch_to_tsquery(cast_operator_function('%1$s','regconfig'), :phrase)" + // websearch_to_tsquery operator + + ")" + // ts_rank function - end + (ascSort ? " asc" : "desc"); + + TypedQuery query = entityManager.createQuery(statement.formatted(ENGLISH_CONFIGURATION), Item.class); + query.setParameter("phrase", phrase); + return query.getResultList(); + } +} diff --git a/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDaoTest.java b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDaoTest.java new file mode 100644 index 00000000..f15aec52 --- /dev/null +++ b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/dao/ItemDaoTest.java @@ -0,0 +1,125 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.dao; + +import com.github.starnowski.posjsonhelper.text.hibernate6.model.Item; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; + +import java.util.List; +import java.util.stream.Stream; + +import static com.github.starnowski.posjsonhelper.text.hibernate6.Application.CLEAR_DATABASE_SCRIPT_PATH; +import static com.github.starnowski.posjsonhelper.text.hibernate6.Application.ITEMS_SCRIPT_PATH; +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlConfig.TransactionMode.ISOLATED; + +class ItemDaoTest extends AbstractItTest { + + @Autowired + private ItemDao itemDao; + + + private static Stream provideShouldFindCorrectItemWithOrderBasedOnPhrase() { + return Stream.of( + Arguments.of("wing", true, asList(1L, 2L)), + Arguments.of("wing", false, asList(2L, 1L)) + ); + } + + //TODO +// private static Stream provideShouldFindCorrectItemWithOrderBasedOnPhraseWithWeights() { +// return Stream.of( +// Arguments.of("wing", true, asList(1L, 2L), new float[]{1.0f, 0.8f, 0.4f, 0.2f}), +// Arguments.of("wing", false, asList(2L, 1L), new float[]{1.0f, 0.8f, 0.4f, 0.2f}) +// ); +// } + + + @Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, ITEMS_SCRIPT_PATH}, + config = @SqlConfig(transactionMode = ISOLATED), + executionPhase = BEFORE_TEST_METHOD) + @DisplayName("should find correct item with order based on phrase") + @ParameterizedTest + @MethodSource("provideShouldFindCorrectItemWithOrderBasedOnPhrase") + public void shouldFindCorrectItemWithOrderBasedOnPhraseRankedByTsRank(String phrase, boolean ascSort, List expectedIds) { + assumeTrue(postgresVersion.getMajor() >= 11, "Test ignored because the 'websearch_to_tsquery' function was added in version 10 of Postgres"); + + // WHEN + List items = itemDao.findItemsByWebSearchToTSQuerySortedByTsRank(phrase, ascSort); + + // THEN + assertEquals(expectedIds, items.stream().map(Item::getId).toList()); + } + + @Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, ITEMS_SCRIPT_PATH}, + config = @SqlConfig(transactionMode = ISOLATED), + executionPhase = BEFORE_TEST_METHOD) + @DisplayName("should find correct item with order based on phrase") + @ParameterizedTest + @MethodSource("provideShouldFindCorrectItemWithOrderBasedOnPhrase") + public void shouldFindCorrectItemWithOrderBasedOnPhraseRankedByTsRankInHQL(String phrase, boolean ascSort, List expectedIds) { + assumeTrue(postgresVersion.getMajor() >= 11, "Test ignored because the 'websearch_to_tsquery' function was added in version 10 of Postgres"); + + // WHEN + List items = itemDao.findItemsByWebSearchToTSQuerySortedByTsRankInHQL(phrase, ascSort); + + // THEN + assertEquals(expectedIds, items.stream().map(Item::getId).toList()); + } + + @Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, ITEMS_SCRIPT_PATH}, + config = @SqlConfig(transactionMode = ISOLATED), + executionPhase = BEFORE_TEST_METHOD) + @DisplayName("should find correct item with order based on phrase") + @ParameterizedTest + @MethodSource("provideShouldFindCorrectItemWithOrderBasedOnPhrase") + public void shouldFindCorrectItemWithOrderBasedOnPhraseRankedByTsRankCd(String phrase, boolean ascSort, List expectedIds) { + assumeTrue(postgresVersion.getMajor() >= 11, "Test ignored because the 'websearch_to_tsquery' function was added in version 10 of Postgres"); + + // WHEN + List items = itemDao.findItemsByWebSearchToTSQuerySortedByTsRankCd(phrase, ascSort); + + // THEN + assertEquals(expectedIds, items.stream().map(Item::getId).toList()); + } + + @Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, ITEMS_SCRIPT_PATH}, + config = @SqlConfig(transactionMode = ISOLATED), + executionPhase = BEFORE_TEST_METHOD) + @DisplayName("should find correct item with order based on phrase") + @ParameterizedTest + @MethodSource("provideShouldFindCorrectItemWithOrderBasedOnPhrase") + public void shouldFindCorrectItemWithOrderBasedOnPhraseRankedByTsRankCdInHQL(String phrase, boolean ascSort, List expectedIds) { + assumeTrue(postgresVersion.getMajor() >= 11, "Test ignored because the 'websearch_to_tsquery' function was added in version 10 of Postgres"); + + // WHEN + List items = itemDao.findItemsByWebSearchToTSQuerySortedByTsRankCdInHQL(phrase, ascSort); + + // THEN + assertEquals(expectedIds, items.stream().map(Item::getId).toList()); + } + + // TODO +// @Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, ITEMS_SCRIPT_PATH}, +// config = @SqlConfig(transactionMode = ISOLATED), +// executionPhase = BEFORE_TEST_METHOD) +// @DisplayName("should find correct item with order based on phrase and custom weights") +// @ParameterizedTest +// @MethodSource("provideShouldFindCorrectItemWithOrderBasedOnPhraseWithWeights") +// public void shouldFindCorrectItemWithOrderBasedOnPhraseRankedByTsRankWithCustomWeights(String phrase, boolean ascSort, List expectedIds, float[] weights) { +// assumeTrue(postgresVersion.getMajor() >= 11, "Test ignored because the 'websearch_to_tsquery' function was added in version 10 of Postgres"); +// +// // WHEN +// List items = itemDao.findItemsByWebSearchToTSQuerySortedByTsRankWithCustomW(phrase, ascSort, weights); +// +// // THEN +// assertEquals(expectedIds, items.stream().map(Item::getId).toList()); +// } +} \ No newline at end of file diff --git a/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/model/Item.java b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/model/Item.java new file mode 100644 index 00000000..488254d9 --- /dev/null +++ b/text/hibernate6-text-tests/src/test/java/com/github/starnowski/posjsonhelper/text/hibernate6/model/Item.java @@ -0,0 +1,62 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name = "item") +public class Item { + + @Id + private Long id; + @Column(name = "short_name", length = 75) + private String shortName; + @Column(name = "full_name", length = 150) + private String fullName; + @Column(name = "short_description", length = 255) + private String shortDescription; + @Column(name = "full_description", length = 1024) + private String fullDescription; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getShortName() { + return shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public String getShortDescription() { + return shortDescription; + } + + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; + } + + public String getFullDescription() { + return fullDescription; + } + + public void setFullDescription(String fullDescription) { + this.fullDescription = fullDescription; + } +} diff --git a/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/clean-database.sql b/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/clean-database.sql index 0e5e2582..c664ce94 100644 --- a/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/clean-database.sql +++ b/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/clean-database.sql @@ -1,2 +1,3 @@ TRUNCATE tweet CASCADE; -TRUNCATE tweet_with_locale CASCADE; \ No newline at end of file +TRUNCATE tweet_with_locale CASCADE; +TRUNCATE item CASCADE; \ No newline at end of file diff --git a/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/items.sql b/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/items.sql new file mode 100644 index 00000000..e01e3188 --- /dev/null +++ b/text/hibernate6-text-tests/src/test/resources/com/github/starnowski/posjsonhelper/text/hibernate6/dao/items.sql @@ -0,0 +1,21 @@ +INSERT INTO item (id, short_name, full_name, full_description, short_description) +VALUES + ( + 1, + 'XDeep Stealth 2.0 TEC Setup', + 'XDeep Stealth 2.0 TEC Setup Sidemount BCD System', + 'The STEALTH 2.0 TEC was designed to excel in deep decompression diving and in extended cave penetrations. It provides 19 kg of lift, supports multiple cylinders, and features a centred dump valve so you can release gas with either hand while maintaining trim. The harness uses multi-thickness webbing, modular weight placement up to 25 kg, and a streamlined wing fixed to the harness for stability. Optional RB (redundant bladder) version includes dual wings in one slim package. The system includes the STEALTH 2.0 harness, modular central weight pocket, and BCD wing mounted to the harness. (Dry weight: ~2.8 kg)', + 'STEALTH 2.0 sidemount BCD system with 19 kg lift, modular weight, and integrated wing.' + ); +INSERT INTO item (id, short_name, full_name, full_description, short_description) +VALUES + ( + 2, + 'XDeep ZEOS 28 Deluxe', + 'XDeep ZEOS 28 Deluxe Aluminium Backplate M Weight Pockets Wing', + 'The ZEOS 28 Deluxe system from XDeep is a high-performance single-tank wing / backplate setup, offering 13 kg (28 lb) lift, modular weight pockets (0 to ~16 kg), and durable materials (Cordura 1100dTEX outer shell, nylon/TPU inner bladder). The aluminium backplate option yields lower weight for travel use, while the 3D mesh padding on harness and backplate enhances comfort and stability. The wing is a double-shell toroidal (“donut”) style providing balanced trim and buoyancy control, and the modular system allows flexible weight distribution for warm or cold water use. The harness features ITW Nexus QR buckles, and the system is adjustable to diverse body shapes. (Dry BCD weight ~1.05 kg; full set without weight pockets ~3.5 kg) ', + 'Single-tank wing/backplate system (13 kg lift) with aluminium backplate, modular weight pockets, and 3D mesh harness for comfort.' + ); + + + diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor.java index c319c3d5..c2f868b9 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TSVectorFunctionDescriptor.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TSVectorFunctionDescriptor.java index 87d469f4..4a237d4a 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TSVectorFunctionDescriptor.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TSVectorFunctionDescriptor.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TextOperatorFunctionDescriptor.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TextOperatorFunctionDescriptor.java index 9bd73f9c..14873715 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TextOperatorFunctionDescriptor.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/TextOperatorFunctionDescriptor.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 @@ -40,7 +40,7 @@ /** * Function descriptor for text postgres operator. - * Generally it renders passed arguments that one is TSVectorFunction object type and second is expression that represents text query. + * Generally it renders passed arguments that one is SqmExpression object type and second is expression that represents text query. * For example: * SQL *

{@code
@@ -73,6 +73,6 @@ protected  SelfRenderingSqmFunction generateSqmFunctionExpression(List) arguments.get(i));
         }
-        return (SelfRenderingSqmFunction) new TextOperatorFunction(queryEngine.getCriteriaBuilder(), (TSVectorFunction) args.get(0), args.get(1), hibernateContext);
+        return (SelfRenderingSqmFunction) new TextOperatorFunction(queryEngine.getCriteriaBuilder(),  args.get(0), args.get(1), hibernateContext);
     }
 }
\ No newline at end of file
diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/AbstractFunctionWithConfigurationAndTextQueryFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/AbstractFunctionWithConfigurationAndTextQueryFunction.java
index f63009ac..95a340d6 100644
--- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/AbstractFunctionWithConfigurationAndTextQueryFunction.java
+++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/AbstractFunctionWithConfigurationAndTextQueryFunction.java
@@ -1,19 +1,19 @@
 /**
  * Posjsonhelper library is an open-source project that adds support of
  * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html)
- * 

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 @@ -40,15 +40,15 @@ *

{@code
  * {{main_func}}( :configuration, :text_query)
  * }
- *

- *

+ * + * * Without configuration argument: * *

{@code
  * {{main_func}}( :text_query)
  * }
- *

- *

+ * + * * where: * {{main_func}} - name of main function returned by method {@link #getFunctionName()} * :configuration - text search configuration diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PhraseToTSQueryFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PhraseToTSQueryFunction.java index b2b4afa5..71c29765 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PhraseToTSQueryFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PhraseToTSQueryFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PlainToTSQueryFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PlainToTSQueryFunction.java index e6915565..73c52d45 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PlainToTSQueryFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/PlainToTSQueryFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/TSVectorFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/TSVectorFunction.java index 442ea193..af2f5d7d 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/TSVectorFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/TSVectorFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/WebsearchToTSQueryFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/WebsearchToTSQueryFunction.java index 0688b844..94165c0b 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/WebsearchToTSQueryFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/functions/WebsearchToTSQueryFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/RegconfigTypeCastOperatorFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/RegconfigTypeCastOperatorFunction.java index a9351344..57d4e932 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/RegconfigTypeCastOperatorFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/RegconfigTypeCastOperatorFunction.java @@ -1,19 +1,19 @@ /** * Posjsonhelper library is an open-source project that adds support of * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - *

+ * * Copyright (C) 2023 Szymon Tarnowski - *

+ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - *

+ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/TextOperatorFunction.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/TextOperatorFunction.java index 7182c0f6..697ad156 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/TextOperatorFunction.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/operators/TextOperatorFunction.java @@ -1,28 +1,27 @@ /** - * Posjsonhelper library is an open-source project that adds support of - * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) - * - * Copyright (C) 2023 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA + * Posjsonhelper library is an open-source project that adds support of + * Hibernate query for https://www.postgresql.org/docs/10/functions-json.html) + *

+ * Copyright (C) 2023 Szymon Tarnowski + *

+ * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + *

+ * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + *

+ * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA */ package com.github.starnowski.posjsonhelper.text.hibernate6.operators; import com.github.starnowski.posjsonhelper.core.HibernateContext; -import com.github.starnowski.posjsonhelper.text.hibernate6.functions.TSVectorFunction; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.function.FunctionRenderer; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; @@ -44,16 +43,16 @@ public class TextOperatorFunction extends SelfRenderingSqmFunction implements Serializable { private final HibernateContext context; - private final TSVectorFunction tsVectorFunction; + private final SqmExpression tsVectorFunction; private final SqmExpression argument; /** - * @param nodeBuilder component of type {@link NodeBuilder} - * @param tsVectorFunction object of type {@link TSVectorFunction} - * @param argument text query expression + * @param nodeBuilder component of type {@link NodeBuilder} + * @param tsVectorFunction object of type {@link SqmExpression} + * @param argument text query expression * @param hibernateContext context object of type {@link HibernateContext} */ - public TextOperatorFunction(NodeBuilder nodeBuilder, TSVectorFunction tsVectorFunction, SqmExpression argument, HibernateContext hibernateContext) { + public TextOperatorFunction(NodeBuilder nodeBuilder, SqmExpression tsVectorFunction, SqmExpression argument, HibernateContext hibernateContext) { super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getTextFunctionOperator()), (FunctionRenderer) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getTextFunctionOperator()), contactParameters(tsVectorFunction, argument), @@ -67,7 +66,8 @@ public TextOperatorFunction(NodeBuilder nodeBuilder, TSVectorFunction tsVectorFu this.argument = argument; } - private static List> contactParameters(TSVectorFunction tsVectorFunction, SqmExpression argument) { + private static List> contactParameters(SqmExpression tsVectorFunction, + SqmExpression argument) { if (tsVectorFunction == null) { throw new IllegalArgumentException("TSVectorFunction argument can not be null"); }