| 
									
										
										
										
											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 | 
					
						
							|  |  |  | from haystack.indexing.io import write_documents_to_db | 
					
						
							| 
									
										
										
										
											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() | 
					
						
							|  |  |  |     write_documents_to_db(document_store=sql_document_store, document_dir="samples/docs") | 
					
						
							|  |  |  |     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() | 
					
						
							|  |  |  |     write_documents_to_db(document_store=document_store, document_dir="samples/docs") | 
					
						
							|  |  |  |     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 |