anton-l HF staff commited on
Commit
75f7430
β€’
1 Parent(s): 08c1b6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -53,7 +53,7 @@ def process_results(results, query):
53
  return results_html
54
 
55
 
56
- def match_query(query, num_results=10):
57
  query_body = {"query": {"match": {"content": query}}, "size": num_results}
58
 
59
  response = es.search(index=os.environ.get("INDEX"), body=query_body)
@@ -61,7 +61,7 @@ def match_query(query, num_results=10):
61
  return hits
62
 
63
 
64
- def phrase_query(query, num_results=10):
65
  query_body = {"query": {"match_phrase": {"content": query}}, "size": num_results}
66
 
67
  response = es.search(index=os.environ.get("INDEX"), body=query_body)
@@ -90,9 +90,9 @@ def search(query, num_results=10):
90
 
91
  query = query[:200]
92
  if query.startswith('"') and query.endswith('"'):
93
- response = phrase_query(query[1:-1], num_results=num_results)
94
  else:
95
- response = match_query(query, num_results=num_results)
96
  results = [
97
  {
98
  "text": html.escape(hit["content"]),
 
53
  return results_html
54
 
55
 
56
+ def match_query(es, query, num_results=10):
57
  query_body = {"query": {"match": {"content": query}}, "size": num_results}
58
 
59
  response = es.search(index=os.environ.get("INDEX"), body=query_body)
 
61
  return hits
62
 
63
 
64
+ def phrase_query(es, query, num_results=10):
65
  query_body = {"query": {"match_phrase": {"content": query}}, "size": num_results}
66
 
67
  response = es.search(index=os.environ.get("INDEX"), body=query_body)
 
90
 
91
  query = query[:200]
92
  if query.startswith('"') and query.endswith('"'):
93
+ response = phrase_query(es, query[1:-1], num_results=num_results)
94
  else:
95
+ response = match_query(es, query, num_results=num_results)
96
  results = [
97
  {
98
  "text": html.escape(hit["content"]),