Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1283 | concept search criteria | added syno…
Browse files Browse the repository at this point in the history
…nyms search criteria with wildcards
  • Loading branch information
snyaggarwal committed Apr 25, 2022
1 parent 7a61183 commit 19fa109
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def get_exact_search_criterion(self):

def get_query(attr):
words = search_str.split(' ')
criteria = Q('match', **{attr: words[0]})
if words[0] != search_str:
criteria = Q('match', **{attr: search_str}) | Q('match', **{attr: words[0]})
else:
criteria = Q('match', **{attr: words[0]})
for word in words[1:]:
criteria &= Q('match', **{attr: word})
return criteria
Expand Down Expand Up @@ -564,13 +567,22 @@ def get_wildcard_search_criterion(self):
name_attr = '_name'

def get_query(_str):
return Q(
"wildcard", id=dict(value=_str, boost=2)
query = Q(
"wildcard", id=dict(value=_str, boost=3)
) | Q(
"wildcard", **{name_attr: dict(value=_str, boost=5)}
) | Q(
"query_string", query=self.get_wildcard_search_string(_str)
)
if self.is_concept_document():
query |= Q(
"wildcard",
synonyms=dict(
value=self.get_wildcard_search_string(self.get_search_string(decode=False, lower=False)),
boost=2
)
)
return query

if not search_string:
return get_query(search_string)
Expand Down

0 comments on commit 19fa109

Please sign in to comment.