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. 13
      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 django.template import loader
from haystack import connections from haystack import connections
from haystack.constants import Indexable 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.indexes import SearchIndex
from haystack.utils import get_model_ct_tuple from haystack.utils import get_model_ct_tuple
@ -119,6 +120,8 @@ class TextExtractField(CharField):
class DocumentoAcessorioIndex(SearchIndex, Indexable): class DocumentoAcessorioIndex(SearchIndex, Indexable):
model = DocumentoAcessorio model = DocumentoAcessorio
tipo = FacetCharField(model_attr='tipo__descricao')
data = FacetDateField(model_attr='data')
text = TextExtractField( text = TextExtractField(
document=True, use_template=True, document=True, use_template=True,
model_attr=( model_attr=(
@ -144,6 +147,9 @@ class DocumentoAcessorioIndex(SearchIndex, Indexable):
class NormaJuridicaIndex(DocumentoAcessorioIndex): class NormaJuridicaIndex(DocumentoAcessorioIndex):
model = NormaJuridica model = NormaJuridica
ano = FacetIntegerField(model_attr='ano')
tipo = FacetCharField(model_attr='tipo__sigla')
data = FacetDateField(model_attr='data', null=True)
text = TextExtractField( text = TextExtractField(
document=True, use_template=True, document=True, use_template=True,
model_attr=( model_attr=(
@ -158,6 +164,9 @@ class NormaJuridicaIndex(DocumentoAcessorioIndex):
class MateriaLegislativaIndex(DocumentoAcessorioIndex): class MateriaLegislativaIndex(DocumentoAcessorioIndex):
model = MateriaLegislativa model = MateriaLegislativa
ano = FacetIntegerField(model_attr='ano')
tipo = FacetCharField(model_attr='tipo__sigla')
data = FacetDateField(model_attr='data_publicacao')
text = TextExtractField( text = TextExtractField(
document=True, use_template=True, document=True, use_template=True,
model_attr=( 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 import (CreateView, DetailView, DeleteView, FormView, ListView, UpdateView)
from django.views.generic.base import RedirectView, TemplateView from django.views.generic.base import RedirectView, TemplateView
from django_filters.views import FilterView 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 haystack.query import SearchQuerySet
from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor, 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')) return HttpResponseRedirect(reverse('sapl.base:appconfig_create'))
class SaplSearchView(SearchView): class SaplSearchView(FacetedSearchView):
results_per_page = 10 results_per_page = 10
facet_fields = ['ano', 'tipo']
form_class = FacetedModelSearchForm
def get_context(self): def get_context(self):
context = super(SaplSearchView, self).get_context() context = super(SaplSearchView, self).get_context()

13
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_ct" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="django_id" 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="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" /> <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 <!-- 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 --> <!-- Portuguese -->
<dynamicField name="*_txt_pt" type="text_pt" indexed="true" stored="true"/> <dynamicField name="*_txt_pt" type="text_pt" indexed="true" stored="true"/>
<fieldType name="text_pt" class="solr.TextField" positionIncrementGap="100"> <fieldType name="text_pt" class="solr.TextField" positionIncrementGap="100">
<analyzer> <analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory"/> <charFilter class="solr.HTMLStripCharFilterFactory"/>
<tokenizer class="solr.StandardTokenizerFactory"/> <tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/> <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"/> <filter class="solr.PortugueseLightStemFilterFactory"/>
<!-- less aggressive: <filter class="solr.PortugueseMinimalStemFilterFactory"/> --> <!-- less aggressive: <filter class="solr.PortugueseMinimalStemFilterFactory"/> -->
<!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Portuguese"/> --> <!-- more aggressive: <filter class="solr.SnowballPorterFilterFactory" language="Portuguese"/> -->
<!-- most aggressive: <filter class="solr.PortugueseStemFilterFactory"/> --> <!-- most aggressive: <filter class="solr.PortugueseStemFilterFactory"/> -->
</analyzer> </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> </fieldType>
<!-- Similarity is the scoring routine for each document vs. a query. <!-- 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"> <updateProcessor class="solr.FieldNameMutatingUpdateProcessorFactory" name="field-name-mutating">
<str name="pattern">[^\w-\.]</str> <str name="pattern">[^\w-\.]</str>
<str name="replacement">_</str> <str name="replacement">_</str>
</updateProcessor> </updateProcessor>=
<updateProcessor class="solr.ParseBooleanFieldUpdateProcessorFactory" name="parse-boolean"/> <updateProcessor class="solr.ParseBooleanFieldUpdateProcessorFactory" name="parse-boolean"/>
<updateProcessor class="solr.ParseLongFieldUpdateProcessorFactory" name="parse-long"/> <updateProcessor class="solr.ParseLongFieldUpdateProcessorFactory" name="parse-long"/>
<updateProcessor class="solr.ParseDoubleFieldUpdateProcessorFactory" name="parse-double"/> <updateProcessor class="solr.ParseDoubleFieldUpdateProcessorFactory" name="parse-double"/>
@ -1193,6 +1193,13 @@
<!-- The update.autoCreateFields property can be turned to false to disable schemaless mode --> <!-- The update.autoCreateFields property can be turned to false to disable schemaless mode -->
<updateRequestProcessorChain name="main-chain" default="true" <updateRequestProcessorChain name="main-chain" default="true"
processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date"> 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.LogUpdateProcessorFactory"/>
<processor class="solr.DistributedUpdateProcessorFactory"/> <processor class="solr.DistributedUpdateProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/> <processor class="solr.RunUpdateProcessorFactory"/>

Loading…
Cancel
Save