Browse Source

Implementa busca facetada

faceted-search-2
eribeiro 4 years ago
parent
commit
26b42e1d22
  1. 11
      sapl/base/search_indexes.py
  2. 7
      sapl/base/views.py
  3. 15
      solr/sapl_configset/conf/managed-schema
  4. 9
      solr/sapl_configset/conf/solrconfig.xml

11
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=(

7
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()

15
solr/sapl_configset/conf/managed-schema

@ -120,6 +120,9 @@
<field name="django_ct" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="django_id" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="text" type="text_pt" indexed="true" stored="true" multiValued="false" />
<field name="ano" type="pint" indexed="true" stored="true" multiValued="false" />
<field name="tipo" type="string" indexed="true" stored="true" multiValued="false" />
<field name="data" type="pdate" indexed="true" stored="true" multiValued="false" />
<field name="last_update" type="pdate" indexed="true" stored="true" default="NOW" />
<!-- This can be enabled, in case the client does not know what fields may be searched. It isn't enabled by default
@ -548,16 +551,22 @@
<!-- Portuguese -->
<dynamicField name="*_txt_pt" type="text_pt" indexed="true" stored="true"/>
<fieldType name="text_pt" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_pt.txt" format="snowball" />
<!-- <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_pt.txt" format="snowball" /> -->
<filter class="solr.PortugueseLightStemFilterFactory"/>
<!-- less aggressive: <filter class="solr.PortugueseMinimalStemFilterFactory"/> -->
<!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Portuguese"/> -->
<!-- most aggressive: <filter class="solr.PortugueseStemFilterFactory"/> -->
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<!-- <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_pt.txt" format="snowball" /> -->
<filter class="solr.PortugueseLightStemFilterFactory"/>
</analyzer>
</fieldType>
<!-- Similarity is the scoring routine for each document vs. a query.

9
solr/sapl_configset/conf/solrconfig.xml

@ -1135,7 +1135,7 @@
<updateProcessor class="solr.FieldNameMutatingUpdateProcessorFactory" name="field-name-mutating">
<str name="pattern">[^\w-\.]</str>
<str name="replacement">_</str>
</updateProcessor>
</updateProcessor>=
<updateProcessor class="solr.ParseBooleanFieldUpdateProcessorFactory" name="parse-boolean"/>
<updateProcessor class="solr.ParseLongFieldUpdateProcessorFactory" name="parse-long"/>
<updateProcessor class="solr.ParseDoubleFieldUpdateProcessorFactory" name="parse-double"/>
@ -1193,6 +1193,13 @@
<!-- The update.autoCreateFields property can be turned to false to disable schemaless mode -->
<updateRequestProcessorChain name="main-chain" default="true"
processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date">
<processor class="solr.RegexReplaceProcessorFactory" name="remove-whitespaces">
<str name="fieldName">text</str>
<str name="pattern">\s+</str>
<str name="replacement"> </str>
<bool name="literalReplacement">true</bool>
</processor>
<processor class="solr.LogUpdateProcessorFactory"/>
<processor class="solr.DistributedUpdateProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/>

Loading…
Cancel
Save