def search(database, view, index): indexer = get_indexer(database, view, index) if not indexer: return json.dumps({"Error": "indexer not found"}) start = time.time() query = request.args.get("q", "") if not query: response = Response(json.dumps(indexer.info()), content_type="application/json") return response include_docs = request.args.get("include_docs", False) include_docs = True if include_docs == "true" else False limit = request.args.get("limit", "25") limit = limit.isdigit() and int(limit) or 0 skip = request.args.get("skip", "0") skip = skip.isdigit() and int(skip) or 0 rows_by_id = {} rows = [] to_fetch = [] hits = indexer.search(query, limit=limit+skip, scores=True) for num, hit in enumerate(hits): if num < skip: continue _id = hit.dict()["_id"] if include_docs: to_fetch.append(_id) row = {"__lucene__": {}, "fields": {}} for key, value in hit.dict().iteritems(): if key == '_id': row["id"] = value elif key.startswith("_"): row["__lucene__"][key] = value else: row["fields"][key] = value #row["body"] = body rows.append(row) rows_by_id[_id] = row if include_docs: for doc in indexer.get_docs(to_fetch): rows_by_id[doc["_id"]]["doc"] = doc ret = {"rows": rows, "limit": limit, "skip": skip, "total_rows": len(hits), "fetch_duration": time.time()-start} json_data = json.dumps(ret) response = Response(json_data, content_type="application/json") return response
def correct(database, view, index): field = request.args.get("field") words = request.args.getlist("word") if not field or not words: return json.dumps({"Error": "Needs word and field"}) indexer = get_indexer(database, view, index) start = time.time() data = {} for word in words: data[word] = list(indexer.indexer.correct(field, word)) ret = {"corrections": data, "fetch_duration": time.time()-start} json_data = json.dumps(ret) response = Response(json_data, content_type="application/json") return response
logger = logging.getLogger(__name__) def get_args(): parser = get_parser(description='Make indexes.') # config parser.add_argument('--config', '-c', default='./config/indexes.yaml') return parser.parse_args() if __name__ == '__main__': # config args = get_args() config = Config(args.config) # build indexer indexer = get_indexer(config) ################################################################################################################################## # make indexes for mel-spectogram-pitch features indexer.make_indexes(input_path=config.input_path, output_path=config.output_path, split_all=config.split_all, split_train=config.split_train) # # make indexes for mel-pitch features # indexer.make_indexes(input_path=config.mel_pitch_input_path, output_path=config.mel_pitch_output_path, # split_all=config.split_all, split_train=config.split_train)