Skip to content

Support FullText search #2

Description

@kasramp

Update the Book table:

ALTER TABLE book ADD FULLTEXT(title, author);

And query:

@Query(value = """
  SELECT b.id AS id,
         b.title AS title,
         b.author AS author,
         b.cover_image_url AS coverImageUrl,
         MATCH(b.title, b.author) AGAINST(:query IN NATURAL LANGUAGE MODE) AS relevance
  FROM book b
  WHERE b.provider = :provider
    AND MATCH(b.title, b.author) AGAINST(:query IN NATURAL LANGUAGE MODE)
  ORDER BY relevance DESC
  """,
  nativeQuery = true)
List<BookOverview> searchBooksByRelevance(@Param("provider") String provider,
                                          @Param("query") String query,
                                          Pageable pageable);

The drawback is that, it doesn't do partial search and is typo intolerant.

The issue with the Like %phrase% is that it doesn't use index and if the table gets too large, it becomes too slow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

improvementImprovement to an existing feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions