We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Best way to Search in all Cloumns?

always i use this following code in mysql :

SELECT * FROM myobject 
WHERE MATCH(`name`, `foo`, `bar`) AGAINST ('$search') IN BOOLEAN MODE

in phalcon ORM :

 myobject::find([
            "columns” => "id, name”,
            "conditions" => "name LIKE ?1 OR foo LIKE ?1 OR bar LIKE ?1 ",
            "bind"       => [1 =>$search]
            ]);

How to find through all cloumns?

is this possible in phalcon ORM in a Quick way?

Thanks:)

Hey, there is no such built in solution since Phalcon aims for top performance. However there is a nice solution from the community: https://github.com/stanislav-web/Searcher

Note: I haven't used it, but looked through source files and it looks promising.

Also here is a nice list of Phalcon goodies: https://github.com/sergeyklay/awesome-phalcon



12.2k

I suggest using raw SQL, Phalcon has that option:

https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql

Therefore you can create a function in your model which utilizes the above Phalcon\Mvc\Model\Resultset\Simple

My solution:

getCloumnMap->

foreach->

create query->

CONCAT(cloumn,cloumn2,....) LIKE '%param%'

And Excute it!

Not problem! Just i searching for best way...

Well if you using for example metadata cache or annotations metadata then your solution perhaps gonna be faster than raw query bot not sure about it.