From 0ac1b1cf46c4565c9c904907df1cbb8222ac043f Mon Sep 17 00:00:00 2001 From: zell Date: Thu, 16 Aug 2007 16:54:52 +0000 Subject: [PATCH] We have to carefully convert the user's query input to the boolean lexeme language TO_TSQUERY() expects. We may ultimately have to do more complicated things here, too. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2191 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/jdbc/depot/PostgreSQLBuilder.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java b/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java index 26745f22..99899fa8 100644 --- a/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java +++ b/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java @@ -49,6 +49,7 @@ import com.samskivert.jdbc.depot.FieldMarshaller.ObjectMarshaller; import com.samskivert.jdbc.depot.FieldMarshaller.ShortMarshaller; import com.samskivert.jdbc.depot.annotation.FullTextIndex; import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch; +import com.samskivert.util.StringUtil; import com.samskivert.Log; @@ -97,7 +98,15 @@ public class PostgreSQLBuilder public void visit (FullTextMatch match) throws Exception { - _stmt.setString(_argIdx ++, match.getQuery()); + // The tsearch2 engine takes queries on the form + // (foo&bar)|goop + // so in this first simple implementation, we just take the user query, chop it into + // words by space/punctuation and 'or' those together like so: + // 'ho! who goes there?' -> 'ho|who|goes|there' + + String[] searchTerms = match.getQuery().toLowerCase().split("\\W+"); + String query = StringUtil.join(searchTerms, "|"); + _stmt.setString(_argIdx ++, query); } protected PGBindVisitor (DepotTypes types, PreparedStatement stmt)