Skip to content

Commit

Permalink
Allow searching descriptions by locale and across types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Sep 16, 2022
1 parent de1aa5e commit eb494df
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions iati_datastore/iatilib/frontend/dsfilter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial
import six
from sqlalchemy import or_, and_, orm
from sqlalchemy import or_, and_, orm, func
from sqlalchemy.sql.operators import eq, gt, lt
from iatilib import db
from iatilib.model import (
Expand Down Expand Up @@ -259,7 +259,12 @@ def title(title):
)

def description(description):
return Activity.description.ilike("%{}%".format(description))
locale = request.args.get("locale", "en")
return or_(
Activity.description.ilike("%{}%".format(description)),
func.jsonb_path_exists(Activity.description_all_values, '$.{}[*] ? (@.* like_regex "{}")'.format('default', description)),
func.jsonb_path_exists(Activity.description_all_values, '$.{}[*] ? (@.* like_regex "{}")'.format(locale, description)),
)

filter_conditions = {
'iati-identifier': partial(eq, Activity.iati_identifier),
Expand Down

0 comments on commit eb494df

Please sign in to comment.