libreantdb package

class libreantdb.DB(es, index_name)[source]

Bases: object

This class contains every query method and every operation on the index

The following elasticsearch body response example provides the typical structure of a single document.

{
  "_index" : "libreant",
  "_type" : "book",
  "_id" : "AU4RleAfD1zQdqx6OQ8Y",
  "_version" : 1,
  "found" : true,
  "_source": {"_language": "en",
              "_text_en": "marco belletti pdf file latex manual",
              "author": "marco belletti",
              "type": "pdf file",
              "title": "latex manual",
              "_attachments": [{"sha1": "dc8dc34b3e0fec2377e5cf9ea7e4780d87ff18c5",
                                "name": "LaTeX_Wikibook.pdf",
                                "url": "fsdb:///dc8dc34b3e0fec2377e5cf9ea7e4780d87ff18c5",
                                "notes": "A n example bookLatex wikibook",
                                "mime": "application/pdf",
                                "download_count": 7,
                                "id": "17fd3d898a834e2689340cc8aacdebb4",
                                "size": 23909451}]
             }
}
add_book(body, doc_type='book')[source]
Call it like this:
db.add_book(doc_type=’book’, body={‘title’: ‘foobar’, ‘_language’: ‘it’})
autocomplete(fieldname, start)[source]
clone_index(new_indexname, index_conf=None)[source]

Clone current index

All entries of the current index will be copied into the newly created one named new_indexname

Parameters:index_conf – Configuration to be used in the new index creation. This param will be passed directly to DB.create_index()
create_index(indexname=None, index_conf=None)[source]

Create the index

Create the index with given configuration. If indexname is provided it will be used as the new index name instead of the class one (DB.index_name)

Parameters:index_conf – configuration to be used in index creation. If this is not specified the default index configuration will be used.
Raises:Exception – if the index already exists.
delete_all()[source]

Delete all books from the index

delete_book(id)[source]
file_is_attached(url)[source]

return true if at least one book has file with the given url as attachment

get_all_books(size=30)[source]
get_book_by_id(id)[source]
get_books_by_actor(authorname)[source]
get_books_by_title(title)[source]
get_books_querystring(query, **kargs)[source]
get_books_simplequery(query)[source]
get_last_inserted(size=30)[source]
increment_download_count(id, attachmentID, doc_type='book')[source]

Increment the download counter of a specific file

iterate_all()[source]
mlt(_id)[source]

High-level method to do “more like this”.

Its exact implementation can vary.

modify_book(id, body, doc_type='book', version=None)[source]

replace the entire book body

Instead of update_book this function will overwrite the book content with param body

If param version is given, it will be checked that the changes are applied upon that document version. If the document version provided is different from the one actually found, an elasticsearch.ConflictError will be raised

properties = {'_insertion_date': {'type': 'long', 'null_value': 0}, '_language': {'index': 'false', 'type': 'text'}, '_text_en': {'type': 'text', 'analyzer': 'english'}, '_text_it': {'type': 'text', 'analyzer': 'it_analyzer'}}
reindex(new_index=None, index_conf=None)[source]

Rebuilt the current index

This function could be useful in the case you want to change some index settings/mappings and you don’t want to loose all the entries belonging to that index.

This function is built in such a way that you can continue to use the old index name, this is achieved using index aliases.

The old index will be cloned into a new one with the given index_conf. If we are working on an alias, it is redirected to the new index. Otherwise a brand new alias with the old index name is created in such a way that points to the newly create index.

Keep in mind that even if you can continue to use the same index name, the old index will be deleted.

Parameters:index_conf – Configuration to be used in the new index creation. This param will be passed directly to DB.create_index()
settings = {'analysis': {'filter': {'italian_elision': {'articles': ['c', 'l', 'all', 'dall', 'dell', 'nell', 'sull', 'coll', 'pell', 'gl', 'agl', 'dagl', 'degl', 'negl', 'sugl', 'un', 'm', 't', 's', 'v', 'd'], 'type': 'elision'}, 'italian_stop': {'stopwords': '_italian_', 'type': 'stop'}, 'italian_stemmer': {'type': 'stemmer', 'language': 'italian'}}, 'analyzer': {'it_analyzer': {'filter': ['italian_elision', 'lowercase', 'italian_stop', 'italian_stemmer'], 'type': 'custom', 'tokenizer': 'standard'}}}}
setup_db(wait_for_ready=True)[source]

Create and configure index

If wait_for_ready is True, this function will block until status for self.index_name will be yellow

update_book(id, body, doc_type='book')[source]

Update a book

The “body” is merged with the current one. Yes, it is NOT overwritten.

In case of concurrency conflict this function could raise elasticsearch.ConflictError

update_mappings()[source]

This acts like a “wrapper” that always point to the recommended function for user searching.

Submodules

class libreantdb.api.DB(es, index_name)[source]

Bases: object

This class contains every query method and every operation on the index

The following elasticsearch body response example provides the typical structure of a single document.

{
  "_index" : "libreant",
  "_type" : "book",
  "_id" : "AU4RleAfD1zQdqx6OQ8Y",
  "_version" : 1,
  "found" : true,
  "_source": {"_language": "en",
              "_text_en": "marco belletti pdf file latex manual",
              "author": "marco belletti",
              "type": "pdf file",
              "title": "latex manual",
              "_attachments": [{"sha1": "dc8dc34b3e0fec2377e5cf9ea7e4780d87ff18c5",
                                "name": "LaTeX_Wikibook.pdf",
                                "url": "fsdb:///dc8dc34b3e0fec2377e5cf9ea7e4780d87ff18c5",
                                "notes": "A n example bookLatex wikibook",
                                "mime": "application/pdf",
                                "download_count": 7,
                                "id": "17fd3d898a834e2689340cc8aacdebb4",
                                "size": 23909451}]
             }
}
add_book(body, doc_type='book')[source]
Call it like this:
db.add_book(doc_type=’book’, body={‘title’: ‘foobar’, ‘_language’: ‘it’})
autocomplete(fieldname, start)[source]
clone_index(new_indexname, index_conf=None)[source]

Clone current index

All entries of the current index will be copied into the newly created one named new_indexname

Parameters:index_conf – Configuration to be used in the new index creation. This param will be passed directly to DB.create_index()
create_index(indexname=None, index_conf=None)[source]

Create the index

Create the index with given configuration. If indexname is provided it will be used as the new index name instead of the class one (DB.index_name)

Parameters:index_conf – configuration to be used in index creation. If this is not specified the default index configuration will be used.
Raises:Exception – if the index already exists.
delete_all()[source]

Delete all books from the index

delete_book(id)[source]
file_is_attached(url)[source]

return true if at least one book has file with the given url as attachment

get_all_books(size=30)[source]
get_book_by_id(id)[source]
get_books_by_actor(authorname)[source]
get_books_by_title(title)[source]
get_books_querystring(query, **kargs)[source]
get_books_simplequery(query)[source]
get_last_inserted(size=30)[source]
increment_download_count(id, attachmentID, doc_type='book')[source]

Increment the download counter of a specific file

iterate_all()[source]
mlt(_id)[source]

High-level method to do “more like this”.

Its exact implementation can vary.

modify_book(id, body, doc_type='book', version=None)[source]

replace the entire book body

Instead of update_book this function will overwrite the book content with param body

If param version is given, it will be checked that the changes are applied upon that document version. If the document version provided is different from the one actually found, an elasticsearch.ConflictError will be raised

properties = {'_insertion_date': {'type': 'long', 'null_value': 0}, '_language': {'index': 'false', 'type': 'text'}, '_text_en': {'type': 'text', 'analyzer': 'english'}, '_text_it': {'type': 'text', 'analyzer': 'it_analyzer'}}
reindex(new_index=None, index_conf=None)[source]

Rebuilt the current index

This function could be useful in the case you want to change some index settings/mappings and you don’t want to loose all the entries belonging to that index.

This function is built in such a way that you can continue to use the old index name, this is achieved using index aliases.

The old index will be cloned into a new one with the given index_conf. If we are working on an alias, it is redirected to the new index. Otherwise a brand new alias with the old index name is created in such a way that points to the newly create index.

Keep in mind that even if you can continue to use the same index name, the old index will be deleted.

Parameters:index_conf – Configuration to be used in the new index creation. This param will be passed directly to DB.create_index()
settings = {'analysis': {'filter': {'italian_elision': {'articles': ['c', 'l', 'all', 'dall', 'dell', 'nell', 'sull', 'coll', 'pell', 'gl', 'agl', 'dagl', 'degl', 'negl', 'sugl', 'un', 'm', 't', 's', 'v', 'd'], 'type': 'elision'}, 'italian_stop': {'stopwords': '_italian_', 'type': 'stop'}, 'italian_stemmer': {'type': 'stemmer', 'language': 'italian'}}, 'analyzer': {'it_analyzer': {'filter': ['italian_elision', 'lowercase', 'italian_stop', 'italian_stemmer'], 'type': 'custom', 'tokenizer': 'standard'}}}}
setup_db(wait_for_ready=True)[source]

Create and configure index

If wait_for_ready is True, this function will block until status for self.index_name will be yellow

update_book(id, body, doc_type='book')[source]

Update a book

The “body” is merged with the current one. Yes, it is NOT overwritten.

In case of concurrency conflict this function could raise elasticsearch.ConflictError

update_mappings()[source]

This acts like a “wrapper” that always point to the recommended function for user searching.

libreantdb.api.collectStrings(leftovers)[source]
libreantdb.api.current_time_millisec()[source]
libreantdb.api.validate_book(body)[source]

This does not only accept/refuse a book. It also returns an ENHANCED version of body, with (mostly fts-related) additional fields.

This function is idempotent.