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')
print(searchstring)
result= tree()
document = db.session.query(Property.shelter_id,func.to_tsvector(func.string_agg(Value.name,' ')).label("text"))\
.join(Attribute)\
.join(Association,Property.id==Association.property_id)\
.join(Value, Association.value_id==Value.id)\
.group_by(Property.shelter_id)\
.subquery()
searchquery = db.session.query(document).filter(document.c.text.match(searchstring))
#print(searchquery)
for shelter_property in searchquery:
#print(shelter_property)
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