def api_search_posts(fields, term, page_size, page): ret = [] searcher = sql.PostSearcher(_session) res = searcher.search_fields(fields, term.strip("%")) full_len = len(res) res = res[page * page_size:page * page_size + page_size] for p in res: files = [] for url in p.urls: if not url.file: print('Post URL Missing a File:', url) continue file = SanitizedRelFile(base=settings.get("output.base_dir"), file_path=url.file.path) if file.is_file(): files.append({'token': url.file.id, 'path': file.absolute()}) if len(files): ret.append({ 'reddit_id': p.reddit_id, 'author': p.author, 'type': p.type, 'title': p.title, 'body': p.body, 'parent_id': p.parent_id, 'subreddit': p.subreddit, 'over_18': p.over_18, 'created_utc': p.created_utc, 'num_comments': p.num_comments, 'score': p.score, 'source_alias': p.source_alias, 'files': files }) return {'total': full_len, 'results': ret}
def api_searchable_fields(): return sql.PostSearcher(_session).get_searchable_fields()
def setUp(self): importlib.reload(sql) self.assertFalse(sql._engine, msg="Failed to clear SQL session.") settings.load(self.settings_file) sql.init_from_settings() self.ps = sql.PostSearcher(sql.session())