Search code examples
androidkotlinandroid-sqliteandroid-room

FTS4 matchinfo not working with android room database


I've two columns (name and description) in FTS virtual table and I want to prioritize the name column in FTS using matchinfo function, but with room in android I'm getting following error:

Error retrieving data from table.: unable to use function matchinfo in the requested context (code 1 SQLITE_ERROR)

Here is my Query:

@Query("""select workout_cache.id, workout_cache.met, workout_cache.name, workout_cache.workoutDescription, matchinfo(workout_cache_fts, 'pcs') as mi
from workout_cache join workout_cache_fts on workout_cache.id = workout_cache_fts.id 
where workout_cache_fts match :text group by workout_cache.id""")
abstract suspend fun query(text: String): List<WorkoutCacheEntityWithMatchInfo>

My WorkoutCacheEntityWithMatchInfo class

class WorkoutCacheEntityWithMatchInfo(
    @Embedded
    val workout: WorkoutCacheEntity,
    @ColumnInfo(name = "mi")
    val matchInfo: ByteArray
)

UPDATE: It's working fine when I don't use join clause.


Solution

  • It's silly. I just removed the group by clause and it worked.

    Here updated Dao:

    @Query("""select workout_cache.id, workout_cache.met, workout_cache.name, workout_cache.workoutDescription, matchinfo(workout_cache_fts, 'pcs') as mi
    from workout_cache join workout_cache_fts on workout_cache.id = workout_cache_fts.id 
    where workout_cache_fts match :text""")
    abstract suspend fun query(text: String): List<WorkoutCacheEntityWithMatchInfo>