Commit 20f69886 authored by felix.herrmann's avatar felix.herrmann
Browse files

Merge branch '142-search-documentation-help' into 'master'

Resolve "search documentation/help"

Closes #142

See merge request !234
parents 630e854a 37856a57
......@@ -364,6 +364,18 @@ ELASTICSEARCH_DSL = {
"default": {"hosts": "elasticsearch:9200"},
}
WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtail.search.backends.elasticsearch7",
"URLS": ["http://elasticsearch:9200"],
"INDEX": "wagtail",
"TIMEOUT": 5,
"OPTIONS": {},
"INDEX_SETTINGS": {},
}
}
RUNSCRIPT_SCRIPT_DIR = "djangoscripts"
# basic bleach configuration
......
......@@ -12,4 +12,5 @@ urlpatterns = [
path("polling/stop/", views.polling_stop, name="polling_stop"),
path("load/", views.load, name="load"),
path("messages/", views.messages, name="messages"),
path("search/", views.help_search, name="help_search"),
]
......@@ -14,10 +14,15 @@ from discuss_data.core.models import KeywordTagged
from discuss_data.dddatasets.models import Category
from discuss_data.ddusers.models import Country
from discuss_data.pages.models import LandingPage, ManualPage, TextPage
from wagtail.core.models import Page
logger = logging.getLogger(__name__)
def help_search(request):
return core_search_view(request, "help_index", 10)
def index_search(index, term, **kwargs):
"""
Using elastic simple_query_string with default wildcard attached, default AND
......@@ -130,7 +135,7 @@ def core_search_view(request, search_index, objects_on_page):
dataset_management_object__main_published_ds_id=F("id")
)
else:
elif search_index == "user_index":
# default search index is user_index
template = "ddusers/_search_results.html"
queryset = index_search(
......@@ -142,6 +147,11 @@ def core_search_view(request, search_index, objects_on_page):
.exclude(last_name="")
.exclude(username="AnonymousUser")
)
elif search_index == "help_index":
template = "pages/_search_results.html"
queryset = Page.objects.live().search(query)
else:
print("no search index given")
pagination = False
paginator_range = None
......
# Generated by Django 2.2.14 on 2020-09-03 10:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0022_auto_20200902_1111'),
]
operations = [
migrations.AddField(
model_name='manualpage',
name='search_index_exclude',
field=models.BooleanField(default=False),
),
]
......@@ -54,12 +54,23 @@ class ManualPage(Page):
intro = models.CharField(max_length=256, blank=True, null=True)
body = StreamField([("topic", ManualTopicBlock())], blank=True, null=True)
search_index_exclude = models.BooleanField(default=False)
content_panels = Page.content_panels + [
FieldPanel("intro"),
FieldPanel("search_index_exclude"),
StreamFieldPanel("body"),
]
search_fields = Page.search_fields + [ # Inherit search_fields from Page
index.SearchField("intro"),
index.SearchField("body"),
]
@classmethod
def get_indexed_objects(cls):
return cls.objects.filter(search_index_exclude=False)
def class_name(self):
return self.__class__.__name__
......
......@@ -14,5 +14,9 @@
{# dataset_index #}
<input type="radio" value="dataset_index" aria-label="{% trans 'Datasets' %}" {% if filter_applied == 'dataset_index' %} checked{% else %}ic-get-from="{% url 'dddatasets:search' %}" ic-push-url="true" ic-push-params="q,countries,categories" ic-include=".search-middle" ic-target="#content"{% endif %} id="search-filter-dataset_index" />
<label class="list-group-item" for="search-filter-dataset_index">{% trans 'Datasets' %}</label>
{# help_index #}
<input type="radio" value="help_index" aria-label="{% trans 'Help' %}" {% if filter_applied == 'help_index' %} checked{% else %}ic-get-from="{% url 'core:help_search' %}" ic-push-url="true" ic-push-params="q,countries,categories" ic-include=".search-middle" ic-target="#content"{% endif %} id="search-filter-help_index" />
<label class="list-group-item" for="search-filter-help_index">{% trans 'Help' %}</label>
</div>
</div>
\ No newline at end of file
{% extends request.is_intercooler|yesno:"blank.html,base.html" %}
{% load static i18n core_tags wagtailcore_tags%}
{% block content %}
{% block ic-content %}
<div id="search-list">
<div class="row">
<div class="col-md-9">
<h2>{% trans "Discuss Data Help Search" %}</h2>
{# big search field #}
<div class="input-group mb-3 search-field-main">
<input class="form-control search-field-main search-middle search-data"{% if query %}value="{{ query }}"{% else %}placeholder="Search"{% endif %} name="q" aria-label="Search">
<div class="input-group-append">
<button class="input-group-text search-button" type="button" ic-include=".search-data" ic-get-from="{% url 'core:help_search' %}" ic-target="#content" ic-push-url="true" ic-push-params="q,countries,categories"><i class="fas fa-search"></i></button>
</div>
</div>
{# search object list #}
{% if object_list %}
<p>{% if object_list.paginator %}{{ object_list.paginator.count }}{% else %}{{ object_list.count }}{% endif %} {% trans "Discuss Data Help Pages found" %}</p>
{% for subpage in object_list %}
<div class="card smallskip usercard">
<div class="card-body">
<a href="{% pageurl subpage %}">{{ subpage.title }}</a>
{# <button class="btn btn-link docucard-button no-padding" ic-get-from="{% pageurl subpage %}" ic-push-url="true" ic-target="#ds-content" >{{ subpage.title }}<i class="fa fa-spinner fa-spin ic-indicator" style="display:none"></i></button> #}
</div>
</div>
{% comment %}
{% if search_type %}
{% include 'ddusers/_user_detail_card.html' with object=object image_url=objectimage.url dsid=ds.uuid cardtype=search_type %}
{% else %}
{% include 'ddusers/_user_detail_card.html' with object=object image_url=objectimage.url %}
{% endif %}
{% endcomment %}
{% endfor %}
{# pagination #}
{% if pagination %}
{% include 'core/_pagination.html' with object_list=object_list paginator_range=paginator_range paginator_last_page=paginator_last_page ic_target='#search-list' %}
{% endif %}
{% else %}
{% trans "Nothing found" %}
{% endif %}
</div>
{# filters #}
<div class="col-md-3">
<form class="search-data">
<h2>{% trans "Filters" %}</h2>
{# search_index #}
{% include 'core/_search_index.html' with filters=search_index filters_all=search_index_all filter_applied="help_index" %}
{% comment %}
{# countries #}
{% include 'core/_search_filter.html' with filters=countries filters_all=countries_all filtertype="countries" %}
{# categories #}
{% include 'core/_search_filter.html' with filters=categories filters_all=categories_all filtertype="categories" %}
{% endcomment %}
</form>
</div>
</div>
</div>
{% endblock ic-content %}
{% endblock content %}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment