mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-11-01 10:19:23 +00:00
Add document count query
This commit is contained in:
parent
ec7ad29d51
commit
ecfd19d2d8
@ -18,4 +18,8 @@ class BaseDocumentStore:
|
||||
def get_document_ids_by_tag(self, tag):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_document_count(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -98,3 +98,7 @@ class SQLDocumentStore(BaseDocumentStore):
|
||||
row = Document(name=doc["name"], text=doc["text"])
|
||||
self.session.add(row)
|
||||
self.session.commit()
|
||||
|
||||
def get_document_count(self):
|
||||
return self.session.query(Document).count()
|
||||
|
||||
|
||||
@ -19,11 +19,10 @@ def write_documents_to_db(datastore, document_dir, clean_func=None, only_empty_d
|
||||
:return: None
|
||||
"""
|
||||
file_paths = Path(document_dir).glob("**/*.txt")
|
||||
n_docs = 0
|
||||
|
||||
# check if db has already docs
|
||||
if only_empty_db:
|
||||
n_docs = len(datastore.get_all_documents())
|
||||
n_docs = datastore.get_document_count()
|
||||
if n_docs > 0:
|
||||
logger.info(f"Skip writing documents since DB already contains {n_docs} docs ... "
|
||||
"(Disable `only_empty_db`, if you want to add docs anyway.)")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user