Skip to content

Commit

Permalink
fix filters issue in week2 plus, add in P4 work
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingers committed Mar 3, 2022
1 parent 2d75dc0 commit 6fcdf43
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion requirements_week4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ipython
urljoin
xgboost
pandas
numpy
numba
numexpr
sklearn
Expand Down
2 changes: 2 additions & 0 deletions week2/utilities/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def create_simple_baseline(user_query, click_prior_query, filters, sort="_score"
}
}
],
"minimum_should_match": 1,
"filter": filters #
}

Expand Down Expand Up @@ -195,6 +196,7 @@ def create_query(user_query, click_prior_query, filters, sort="_score", sortDir=
}
}
],
"minimum_should_match": 1,
"filter": filters #
}
},
Expand Down
9 changes: 6 additions & 3 deletions week3/utilities/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create_simple_baseline(user_query, click_prior_query, filters, sort="_score"
"slop": "6",
"minimum_should_match": "2<75%",
"fields": ["name^10", "name.hyphens^10", "shortDescription^5",
"longDescription^5", "department^0.5", "sku", "manufacturer", "features", "categoryPath", "name_synonyms"]
"longDescription^5", "department^0.5", "sku", "manufacturer", "features", "categoryPath", "name_analogies"]
}
},
{
Expand All @@ -100,6 +100,7 @@ def create_simple_baseline(user_query, click_prior_query, filters, sort="_score"
}
}
],
"minimum_should_match": 1,
"filter": filters #
}

Expand All @@ -116,9 +117,10 @@ def create_simple_baseline(user_query, click_prior_query, filters, sort="_score"
if user_query == "*" or user_query == "#":
#replace the bool
try:
query_obj["query"].pop("bool")
query_obj["query"] = {"match_all": {}}
except:
print("Couldn't replace query for *")
pass
if highlight:
query_obj["highlight"] = {
"fields": {
Expand Down Expand Up @@ -175,7 +177,7 @@ def create_query(user_query, click_prior_query, filters, sort="_score", sortDir=
"slop": "6",
"minimum_should_match": "2<75%",
"fields": ["name^10", "name.hyphens^10", "shortDescription^5",
"longDescription^5", "department^0.5", "sku", "manufacturer", "features", "categoryPath", "name_synonyms"]
"longDescription^5", "department^0.5", "sku", "manufacturer", "features", "categoryPath", "name_analogies"]
}
},
{
Expand All @@ -194,6 +196,7 @@ def create_query(user_query, click_prior_query, filters, sort="_score", sortDir=
}
}
],
"minimum_should_match": 1,
"filter": filters #
}
},
Expand Down
10 changes: 9 additions & 1 deletion week4/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def process_filters(filters_input):

return filters, display_filters, applied_filters

def get_query_category(user_query, query_class_model):
print("IMPLEMENT ME: get_query_category")
return None


@bp.route('/query', methods=['GET', 'POST'])
def query():
Expand Down Expand Up @@ -131,6 +135,10 @@ def query():
else:
query_obj = qu.create_query("*", "", [], sort, sortDir, size=100)

query_class_model = current_app.config["query_model"]
query_category = get_query_category(user_query, query_class_model)
if query_category is not None:
print("IMPLEMENT ME: add this into the filters object so that it gets applied at search time. This should look like your `term` filter from week 1 for department but for categories instead")
#print("query obj: {}".format(query_obj))
response = opensearch.search(body=query_obj, index=current_app.config["index_name"], explain=explain)
# Postprocess results here if you so desire
Expand All @@ -139,7 +147,7 @@ def query():
if error is None:
return render_template("search_results.jinja2", query=user_query, search_response=response,
display_filters=display_filters, applied_filters=applied_filters,
sort=sort, sortDir=sortDir, model=model, explain=explain)
sort=sort, sortDir=sortDir, model=model, explain=explain, query_category=query_category)
else:
redirect(url_for("index"))

Expand Down
7 changes: 5 additions & 2 deletions week4/templates/display_filters.jinja2
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div><span class="filter-header">Filters</span>: {{ display_filters|join(", ") }}
{% if display_filters %}<div><span class="filter-header">Filters</span>: {{ display_filters|join(", ") }}
<span><a href="{{url_for("search.query")}}?&query={{ query }}">Clear All Filters</a></span>
</div>
</div>{% endif %}
{% if query_category %}<div>
Your query categorization model predicted: {{ query_category }}
</div>{% endif %}
4 changes: 1 addition & 3 deletions week4/templates/search_results.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

{% block content %}
<div id="did-you-mean">DYM goes here</div>
{% if display_filters%}
<div id="applied-filters">{% include 'display_filters.jinja2' %}</div>
{% endif %}
<div id="applied-filters">{% include 'display_filters.jinja2' %}</div>
{% if search_response and search_response.hits%}
<div id="all-results">
<div id="search-meta-container">Your query of {{ query }} returned {{ "{:,d}".format(search_response.hits.total.value) }} hits in {{ search_response.took }} ms.</div>
Expand Down
2 changes: 2 additions & 0 deletions week4/utilities/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def create_simple_baseline(user_query, click_prior_query, filters, sort="_score"
}
}
],
"minimum_should_match": 1,
"filter": filters #
}

Expand Down Expand Up @@ -195,6 +196,7 @@ def create_query(user_query, click_prior_query, filters, sort="_score", sortDir=
}
}
],
"minimum_should_match": 1,
"filter": filters #
}
},
Expand Down

0 comments on commit 6fcdf43

Please sign in to comment.