def test_unique_values(self): catalog = Catalog('tests/catalog', Document.fields) values = catalog.get_unique_values('title') self.assert_('pearl' in values) self.assert_('motorola' not in values)
def test_everything(self): catalog = Catalog('tests/catalog', Document.fields) # Simple Search, hit results = catalog.search(data=u'lion') self.assertEqual(len(results), 4) documents = [ x.name for x in results.get_documents(sort_by='name') ] self.assertEqual(documents, ['03.txt', '08.txt', '10.txt', '23.txt']) # Simple Search, miss self.assertEqual(len(catalog.search(data=u'tiger')), 0) # Unindex, Search, Abort, Search catalog.unindex_document('03.txt') results = catalog.search(data=u'lion') self.assertEqual(len(catalog.search(data=u'lion')), 3) catalog.abort_changes() self.assertEqual(len(catalog.search(data=u'lion')), 4) # Query on indexed boolean self.assertEqual(len(catalog.search(about_wolf=True)), 5) # Query on stored boolean results = catalog.search(about_wolf=True) longer_stories = 0 for result in results.get_documents(): if result.is_long: longer_stories += 1 self.assertEqual(longer_stories, 0) # Phrase Query results = catalog.search(data=u'this is a double death') self.assertEqual(len(results), 1) # Range Query query = RangeQuery('name', '03.txt', '06.txt') results = catalog.search(query) self.assertEqual(len(results), 4) # Not Query (1/2) query = NotQuery(PhraseQuery('data', 'lion')) results = catalog.search(query) self.assertEqual(len(results), 27) # Not Query (2/2) query1 = PhraseQuery('data', 'mouse') query2 = NotQuery(PhraseQuery('data', 'lion')) query = AndQuery(query1, query2) results = catalog.search(query) self.assertEqual(len(results), 2)
def test_everything(self): catalog = Catalog('tests/catalog', Document.fields) # Simple Search, hit results = catalog.search(data=u'lion') self.assertEqual(len(results), 4) documents = [x.name for x in results.get_documents(sort_by='name')] self.assertEqual(documents, ['03.txt', '08.txt', '10.txt', '23.txt']) # Simple Search, miss self.assertEqual(len(catalog.search(data=u'tiger')), 0) # Unindex, Search, Abort, Search catalog.unindex_document('03.txt') results = catalog.search(data=u'lion') self.assertEqual(len(catalog.search(data=u'lion')), 3) catalog.abort_changes() self.assertEqual(len(catalog.search(data=u'lion')), 4) # Query on indexed boolean self.assertEqual(len(catalog.search(about_wolf=True)), 5) # Query on stored boolean results = catalog.search(about_wolf=True) longer_stories = 0 for result in results.get_documents(): if result.is_long: longer_stories += 1 self.assertEqual(longer_stories, 0) # Phrase Query results = catalog.search(data=u'this is a double death') self.assertEqual(len(results), 1) # Range Query query = RangeQuery('name', '03.txt', '06.txt') results = catalog.search(query) self.assertEqual(len(results), 4) # Not Query (1/2) query = NotQuery(PhraseQuery('data', 'lion')) results = catalog.search(query) self.assertEqual(len(results), 27) # Not Query (2/2) query1 = PhraseQuery('data', 'mouse') query2 = NotQuery(PhraseQuery('data', 'lion')) query = AndQuery(query1, query2) results = catalog.search(query) self.assertEqual(len(results), 2)