Manage ASL magazines and their articles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
asl-articles/asl_articles/search.py

31 lines
894 B

""" Handle search requests. """
import logging
from flask import request, jsonify
from asl_articles import app
from asl_articles.models import Publisher
_logger = logging.getLogger( "search" )
# ---------------------------------------------------------------------
@app.route( "/search", methods=["POST"] )
def search():
"""Run a search query."""
query_string = request.json.get( "query" ).strip()
_logger.debug( "SEARCH: [%s]", query_string )
query = Publisher.query
if query_string:
query = query.filter(
Publisher.publ_name.ilike( "%{}%".format( query_string ) )
)
publishers = list( query )
_logger.debug( "- Found: %s", " ; ".join( str(p) for p in publishers ) )
publishers = [ {
"type": "publ",
"id": p.publ_id,
"publ_name": p.publ_name
} for p in publishers ]
return jsonify( publishers )