def test_add_document(self): sut = Whoosh() sut.delete_index("test") sut.create_index("test", schema = Schema(id=ID(stored=True),name=TEXT(stored=True))) sut.index_document("test", {'id':'1', 'name':'Daniel'}); documents = [x for x in sut.find_all("test")] self.assertEqual(1, len(documents)) self.assertEqual('1', documents[0]['id']) self.assertEqual('Daniel', document[0]['name']) sut.delete_index("test")
def test_find_by_field(self): sut = Whoosh() sut.delete_index("test") sut.create_index("test", schema = Schema(id=ID(stored=True),name=TEXT(stored=True))) sut.index_document("test", {'id':'1', 'name':u("Daniel")}); sut.index_document("test", {'id':'2', 'name':u("Jon")}); documents = [x for x in sut.find_all("test", {'name':u("jon")})] self.assertEqual('2', documents[0]['id']) self.assertEqual('Jon', documents[0]['name']) sut.delete_index("test")
def test_delete_documents(self): sut = Whoosh() sut.delete_index("test") sut.index_document("test", {'id':'1', 'name':'Daniel'}); sut.index_document("test", {'id':'2', 'name':'Jon'}); sut.delete_document("test", '1') documents = [x for x in sut.find_all("test")] self.assertEqual(1, len(documents)) self.assertEqual('2', documents[0]['id']) self.assertEqual('Jon', documents[0]['name']) sut.delete_index("test")