Skip to content

Commit

Permalink
Filter by status in search (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik authored Jan 29, 2024
1 parent b39da88 commit 7206eaf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/stampy_nlp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def wrapper(*args, **kwargs):
@log_queries
def search_html():
logger.debug('search_html()')
query = DEFAULT_QUERY
return render_template('search.html', query=query, results=semantic_search(query))
args = request.args or {}
query = args.get('query') or DEFAULT_QUERY
return render_template('search.html', query=query, results=semantic_search(query), status=args.get('status'))


@frontend.route('/duplicates')
Expand Down Expand Up @@ -126,7 +127,7 @@ def search_api():
query = request.args.get('query', DEFAULT_QUERY)
top_k = as_int('top', DEFAULT_TOPK)
status = request.args.getlist('status')
show_live = as_bool('showLive', 'true')
show_live = as_bool('showLive', str(not status))
get_content = as_bool('getContent', 'false')

return jsonify(semantic_search(query, top_k=top_k, showLive=show_live, status=status, get_content=get_content))
Expand Down
15 changes: 15 additions & 0 deletions src/stampy_nlp/static/css/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,18 @@ tr:hover {
background: khaki;
}

.search-header {
display: flex;
}
.search-header h2 {
flex: content;
display: inline-block;
margin-right: 20px;
}
.search-header .status-input {
display: inline;
margin-left: 10px;
}
.search-header .status-label {
display: inline;
}
41 changes: 27 additions & 14 deletions src/stampy_nlp/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
{% extends "template.html" %}
{% block content %}
<div style="width:100%; padding:5px" >

<h2 id="title">Semantic Search for Similar FAQs</h2>

<div class="search-header">
<h2 id="title">Semantic Search for Similar FAQs</h2>
<span>
<input type="checkbox" id="all" name="status" value="All" class="status-input">
<label for="all" class="status-label">All</label>
<input type="checkbox" id="live" name="live" value="Live on site" class="status-input">
<label for="live" class="status-label">Live</label>
<input type="checkbox" id="in_progress" name="in_progress" value="In progress" class="status-input">
<label for="in_progress" class="status-label">In progress</label>
</span>
</div>
<p id="status"></p>
<input type="search" id="query" name="question" value="{{ query }}">
<div id="results" class="dropdown-content show">
Expand All @@ -20,7 +30,7 @@ <h2 id="title">Semantic Search for Similar FAQs</h2>
{% endfor %}
</div>
</div>

</body>
<script>
const TITLE = document.getElementById('title');
Expand All @@ -31,12 +41,17 @@ <h2 id="title">Semantic Search for Similar FAQs</h2>
const QUERY_URL = "/api/search?status=all&query="

QUERY.addEventListener('keyup', search);
Array.from(document.getElementsByClassName('status-input')).forEach(e => e.addEventListener('change', search))

async function search()
{
async function search() {
STATUS.innerText = "";

apicall = QUERY_URL + encodeURIComponent(QUERY.value);

const statusParams = Array.from(document.getElementsByClassName('status-input'))
.filter(e => e.checked)
.map(e => 'status=' + encodeURIComponent(e.value))
.join('&')

apicall = QUERY_URL + encodeURIComponent(QUERY.value) + (statusParams !== "" ? '&' + statusParams : '');
console.log("get:", apicall);
let f = await fetch(apicall);
let text = await f.text();
Expand All @@ -45,13 +60,11 @@ <h2 id="title">Semantic Search for Similar FAQs</h2>

let k = 5
// print top k results
for (let i = 0; i < k; i++)
{
ANCHORS[i].href = response[i]["url"]
ANCHORS[i].innerHTML =
`(${response[i]["score"].toFixed(2)}) ${response[i]["title"]}`
}
response.slice(0, k).forEach((res, i) => {
ANCHORS[i].href = res["url"]
ANCHORS[i].innerHTML = `(${res["score"].toFixed(2)}) ${res["title"]}`
})
}
</script>
{% endblock %}
</html>
</html>

0 comments on commit 7206eaf

Please sign in to comment.