Skip to content

Commit

Permalink
Adjusts default behaviour of fulltext search.
Browse files Browse the repository at this point in the history
Signed-off-by: Ralph Gasser <[email protected]>
  • Loading branch information
ppanopticon committed Nov 16, 2024
1 parent 8347e6d commit e41915f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ class ScalarDescriptorReader(field: Schema.Field<*, ScalarDescriptor<*, *>>, con
* @return [Sequence] of [ScalarDescriptor]s.
*/
private fun queryFulltext(query: SimpleFulltextQuery): Sequence<ScalarDescriptor<*, *>> {
val statement = "SELECT * FROM \"$tableName\" WHERE $VALUE_ATTRIBUTE_NAME @@ plainto_tsquery(?)"
val queryString = query.value.value.split(" ").map { "$it:*" }.joinToString(" | ") { it }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ to_tsquery(?)"
return sequence {
this@ScalarDescriptorReader.connection.jdbc.prepareStatement(statement).use { stmt ->
stmt.setString(1, query.value.value)
stmt.setString(1, queryString)
stmt.executeQuery().use { result ->
while (result.next()) {
yield(rowToDescriptor(result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ class StructDescriptorReader(field: Schema.Field<*, StructDescriptor<*>>, connec
*/
private fun queryFulltext(query: SimpleFulltextQuery): Sequence<StructDescriptor<*>> {
require(query.attributeName != null) { "Query attribute must not be null for a fulltext query on a struct descriptor." }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ plainto_tsquery(?)"
val queryString = query.value.value.split(" ").map { "$it:*" }.joinToString(" | ") { it }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ to_tsquery(?)"
return sequence {
this@StructDescriptorReader.connection.jdbc.prepareStatement(statement).use { stmt ->
stmt.setString(1, query.value.value)
stmt.setString(1, queryString)
stmt.executeQuery().use { result ->
while (result.next()) {
yield(rowToDescriptor(result))
Expand Down

0 comments on commit e41915f

Please sign in to comment.