How to postgres search with two search text parameter, Search FIlter text 1 && search filter text 2

StackOverflow https://stackoverflow.com/questions/9991421

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")
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top