Implement a better Drilldown form
This commit is contained in:
parent
67ea926c96
commit
424f8381d3
|
@ -21,11 +21,13 @@ def initialise_opensearch():
|
|||
return client
|
||||
|
||||
|
||||
def construct_query(query, fields):
|
||||
def construct_query(query, fields, results):
|
||||
if not fields:
|
||||
fields = settings.OPENSEARCH_MAIN_SEARCH_FIELDS
|
||||
if not results:
|
||||
results = 5
|
||||
query = {
|
||||
"size": 5,
|
||||
"size": results,
|
||||
"query": {
|
||||
"multi_match": {
|
||||
"query": query,
|
||||
|
@ -36,8 +38,8 @@ def construct_query(query, fields):
|
|||
return query
|
||||
|
||||
|
||||
def run_main_query(client, query, fields=None):
|
||||
search_query = construct_query(query, fields)
|
||||
def run_main_query(client, query, fields=None, results=None):
|
||||
search_query = construct_query(query, fields, results)
|
||||
# fmt: off
|
||||
response = client.search(body=search_query,
|
||||
index=settings.OPENSEARCH_INDEX_MAIN)
|
||||
|
|
|
@ -2,12 +2,8 @@
|
|||
|
||||
{% for plan in plans %}
|
||||
|
||||
{% if plan in user_plans %}
|
||||
<div class="box has-background-info-light">
|
||||
{% else %}
|
||||
<div class="box">
|
||||
{% endif %}
|
||||
|
||||
<div class="box">
|
||||
<article class="media">
|
||||
<div class="media-left">
|
||||
<figure class="image is-64x64">
|
||||
|
|
|
@ -1,93 +1,96 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block content %}
|
||||
|
||||
<div class="block">
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label is-normal">
|
||||
<label class="label">Search</label>
|
||||
</div>
|
||||
<div class="field-body">
|
||||
<div class="field">
|
||||
<p class="control is-expanded has-icons-left">
|
||||
{% csrf_token %}
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<input name="query" class="input" type="text" placeholder="Query">
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-user"></i>
|
||||
<i class="fas fa-magnifying-glass"></i>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label is-normal">
|
||||
<label class="label">Timescale</label>
|
||||
</div>
|
||||
|
||||
<div class="field-body">
|
||||
<div class="field is-narrow">
|
||||
<div class="control">
|
||||
<div class="field">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<div class="select is-fullwidth">
|
||||
<select name="fields">
|
||||
<select name="timescale">
|
||||
<option value="minute">Minute</option>
|
||||
<option value="hour">Hour</option>
|
||||
<option value="day">Day</option>
|
||||
<option value="week">Week</option>
|
||||
<option value="month">Month</option>
|
||||
<option value="6months">6 months</option>
|
||||
|
||||
</select>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-magnifying-glass"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="field-label is-normal">
|
||||
<label class="label">Fields</label>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<div class="select is-fullwidth is-multiple">
|
||||
<select multiple name="fields">
|
||||
{% for field in fields %}
|
||||
<option>{{ field }}</option>
|
||||
<option value="{{ field }}">{{ field }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-magnifying-glass"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field-body">
|
||||
<div class="field is-narrow">
|
||||
<div class="control">
|
||||
<div class="select is-fullwidth">
|
||||
<select>
|
||||
<option>day</option>
|
||||
<option>week</option>
|
||||
<option>month</option>
|
||||
<option>year</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field is-horizontal">
|
||||
|
||||
<div class="field-body">
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label">
|
||||
<label class="label">Search all fields</label>
|
||||
</div>
|
||||
<div class="field-body">
|
||||
<div class="field is-narrow">
|
||||
<div class="control">
|
||||
<label class="radio">
|
||||
<input type="radio" name="member">
|
||||
Yes
|
||||
</label>
|
||||
<label class="radio">
|
||||
<input type="radio" name="member">
|
||||
No
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label is-normal">
|
||||
<label class="label">Results</label>
|
||||
</div>
|
||||
<div class="field-body">
|
||||
<div class="field is-narrow">
|
||||
<div class="control">
|
||||
|
||||
<div class="field">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<div class="select is-fullwidth">
|
||||
<select name="results">
|
||||
<option>5</option>
|
||||
<option>10</option>
|
||||
<option>25</option>
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="15">15</option>
|
||||
<option value="20">20</option>
|
||||
</select>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-magnifying-glass"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-body">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="field is-horizontal">
|
||||
<div class="field-label">
|
||||
<!-- Left empty for spacing -->
|
||||
|
@ -95,11 +98,11 @@
|
|||
<div class="field-body">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
|
||||
<button class="button is-primary">
|
||||
Send message
|
||||
Search
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -137,6 +140,7 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if results is not None %}
|
||||
<p>{{ card }} hits</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -18,20 +18,24 @@ class Drilldown(LoginRequiredMixin, View):
|
|||
def get(self, request):
|
||||
if not request.user.has_plan(self.plan_name):
|
||||
return render(request, "denied.html")
|
||||
return render(request, self.template_name)
|
||||
context = {"fields": settings.OPENSEARCH_MAIN_SEARCH_FIELDS}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
def post(self, request):
|
||||
if not request.user.has_plan(self.plan_name):
|
||||
return render(request, "denied.html")
|
||||
fields = None
|
||||
if "fields" in request.POST:
|
||||
fields = request.POST["fields"]
|
||||
fields = request.POST.getlist("fields")
|
||||
print("FIELD", fields)
|
||||
if "results" in request.POST:
|
||||
results = request.POST["results"]
|
||||
print("RESULTS", results)
|
||||
if "query" in request.POST:
|
||||
query = request.POST["query"]
|
||||
# field = results.POST["field"]
|
||||
# print("FIELD ", field)
|
||||
results = run_main_query(client, query, fields)
|
||||
results = run_main_query(client, query, fields, results)
|
||||
pp.pprint(results)
|
||||
results_parsed = []
|
||||
if "hits" in results.keys():
|
||||
|
|
Loading…
Reference in New Issue