def test_integration(self): api.initialize_index(self.index_path) doc_set_info = { 'id': 'test', 'title': 'Test documentation', 'path': get_data_path('upload', 'test'), 'harvester': html_config() } api.index_document_set(self.index_path, doc_set_info) self.assertEqual( list(api.search(self.index_path, "ShouldNotBeIndexed")), []) hits = list(api.search(self.index_path, "ShouldBeIndexed")) self.assertEqual(len(hits), 1) self.assertEqual(hits[0]['path'], 'test1.html') self.assertEqual(hits[0]['title'], 'The title') self.assertEqual(hits[0]['set'], 'test') self.assertEqual(hits[0]['kind'], 'HTML') hits = list(api.search(self.index_path, "ShouldBeIndexed set:test")) self.assertEqual(len(hits), 1) self.assertEqual( list(api.search(self.index_path, "ShouldBeIndexed set:unknown")), []) api.clear_document_set(self.index_path, 'unknown') hits = list(api.search(self.index_path, "ShouldBeIndexed")) self.assertEqual(len(hits), 1) api.clear_document_set(self.index_path, doc_set_info['id']) self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed")), [])
def test_integration(self): api.initialize_index(self.index_path) doc_set_info = { 'id': 'test', 'title': 'Test documentation', 'path': get_data_path('upload', 'test'), 'harvester': html_config() } api.index_document_set(self.index_path, doc_set_info) self.assertEqual(list(api.search(self.index_path, "ShouldNotBeIndexed")), []) hits = list(api.search(self.index_path, "ShouldBeIndexed")) self.assertEqual(len(hits), 1) self.assertEqual(hits[0]['path'], 'test1.html') self.assertEqual(hits[0]['title'], 'The title') self.assertEqual(hits[0]['set'], 'test') self.assertEqual(hits[0]['kind'], 'HTML') hits = list(api.search(self.index_path, "ShouldBeIndexed set:test")) self.assertEqual(len(hits), 1) self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed set:unknown")), []) api.clear_document_set(self.index_path, 'unknown') hits = list(api.search(self.index_path, "ShouldBeIndexed")) self.assertEqual(len(hits), 1) api.clear_document_set(self.index_path, doc_set_info['id']) self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed")), [])
def _prepare_index(cls): api.initialize_index(INDEX_PATH) doc_set_info = { 'id': 'test', 'title': 'Test documentation', 'path': get_data_path('upload', 'test'), 'harvester': html_config() } api.index_document_set(INDEX_PATH, doc_set_info)
def _prepare_index(cls): api.initialize_index(INDEX_PATH) doc_set_info = { 'id': 'test', 'title': 'Test documentation', 'path': get_data_path('api'), 'url': 'http://docs.exemple.com/', 'harvester': html_config() } api.index_document_set(INDEX_PATH, doc_set_info)
def load_doc_sets(settings): """ Given a settings dictionary with the path of the doc sets file, replace the path (in-place) with the doc sets themselves. """ index_path = settings['dokang.index_path'] if not os.path.exists(index_path): api.initialize_index(index_path) upload_dir = settings['dokang.uploaded_docs.dir'] if not os.path.exists(upload_dir): os.makedirs(upload_dir) sets = settings['dokang.doc_sets'] = {} for uploaded in os.listdir(upload_dir): sets[uploaded] = doc_set(settings, uploaded) return settings
def get_doc_sets(settings): """ Get doc sets using path of doc sets file defined in settings. """ index_path = settings['dokang.index_path'] if not os.path.exists(index_path): try: os.makedirs(os.path.dirname(index_path)) except OSError: # It's ok if the parent dir exists already pass api.initialize_index(index_path) upload_dir = settings['dokang.uploaded_docs.dir'] if not os.path.exists(upload_dir): os.makedirs(upload_dir) return { uploaded: doc_set(settings, uploaded) for uploaded in (x.decode('utf-8') if isinstance(x, bytes) else x for x in os.listdir(upload_dir)) }
def init(settings, force): index_path = settings['dokang.index_path'] if os.path.exists(index_path) and not force: sys.exit("Index already exists at %s. Use `--force` to overwrite it." % index_path) api.initialize_index(index_path)