Class SqlSearchEngine

java.lang.Object
com.codename1.backend.search.SqlSearchEngine
All Implemented Interfaces:
SearchEngine, Closeable, AutoCloseable

public final class SqlSearchEngine extends Object implements SearchEngine

Full-text search in the application's own SQL database, for a project that does not run a search cluster.

Documents go into one table, cn1_search_documents, created when the engine opens, with every string of a document joined into a body column:

  • PostgreSQL matches with websearch_to_tsquery('simple', ...) over a GIN index and ranks with ts_rank. The simple configuration lowercases but does not stem, so "shoe" does not find "shoes"; it is the one configuration that behaves the same for every language.
  • MySQL and MariaDB match every word with a FULLTEXT index in boolean mode. InnoDB does not index words shorter than innodb_ft_min_token_size (3) or its default stop words, so those are matched as whole words in memory over what the index found.
  • SQLite narrows with LIKE, one condition per word, then requires each word as a whole word, and scores by how often the words occur. Correct, and linear in the size of the index.

Matching, as on a search cluster, requires every word. Filters, field restrictions, sorting, facets and paging are then applied in memory over at most MAX_CANDIDATES matches; past that SearchResult.isTotalExact() is false, and a filter or a sort sees only those candidates (the best scored, or the first by id for an empty query), so a selective filter over a larger index belongs in a search cluster. Highlights are not produced.