4523: slightly modified full text search condition.
authorRadhika Chippada <radhika@curoverse.com>
Fri, 6 Feb 2015 21:15:23 +0000 (16:15 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Fri, 6 Feb 2015 21:15:23 +0000 (16:15 -0500)
services/api/lib/record_filters.rb

index b8cdef0b73b52dd0de1792437da1ff98bee28c9c..51153fe081267162139a3ec0dbadbe49bfd1b1eb 100644 (file)
@@ -42,8 +42,12 @@ module RecordFilters
           raise ArgumentError.new("Full text search on individual columns is not supported")
         end
         attrs = [] #  skip the generic per-column operator loop below
+        # Use to_tsquery since plainto_tsquery does not support prefix search.
+        # Instead split operand and join the words with ' & ' and add ':*' to the last word
+        # Thus when searched for "some str", objects containing "some" and "str:*" are found.
         cond_out << model_class.full_text_tsvector+" @@ to_tsquery(?)"
-        param_out << operand.split.each {|s| s.concat(':*')}.join(' & ')
+        operand << ':*'
+        param_out << operand.split.join(' & ')
       else
        attrs.each do |attr|
         if !model_class.searchable_columns(operator).index attr.to_s