Search::Typesense - Perl interface to the Typesense search engine
version 0.08
my $typesense = Search::Typesense->new(
host => $host, # required
api_key => $key, # required
port => $port, # defaults to 8108
use_https => $bool, # defaults to true
);
my $results = $typesense->search(
$collection_name,
{ q => 'Search String' },
);
if ( $results->{found} ) {
foreach my $hit ( @{ $results->{hits} } ) {
...;
}
}
Check here for a comparison to ElasticSearch and similar technologies.
ALPHA CODE. The interface can and will change without warning.
This is an interface to the Typesense search engine. Most methods will do one of three things:
- Return results as defined in the Typesense documentation (listed per section)
- Return nothing if Typesense returns a 404.
croak
if Typesense returns an error.
The constructor takes a list (or hashref) of key/value pairs.
my $typesense = Search::Typesense->new(
host => $host, # required
api_key => $key, # required
port => $port, # defaults to 8108
use_https => $bool, # defaults to true
);
The api key to which will be sent as the X-TYPESENSE-API-KEY
header.
The hostname to connect to.
Optional port number to connect to. Defaults to 8108 if not supplied.
Optional boolean. Whether or not to connect to Typesense over https. Default true.
For CRUD operations on collections and documents, see the documentation for
collections
(Search::Typesense::Collection) and documents
(Search::Typesense::Document).
my $collections = $typesense->collections;
my $collection = $collections->get($collection_name);
my $results = $collections->search($collection_name, {q => 'London'});
Returns an instance of Search::Typesense::Collection for managing Typesense collections.
my $results = $typesense->search($collection_name, {q => 'London'});
Shorthand that delegated to $typesense->collections->search(...)
.
We provide this on the top-level $typesense
object because this is the
common case.
my $documents = $typesense->documents;
my $document = $documents->delete($collection_name, $document_id);
Returns an instance of Search::Typesense::Document for managing Typesense documents.
$typesense->assert_is_running;
This does nothing if we can connect to Typesense. Otherwise, this method will
croak
with a message explaining the error.
my $version = $typesense->typesense_version;
Returns an instance of Search::Typesense::Version.
If your version of Typesense is older than 0.8.0
, this method will return
nothing.
Currently Typesense supports languages that use spaces as a word separator. In the future, a new tokenizer will be added to support languages such as Chinese or Japanese. I do not know the timeframe for this.
Curtis "Ovid" Poe, <ovid at allaroundtheworld.fr>
Please report any bugs or feature requests to
https://github.com/Ovid/Search-Typesense/issues
. I will be notified, and
then you'll automatically be notified of progress on your bug as I make
changes.
You can find documentation for this module with the perldoc command.
perldoc Search::Typesense
You can also look for information at:
-
Github Repo
-
Issue Tracker
-
Search CPAN
Thanks for Sebastian Reidel and Matt Trout for feedback.
This software is Copyright (c) 2021 by Curtis "Ovid" Poe.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Curtis "Ovid" Poe [email protected]
This software is copyright (c) 2021 by Curtis "Ovid" Poe.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.