Search code examples
ruby-on-railspostgresqlsearchpg-search

pass array to PgSearch.multisearch


I am going to try using using PgSearch.multisearch in my app.

Is there a way to pass an array to PgSearch.multisearch() method?

search = PgSearch.multisearch('test1')

returns a record

search = PgSearch.multisearch(['test1', 'test2'])

returns empty array


Solution

  • Search terms are separated by a space. This will search for results that match test1 and test2:

    search = PgSearch.multisearch(['test1', 'test2'].join(" "))
    

    To use an OR condition, you can initialize the multisearch:

    PgSearch.multisearch_options = { using: { tsearch: { any_word: true }}}
    search = PgSearch.multisearch(['test1', 'test2'].join(" "))