sqlitefts5

How to FTS-match from 2 different columns


I am trying to search 2 separate columns called keyword and keyword2 for a match. Can this be done with SQLite FTS?

I've tried this statement but it did not work:

String sql = "Select * from tblvHAL2001 WHERE tblvHAL2001 MATCH 'keyword:" + question + "' OR MATCH 'keyword2:" + question +"'";

Solution

  • You should use only a single FTS query per table. FTS does have boolean operators:

    ... WHERE tblvHAL2001 MATCH 'keyword: "blah" OR keyword2: "blah"'
    

    And in FTS5, a single column filter can specify multiple columns:

    ... WHERE tblvHAL2001 MATCH '{keyword keyword2}: "blah"'