Browse Source

Muda o backend para Solr

Edward Ribeiro 7 years ago
parent
commit
dea2500d80
  1. 8
      docker-compose.yml
  2. 12
      sapl/base/search_indexes.py
  3. 20
      sapl/settings.py
  4. 3
      start.sh

8
docker-compose.yml

@ -24,7 +24,7 @@ services:
- "8983:8983"
sapl:
image: interlegis/sapl:3.1.106-ALPHA
image: interlegis/sapl:3.1.112-ALPHA
# build: .
restart: always
environment:
@ -36,8 +36,10 @@ services:
EMAIL_HOST: smtp.dominio.net
EMAIL_HOST_USER: usuariosmtp
EMAIL_HOST_PASSWORD: senhasmtp
SOLR_COLLECTION: sapl
SOLR_HOST: 10.1.10.192
USE_SOLR: 'True'
#SOLR_COLLECTION: sapl
#SOLR_HOST: saplsolr
SOLR_URL: http://saplsolr:8983/solr/sapl
TZ: America/Sao_Paulo
volumes:
- sapl_data:/var/interlegis/sapl/data

12
sapl/base/search_indexes.py

@ -29,6 +29,8 @@ logger = logging.getLogger(BASE_DIR.name)
class TextExtractField(CharField):
backend = None
def __init__(self, **kwargs):
super().__init__(**kwargs)
assert self.model_attr
@ -37,11 +39,11 @@ class TextExtractField(CharField):
self.model_attr = (self.model_attr, )
def solr_extraction(self, arquivo):
backend = connections['default'].get_backend()
if not self.backend:
self.backend = connections['default'].get_backend()
try:
with open(arquivo.path, 'rb') as f:
data = backend.extract_file_contents(f)['contents']
print('.')
data = self.backend.extract_file_contents(f)['contents']
except Exception as e:
self.print_error(arquivo, e)
data = ''
@ -126,7 +128,9 @@ class TextExtractField(CharField):
value = getattr(obj, attr)
if not value:
continue
data += getattr(self, func)(value)
data += getattr(self, func)(value) + ' '
data = data.replace('\n', ' ')
return data

20
sapl/settings.py

@ -108,16 +108,16 @@ if USE_SOLR:
SEARCH_BACKEND = 'haystack.backends.solr_backend.SolrEngine'
if SOLR_URL:
SEARCH_URL = ('URL', SOLR_URL)
# elif SOLR_HOST and SOLR_COLLECTION:
# SEARCH_URL = ('URL', 'http://{}:8983/solr/{}'.format(SOLR_HOST, SOLR_COLLECTION))
# # elif SOLR_HOST:
# # SEARCH_URL = ('URL', 'http://{}:8983/solr/sapl'.format(SOLR_HOST))
# # elif SOLR_CORE:
# # SEARCH_URL = ('URL', 'http://localhost:8983/solr/sapl'.format(SOLR_COLLECTION))
# else:
# SEARCH_URL = ('URL', 'http://localhost:8983/solr/sapl')
#
print("Solr URL: {}".format(SEARCH_URL[1]))
elif SOLR_HOST and SOLR_COLLECTION:
SEARCH_URL = ('URL', 'http://{}:8983/solr/{}'.format(SOLR_HOST, SOLR_COLLECTION))
elif SOLR_HOST and not SOLR_COLLECTION:
SEARCH_URL = ('URL', 'http://{}:8983/solr/sapl'.format(SOLR_HOST))
elif SOLR_COLLECTION and not SOLR_HOST:
SEARCH_URL = ('URL', 'http://localhost:8983/solr/sapl'.format(SOLR_COLLECTION))
else:
SEARCH_URL = ('URL', 'http://localhost:8983/solr/sapl')
# print("Solr URL: {}".format(SEARCH_URL[1]))
# ...or for multicore...
# 'URL': 'http://127.0.0.1:8983/solr/mysite',

3
start.sh

@ -36,6 +36,9 @@ create_env() {
echo "EMAIL_SEND_USER = ""${EMAIL_HOST_USER-''}" >> $FILENAME
echo "DEFAULT_FROM_EMAIL = ""${EMAIL_HOST_USER-''}" >> $FILENAME
echo "SERVER_EMAIL = ""${EMAIL_HOST_USER-''}" >> $FILENAME
echo "USE_SOLR = ""${USER_SOLR-True}" >> $FILENAME
echo "SOLR_HOST = ""${SOLR_HOST-'saplsolr'}" >> $FILENAME
echo "SOLR_COLLECTION = ""${SOLR_COLLECTION-'sapl'}" >> $FILENAME
echo "SOLR_URL = ""${SOLR_URL-'http://saplsolr:8983/solr/sapl'}" >> $FILENAME

Loading…
Cancel
Save