Skip to content

Commit

Permalink
Add simple cards endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Apr 18, 2024
1 parent 4603038 commit 5c3cbda
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import json

from flask import Flask
from flask import Flask, current_app, request
from flask_cors import CORS

import elasticsearch
Expand Down Expand Up @@ -299,6 +299,34 @@ def process_extra(self, return_value, response):
app.register_blueprint(blueprint, url_prefix='/api/idx/')


# Simple API, with four parameters: q, response, situation and bounds
@app.route('/api/simple/cards')
def simple_cards():
q = request.args.get('q', '')
responses = request.args.get('response', '')
situations = request.args.get('situation', '')
bounds = request.args.get('bounds', '')
filters = {}
if responses:
filters['response_ids_parents']= responses
if situations:
filters['situation_ids']= situations
if bounds:
filters['branch_geometry__bounded'] = json.loads(bounds)
filters = json.dumps([filters])

es_client = current_app.config['ES_CLIENT']
return blueprint.controllers.search(
es_client, ['cards'], q,
size=30,
offset=0,
filters=filters,
score_threshold=0,
match_type='cross_fields',
match_operator='or',
).get('search_results', [])


@app.after_request
def add_header(response):
response.cache_control.max_age = 600
Expand Down

0 comments on commit 5c3cbda

Please sign in to comment.