Commit 7ae1a33b authored by Aron Gergely's avatar Aron Gergely

Added basic full text search functionality to API

parent 8ef94d5a
......@@ -16,7 +16,7 @@ __license__ = ""
#from bootstrap import db
from bootstrap import db
from sqlalchemy.sql import func
from sqlalchemy.sql import func, select
from flask import Blueprint, jsonify, request
from collections import defaultdict
from web.models import Shelter, Attribute, Property, Value, Association, ShelterPicture, Category
......@@ -178,3 +178,21 @@ def attributes(attribute_name, attribute_value=''):
return jsonify(result)
@api_bp.route('/shelters/search/<searchstring>', methods=['GET'])
def fulltext(searchstring):
searchstring = request.args.get('string')
result= tree()
document = db.session.query(Property.shelter_id,func.to_tsvector(func.string_agg(,' ')).label("text"))\
searchquery = db.session.query(document).filter(document.c.text.match(searchstring))
for shelter_property in searchquery:
result[shelter_property.shelter_id] = 1#shelter_property.text
return jsonify(result)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment