Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fulltext search with ORM methods?
  • Are there any methods / method configurations which would allow an Orm\Model to perform a fulltext 'MATCH .. AGAINST', or is the 'DB' class the best option?

    Cheers,

    Paul 
  • I have never tried it, but you can probably code up the where clause using DB::expr(), in which case it will work both with DB and ORM.
  • I'll give this a shot once I get home and report back. Thanks Harro.
  • Hi, did you eventually find a solution ?

    I did not succeed with DB:expr() in the 'where' property.
  • What did you exactly try?

    ->where(\DB::expr('SOME SQL HERE'))->

    should work without problems.

    The encapsulation is just that the SQL compiler doesn't see the sql as a literal, and tried to escape and quote it.
  • Thanks. Actually I misunderstood the use of Database_Expression objects. I was trying to use it directly in the where clause of the find() method in ORM Model.

    I tried to call directly the where() method on a Query object. It's work a lot better, except that the compiled SQL query contains a syntax error and looks like :

    ... MATCH (`column`)  AGAINST ('search') null;

    The "null" at the end make the query fail.

    I tried to pass an empty string as the value parameter like the following :

    $query->where( \DB::expr('MATCH (`column`) AGAINST ('search'), '' );

    but it produce the following SQL :

    ... MATCH (`column`)  AGAINST ('search') = '';

    wich is syntaxically correct but fail to get the desired elements.

    So at last I directly edited the query class (I will next overload it in my own class) to add line 130 :

    if( $column instanceof \Fuel\Core\Database_Expression )
    {
    $sql .= $db->quote_identifier( $column );
    }
    else
    {
    $sql .= $db->quote_identifier($column).' '.$op.' '. $value;
    }

    That works fine.

    So, I'm a little bit suprised to have to edit the core class to make it work. I suppose that I missed something somewhere but what ?

    If you have an idea, please tell me.
  • What exactly are you looking at, and how old is your code?

    Support for DB::expr() in where() clauses has been added 5 months ago, on August 1st 2013: https://github.com/fuel/core/commit/995311e5fbe95c7c8bed3f2f2d31794ed8c12543
  • That's it, my code seems to old because it does not contains this commit.

    I will upgrade the version of Fuel or at least this class.

    Thank you very much for the help !
  • I think a partial upgrade is a bad idea, but if you insist, update the entire fuel/classes/database folder, changes are often done in multiple files. You don't want to run into other issues.
  • The project I am working on was running on the FuelPHP 1.6. The upgrade to 1.7.1 worked fine and I am now able to easily make fulltext searches.

    Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion