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
(**book)[source]¶ - Call it like this:
- db.add_book(doc_type=’book’, body={‘title’: ‘foobar’, ‘_language’: ‘it’})
-
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.
-
file_is_attached
(url)[source]¶ return true if at least one book has file with the given url as attachment
-
increment_download_count
(id, attachmentID, doc_type='book')[source]¶ Increment the download counter of a specific file
-
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
= {'_language': {'index': 'no', 'type': 'string'}, '_insertion_date': {'type': 'long', 'null_value': 0}, '_text_en': {'type': 'string', 'analyzer': 'english'}, '_text_it': {'type': 'string', '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
-
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
(**book)[source]¶ - Call it like this:
- db.add_book(doc_type=’book’, body={‘title’: ‘foobar’, ‘_language’: ‘it’})
-
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.
-
file_is_attached
(url)[source]¶ return true if at least one book has file with the given url as attachment
-
increment_download_count
(id, attachmentID, doc_type='book')[source]¶ Increment the download counter of a specific file
-
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
= {'_language': {'index': 'no', 'type': 'string'}, '_insertion_date': {'type': 'long', 'null_value': 0}, '_text_en': {'type': 'string', 'analyzer': 'english'}, '_text_it': {'type': 'string', '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
-