Question

How to Postgres search with two search text parameter , pg-search + Search FIlter 1 + search filter 2 .

How to search in pg_Search output I want union of "filter 1" && "filter 1"

 @output = PgSearch.multisearch("filter 1") +  PgSearch.multisearch("filter 2")
Was it helpful?

Solution

I'm the author and maintainer of pg_search.

Search terms are joined by AND by default in PostgreSQL full text search. Thus, you could simply do this:

 @output = PgSearch.multisearch("filter 1 filter 2")

Assuming you have the query terms in string variables, it would look something like one of these:

 @output = PgSearch.multisearch("#{query1} #{query2}") # if query1 and query2 are strings
 @output = PgSearch.multisearch(queries.join(" "))     # if queries is an array of strings

Joining by OR is a lot more complicated. I don't yet have an easy solution for it, although it should be possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top