2020-05-04 18:00:07 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from time import sleep
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from haystack.database.elasticsearch import ElasticsearchDocumentStore
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-22 16:08:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from haystack.database.sql import SQLDocumentStore
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-08 11:07:19 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from haystack.indexing.utils import convert_files_to_dicts
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-27 17:53:42 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 18:00:07 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								def test_sql_write_read():
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-24 18:24:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sql_document_store = SQLDocumentStore()
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-08 11:07:19 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    documents = convert_files_to_dicts(dir_path="samples/docs")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    sql_document_store.write_documents(documents)
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-24 18:24:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    documents = sql_document_store.get_all_documents()
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-27 17:53:42 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert len(documents) == 2
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-24 18:24:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    doc = sql_document_store.get_document_by_id("1")
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-27 12:19:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert doc.id
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert doc.text
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 18:00:07 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def test_elasticsearch_write_read(elasticsearch_fixture):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    document_store = ElasticsearchDocumentStore()
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-08 11:07:19 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    documents = convert_files_to_dicts(dir_path="samples/docs")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    document_store.write_documents(documents)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 18:00:07 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sleep(2)  # wait for documents to be available for query
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    documents = document_store.get_all_documents()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert len(documents) == 2
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert documents[0].id
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert documents[0].text
							 |