Lingua::Thesaurus::Storage::SQLite - Thesaurus storage in an SQLite database


This class implements the Lingua::Thesaurus::Storage role, by storing thesaurus data in a DBD::SQLite database.



  my $storage = Lingua::Thesaurus::Storage::SQLite->new($dbname);
  my $storage = Lingua::Thesaurus::Storage::SQLite->new(%args);

If new() has only one scalar argument, this is interpreted as new(dbname => $arg). Otherwise, parameters should be passed as a hash or hashref, with the following options :


Filename for storing the DBD::SQLite database. This could also be :memory: for an in-memory database.


Optional handle to an already connected database (in that case, the dbname parameter will not be used).


Hashref of key-value pairs that will be stored into the database, and can be retrieved by other processes using the thesaurus. This package interprets the following keys :


If true, the term table will use SQLite's fulltext functionalities. This means that $thesaurus->search_terms('sci*') will also retrieve 'computer science'; you can also issue boolean queries like 'sci* AND NOT comp*'.

If true, the term table is just a regular SQLite table, and queries will be interpreted through SQLite's 'LIKE' operator.


This parameter only makes sense together with use_fulltext. It will activate "unaccent" in Search::Tokenizer, so that a query for thésaurus will also find thesaurus, or vice-versa.


Name of the class for instanciating terms. Default is Lingua::Thesaurus::Term.


Name of the class for instanciating "relation types". Default is Lingua::Thesaurus::RelType.

Retrieval methods

See "Retrieval methods" in Lingua::Thesaurus::Storage

Populating the database

See "Populating the database" in Lingua::Thesaurus::Storage for the API.

Below are some particular notes about the SQLite implementation.


This method just performs begin_work .. commit, because inserts into an SQLite database are much faster under a transaction. No support for rollbacks is programmed, because in this context there is no need for it.


If use_fulltext is false, terms are stored in a regular table with a UNIQUE constraint, so it is not possible to store the same term string twice.

If use_fulltext is true, no constraint is enforced.