diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index 359fbd44b..976c605c9 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -7,7 +7,8 @@ from django.db.models.functions import Concat from django.template import loader from haystack import connections from haystack.constants import Indexable -from haystack.fields import CharField +from haystack.fields import CharField, IntegerField, FacetCharField, \ + FacetIntegerField, FacetDateField from haystack.indexes import SearchIndex from haystack.utils import get_model_ct_tuple @@ -119,6 +120,8 @@ class TextExtractField(CharField): class DocumentoAcessorioIndex(SearchIndex, Indexable): model = DocumentoAcessorio + tipo = FacetCharField(model_attr='tipo__descricao') + data = FacetDateField(model_attr='data') text = TextExtractField( document=True, use_template=True, model_attr=( @@ -144,6 +147,9 @@ class DocumentoAcessorioIndex(SearchIndex, Indexable): class NormaJuridicaIndex(DocumentoAcessorioIndex): model = NormaJuridica + ano = FacetIntegerField(model_attr='ano') + tipo = FacetCharField(model_attr='tipo__sigla') + data = FacetDateField(model_attr='data', null=True) text = TextExtractField( document=True, use_template=True, model_attr=( @@ -158,6 +164,9 @@ class NormaJuridicaIndex(DocumentoAcessorioIndex): class MateriaLegislativaIndex(DocumentoAcessorioIndex): model = MateriaLegislativa + ano = FacetIntegerField(model_attr='ano') + tipo = FacetCharField(model_attr='tipo__sigla') + data = FacetDateField(model_attr='data_publicacao') text = TextExtractField( document=True, use_template=True, model_attr=( diff --git a/sapl/base/views.py b/sapl/base/views.py index 91b1523bf..c274eb9c4 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -28,7 +28,8 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import (CreateView, DetailView, DeleteView, FormView, ListView, UpdateView) from django.views.generic.base import RedirectView, TemplateView from django_filters.views import FilterView -from haystack.views import SearchView +from haystack.forms import FacetedSearchForm, FacetedModelSearchForm +from haystack.views import SearchView, FacetedSearchView from haystack.query import SearchQuerySet from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor, @@ -2207,8 +2208,10 @@ class AppConfigCrud(CrudAux): return HttpResponseRedirect(reverse('sapl.base:appconfig_create')) -class SaplSearchView(SearchView): +class SaplSearchView(FacetedSearchView): results_per_page = 10 + facet_fields = ['ano', 'tipo'] + form_class = FacetedModelSearchForm def get_context(self): context = super(SaplSearchView, self).get_context() diff --git a/solr/sapl_configset/conf/managed-schema b/solr/sapl_configset/conf/managed-schema index b6ecffaaf..b3e4a97d4 100644 --- a/solr/sapl_configset/conf/managed-schema +++ b/solr/sapl_configset/conf/managed-schema @@ -120,6 +120,9 @@ + + + - - + + - + + + + + + + + + + text + \s+ + + true +