From 8ef258618065028d2639e0401008cd63335161bd Mon Sep 17 00:00:00 2001 From: tuminglei Date: Sun, 17 Apr 2022 20:23:47 +0800 Subject: [PATCH] merge #551's changes, jump to v0.20.3 --- README.md | 20 +++++++++---------- build.sbt | 2 +- .../slickpg/search/PgSearchExtensions.scala | 3 +++ .../github/tminglei/slickpg/search/README.md | 3 ++- .../slickpg/PgSearchSupportSuite.scala | 14 +++++++++---- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c5c6c70b..eab61d80 100644 --- a/README.md +++ b/README.md @@ -194,44 +194,44 @@ Install ------- To use `slick-pg` in [sbt](http://www.scala-sbt.org/ "slick-sbt") project, add the following to your project file: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg" % "0.20.3" ``` > If you need `joda-time` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_joda-time" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_joda-time" % "0.20.3" ``` > If you need `jts` geom support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_jts" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_jts" % "0.20.3" or -libraryDependencies += "com.github.tminglei" %% "slick-pg_jts_lt" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_jts_lt" % "0.20.3" ``` > If you need `json4s` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_json4s" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_json4s" % "0.20.3" ``` > If you need `play-json` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_play-json" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_play-json" % "0.20.3" ``` > If you need `spray-json` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_spray-json" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_spray-json" % "0.20.3" ``` > If you need `argonaut json` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_argonaut" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_argonaut" % "0.20.3" ``` > If you need `circe json` support, pls append dependency: ```scala -libraryDependencies += "com.github.tminglei" %% "slick-pg_circe-json" % "0.20.2" +libraryDependencies += "com.github.tminglei" %% "slick-pg_circe-json" % "0.20.3" ``` @@ -240,7 +240,7 @@ Or, in [maven](http://maven.apache.org/ "maven") project, you can add `slick-pg` com.github.tminglei slick-pg_2.12 - 0.20.2 + 0.20.3 ... diff --git a/build.sbt b/build.sbt index 49523489..8e2ce731 100644 --- a/build.sbt +++ b/build.sbt @@ -6,7 +6,7 @@ lazy val commonSettings = Seq( organizationName := "slick-pg", organization := "com.github.tminglei", name := "slick-pg", - version := "0.20.2", + version := "0.20.3", scalaVersion := scala213, crossScalaVersions := Seq(scala213, scala212, scala211), diff --git a/core/src/main/scala/com/github/tminglei/slickpg/search/PgSearchExtensions.scala b/core/src/main/scala/com/github/tminglei/slickpg/search/PgSearchExtensions.scala index 1b7e8eb4..066c7113 100644 --- a/core/src/main/scala/com/github/tminglei/slickpg/search/PgSearchExtensions.scala +++ b/core/src/main/scala/com/github/tminglei/slickpg/search/PgSearchExtensions.scala @@ -92,6 +92,7 @@ trait PgSearchExtensions extends JdbcTypesComponent { driver: PostgresProfile => val Or = new SqlOperator("||") val Negate = new SqlOperator("!!") val Contains = new SqlOperator("@>") + val Phrase = new SqlOperator("<->") val GetCurrTsConfig = new SqlFunction("get_current_ts_config") val ToTsQuery = new SqlFunction("to_tsquery") @@ -138,6 +139,8 @@ trait PgSearchExtensions extends JdbcTypesComponent { driver: PostgresProfile => def !! = SearchLibrary.Negate.column[TQ](c.toNode) def @>[P2, R](e: Rep[P2])(implicit om: o#arg[TQ, P2]#to[Boolean, R]) = om.column(SearchLibrary.Contains, c.toNode, e.toNode) + def <->[P2, R](e: Rep[P2])(implicit om: o#arg[TQ, P2]#to[TQ, R]) = + om.column(SearchLibrary.Phrase, c.toNode, e.toNode) def numNode = SearchLibrary.NumNode.column[Int](c.toNode) def queryTree = SearchLibrary.QueryTree.column[String](c.toNode) diff --git a/core/src/main/scala/com/github/tminglei/slickpg/search/README.md b/core/src/main/scala/com/github/tminglei/slickpg/search/README.md index 7aec0720..a36487cd 100644 --- a/core/src/main/scala/com/github/tminglei/slickpg/search/README.md +++ b/core/src/main/scala/com/github/tminglei/slickpg/search/README.md @@ -2,12 +2,13 @@ Supported Search Oper/Functions ------------------------------- | Slick Oper/Function | PG Oper/Function | Description | Example | Result | -| ------------------- | ---------------- | -------------------------------- | -------------------------------------- | ----------- | +|---------------------|------------------| -------------------------------- | -------------------------------------- | ----------- | | tsQuery | to_tsquery | normalize words and convert to tsquery | to_tsquery('english', 'The & Fat & Rats') | 'fat' & 'rat' | | tsVector | to_tsvector | reduce document text to tsvector | to_tsvector('english', 'The Fat Rats') | 'fat':2 'rat':3 | | @@ | @@ | tsvector matches tsquery ? | to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat') | t | | @+ | || | concatenate tsvectors | 'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector | 'a':1 'b':2,5 'c':3 'd':4 | | @& | && | AND tsquerys together | 'fat | rat'::tsquery && 'cat'::tsquery | ( 'fat' | 'rat' ) & 'cat' | +| <-> | <-> | Constructs a phrase query, which matches if the two input queries match at successive lexemes. | to_tsquery('fat') <-> to_tsquery('rat') | 'fat' <-> 'rat' | | @| | || | OR tsquerys together | 'fat | rat'::tsquery || 'cat'::tsquery | ( 'fat' | 'rat' ) | 'cat' | | !! | !! | negate a tsquery | !! 'cat'::tsquery | !'cat' | | @> | @> | tsquery contains another ? | 'cat'::tsquery @> 'cat & rat'::tsquery | f | diff --git a/src/test/scala/com/github/tminglei/slickpg/PgSearchSupportSuite.scala b/src/test/scala/com/github/tminglei/slickpg/PgSearchSupportSuite.scala index 01ff97f1..e393e696 100644 --- a/src/test/scala/com/github/tminglei/slickpg/PgSearchSupportSuite.scala +++ b/src/test/scala/com/github/tminglei/slickpg/PgSearchSupportSuite.scala @@ -27,13 +27,15 @@ class PgSearchSupportSuite extends AnyFunSuite with PostgresContainer { val testRec1 = TestBean(33L, "fat cat ate rat", TsVector("'ate' 'cat' 'fat' 'rat'"), "") val testRec2 = TestBean(37L, "cat", TsVector("'ca'"), "fat") + val testRec3 = TestBean(38L, "mike rose", TsVector("'mike' 'rose'"), "") + val testRec4 = TestBean(39L, "mike and rose", TsVector("'mike' 'and' 'rose'"), "") test("Text search Lifted support") { Await.result(db.run( DBIO.seq( Tests.schema create, /// - Tests forceInsertAll List(testRec1, testRec2) + Tests forceInsertAll List(testRec1, testRec2, testRec3, testRec4) ).andThen( DBIO.seq( // get_current_ts_config @@ -62,13 +64,17 @@ class PgSearchSupportSuite extends AnyFunSuite with PostgresContainer { ), // @> Tests.filter(r => plainToTsQuery(r.text, Some("english")) @> toTsQuery(r.comment, Some("english"))).sortBy(_.id).to[List].result.map( - r => assert(List(testRec1) === r) + r => assert(List(testRec1, testRec3, testRec4).map(_.id) === r.map(_.id)) ), Tests.filter(r => phraseToTsQuery(r.text, Some("english")) @> toTsQuery(r.comment, Some("english"))).sortBy(_.id).to[List].result.map( - r => assert(List(testRec1) === r) + r => assert(List(testRec1, testRec3, testRec4).map(_.id) === r.map(_.id)) ), Tests.filter(r => webSearchToTsQuery(r.text, Some("english")) @> toTsQuery(r.comment, Some("english"))).sortBy(_.id).to[List].result.map( - r => assert(List(testRec1) === r) + r => assert(List(testRec1, testRec3, testRec4).map(_.id) === r.map(_.id)) + ), + // <-> + Tests.filter(r => toTsVector(r.text, Some("english")) @@ (tsQuery("mike".bind) <-> tsQuery("rose".bind))).sortBy(_.id).to[List].result.map( + r => assert(List(testRec3) === r) ), // length Tests.filter(_.id === 33L).map(r => toTsVector(r.text).length).result.head.map(