Skip to content

Commit

Permalink
Remove search provider info template feature
Browse files Browse the repository at this point in the history
It just makes things complicated without any real advantage.
  • Loading branch information
medihack committed Jun 16, 2024
1 parent 94bc54e commit 4b0b98c
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 86 deletions.
2 changes: 0 additions & 2 deletions radis/opensearch/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def fetch_opensearch_document(report: Report) -> dict[str, Any]:
name="OpenSearch BM25",
search=search,
max_results=1000,
info_template="", # TODO:
)
)

Expand All @@ -84,6 +83,5 @@ def fetch_opensearch_document(report: Report) -> dict[str, Any]:
count=count,
retrieve=retrieve,
max_results=None,
info_template="", # TODO:
)
)
2 changes: 0 additions & 2 deletions radis/rag/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class RetrievalProvider(NamedTuple):
for a search.
- max_results (int | None): The maximum number of results that can be retrieved by this
provider, or None if there is no limit.
- info_template (str): The template to be rendered as info.
"""

name: str
count: Callable[[Search], int]
retrieve: Callable[[Search], Iterable[str]]
max_results: int | None
info_template: str


retrieval_providers: dict[str, RetrievalProvider] = {}
Expand Down
4 changes: 0 additions & 4 deletions radis/search/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from crispy_forms.helper import FormHelper, Layout
from crispy_forms.layout import Button, Div, Field
from django import forms
from django.urls import reverse

from radis.core.constants import LANGUAGE_LABELS
from radis.reports.models import Language, Modality
Expand Down Expand Up @@ -105,9 +104,6 @@ def create_query_layout(self) -> Layout:
"maxlength": 200,
},
provider_attrs={
"hx-post": reverse("search_info"),
"hx-target": "#search-panel",
"@change": "providerChanged",
"style": "max-width: 200px",
"aria-label": "Select search provider",
},
Expand Down
2 changes: 0 additions & 2 deletions radis/search/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ class SearchProvider(NamedTuple):
- search (Callable[[Search], SearchResult]): The function that handles the search.
- max_results (int): The maximum number of results that can be fetched by a search.
Must be smaller than offset + limit when searching.
- info_template (str): The template to be rendered as info.
"""

name: str
search: Callable[[Search], SearchResult]
max_results: int
info_template: str


search_providers: dict[str, SearchProvider] = {}
Expand Down
16 changes: 0 additions & 16 deletions radis/search/static/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,6 @@ function QueryInput() {
// @ts-ignore
queryInput.value = "";
queryInput.focus();

const params = new URLSearchParams(window.location.search);
params.delete("query");
params.delete("page");
params.delete("per_page");
const newUrl = `${window.location.pathname}?${params.toString()}`;
history.pushState(null, "", newUrl);
},
providerChanged(event) {
const selectedProvider = event.target.value;
const params = new URLSearchParams(window.location.search);
params.set("provider", selectedProvider);
params.delete("page");
params.delete("per_page");
const newUrl = `${window.location.pathname}?${params.toString()}`;
history.pushState(null, "", newUrl);
},
};
}
Expand Down
17 changes: 15 additions & 2 deletions radis/search/templates/search/_search_info.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<div class="card mt-3">
<div class="card-body">
<h5 class="card-title">{{ selected_provider }}</h5>
{% include info_template %}
<h5 class="card-title">Search Info</h5>
<p>
Provide your search query in the search box above to search for reports. You can use
additional filters to narrow down the search results (on the right side).
</p>
<p>
The following search rules apply:
<ul>
<li>Search terms are case-insensitive.</li>
<li>All terms in a query must be matched by a document (implicit AND query).</li>
<li>term1 OR term2 (capital OR) means that either term1 or term2 must match.</li>
<li>A phrase surrounded by quotes will look for an exact match, e.g. "lung disease".</li>
<li>- in front of a term means that the term or phrase must not be present.</li>
</ul>
</p>
</div>
</div>
2 changes: 0 additions & 2 deletions radis/search/templates/search/form_elements/query_input.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<button type="button"
class="btn bg-transparent"
@click="clearQuery()"
hx-post="{% url 'search_info' %}"
hx-target="#search-panel"
style="width: 40px;
margin-left: -40px;
padding: 0;
Expand Down
16 changes: 7 additions & 9 deletions radis/search/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ <h4 class="mb-3">Search Reports</h4>
<div class="row">{% crispy form form.query_helper %}</div>
<div class="row">
<div class="col">
<div id="search-panel">
{% if form.non_field_errors %}
<div class="mt-3">{% include "bootstrap5/errors.html" %}</div>
{% elif documents != None %}
{% include "search/_search_results.html" %}
{% elif info_template %}
{% include "search/_search_info.html" %}
{% endif %}
</div>
{% if form.non_field_errors %}
<div class="mt-3">{% include "bootstrap5/errors.html" %}</div>
{% elif documents != None %}
{% include "search/_search_results.html" %}
{% else %}
{% include "search/_search_info.html" %}
{% endif %}
</div>
<div class="col col-auto">
<div id="filters" class="card mt-3">
Expand Down
3 changes: 1 addition & 2 deletions radis/search/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns

from .views import InfoView, SearchView
from .views import SearchView

urlpatterns = [
path("", SearchView.as_view(), name="search"),
path("info", InfoView.as_view(), name="search_info"),
]

urlpatterns = format_suffix_patterns(urlpatterns)
21 changes: 0 additions & 21 deletions radis/search/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Any

from adit_radis_shared.common.mixins import HtmxOnlyMixin
from adit_radis_shared.common.types import AuthenticatedHttpRequest
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.core.exceptions import ValidationError
from django.core.paginator import Paginator
from django.http import Http404, HttpRequest
from django.shortcuts import render
Expand Down Expand Up @@ -42,7 +40,6 @@ def get(self, request: AuthenticatedHttpRequest, *args, **kwargs):

search_provider = search_providers[provider]
context["selected_provider"] = search_provider.name
context["info_template"] = search_provider.info_template

page_number = self.get_page_number(request)
page_size: int = self.get_page_size(request)
Expand Down Expand Up @@ -115,21 +112,3 @@ def get_page_size(self, request: HttpRequest) -> int:
except ValueError:
page_size = 10
return page_size


class InfoView(LoginRequiredMixin, HtmxOnlyMixin, View):
def post(self, request: AuthenticatedHttpRequest, *args, **kwargs):
provider_name = request.POST.get("provider", "")
provider = search_providers.get(provider_name)

if not provider:
raise ValidationError(f"Invalid search provider: {provider_name}")

return render(
request,
"search/_search_info.html",
{
"selected_provider": provider_name,
"info_template": provider.info_template,
},
)
4 changes: 0 additions & 4 deletions radis/vespa/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def fetch_vespa_document(report: Report) -> dict[str, Any]:
name="Vespa Hybrid Ranking",
search=search_hybrid,
max_results=MAX_SEARCH_HITS,
info_template="vespa/_hybrid_info.html",
)
)

Expand All @@ -80,7 +79,6 @@ def fetch_vespa_document(report: Report) -> dict[str, Any]:
name="Vespa BM25 Ranking",
search=search_bm25,
max_results=MAX_SEARCH_HITS,
info_template="vespa/_bm25_info.html",
)
)

Expand All @@ -89,7 +87,6 @@ def fetch_vespa_document(report: Report) -> dict[str, Any]:
name="Vespa Semantic Ranking",
search=search_semantic,
max_results=MAX_SEARCH_HITS,
info_template="vespa/_bm25_info.html",
)
)

Expand All @@ -99,6 +96,5 @@ def fetch_vespa_document(report: Report) -> dict[str, Any]:
count=count_bm25,
retrieve=retrieve_bm25,
max_results=MAX_RETRIEVAL_HITS,
info_template="vespa/_bm25_info.html",
)
)
5 changes: 0 additions & 5 deletions radis/vespa/templates/vespa/_bm25_info.html

This file was deleted.

6 changes: 0 additions & 6 deletions radis/vespa/templates/vespa/_hybrid_info.html

This file was deleted.

9 changes: 0 additions & 9 deletions radis/vespa/templates/vespa/_query_rules.html

This file was deleted.

0 comments on commit 4b0b98c

Please sign in to comment.