Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES: fix mapping #705

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ celerybeat-schedule
# Coverage xml file
cov.xml

# these json files are generated during the setup
# these json files are generated during bootstrap or run-test
rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1.json
rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1.json

# ES mapping files
tmp/
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ recursive-include rero_ils *.po *.pot *.mo
recursive-include docker *.cfg *.conf *.crt *.ini *.key *.pem *.sh
exclude rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1.json
exclude rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1.json
# ES mappings
exclude mapping_after_setup.txt
exclude mapping_before_setup.txt

# added by check_manifest.py
include *.base
Expand Down
20 changes: 20 additions & 0 deletions rero_ils/modules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,3 +1324,23 @@ def run_tests(self, tests):
dependency_tests.run_tests(tests)

sys.exit(dependency_tests.missing + dependency_tests.not_found)


@utils.command('dump_es_mappings')
@click.option('-v', '--verbose', 'verbose', is_flag=True, default=False)
@click.option('-o', '--outfile', 'outfile', type=click.File('w'), default=None)
@with_appcontext
def dump_es_mappings(verbose, outfile):
"""Dumps ES mappings."""
click.secho('Dump ES mappings:', fg='green')
aliases = current_search.client.indices.get_alias('*')
mappings = current_search.client.indices.get_mapping()
for alias in sorted(aliases):
if alias[0] != '.':
mapping = mappings.get(alias, {}).get('mappings')
click.echo('{alias}'.format(alias=alias))
if verbose or not outfile:
print(json.dumps(mapping, indent=2))
if outfile:
json.dump(mapping, outfile, indent=2)
outfile.write('\n')
12 changes: 0 additions & 12 deletions rero_ils/modules/documents/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

"""Signals connector for Document."""

from .views import create_publication_statement
from ..documents.api import DocumentsSearch
from ..holdings.api import Holding, HoldingsSearch
from ..items.api import ItemsSearch
Expand Down Expand Up @@ -78,17 +77,6 @@ def enrich_document_data(sender, json=None, record=None, index=None,
if holdings:
json['holdings'] = holdings

# provisionActivity
publisher_statements = []
for provision_activity in record.get('provisionActivity', []):
publication_statement = create_publication_statement(
provision_activity
).get('default')
if publication_statement:
publisher_statements.append(publication_statement)
if publisher_statements:
json['publisherStatement'] = publisher_statements

# MEF person ES index update
authors = []
for author in json.get('authors', []):
Expand Down
26 changes: 17 additions & 9 deletions rero_ils/modules/documents/mappings/v6/documents/document.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@
"properties": {
"_text": {
"properties": {
"default": {
"value": {
"type": "text"
},
"language": {
"type": "keyword"
}
}
},
Expand Down Expand Up @@ -245,9 +248,6 @@
"statement": {
"type": "object",
"properties": {
"type": {
"type": "text"
},
"label": {
"type": "object",
"properties": {
Expand All @@ -259,6 +259,9 @@
"type": "keyword"
}
}
},
"type": {
"type": "text"
}
}
},
Expand All @@ -274,19 +277,21 @@
"type": "date",
"format": "yyyy"
},
"type": {
"type": "text"
},
"_text": {
"properties": {
"default": {
"value": {
"type": "text"
},
"language": {
"type": "keyword"
}
}
}
}
},
"publisherStatement": {
"type": "keyword",
"index": false
},
"extent": {
"type": "text",
"analyzer": "global_lowercase_asciifolding"
Expand Down Expand Up @@ -435,6 +440,9 @@
"pid": {
"type": "keyword"
},
"available": {
"type": "boolean"
},
"call_number": {
"type": "keyword"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ <h1 class="col-sm-10 col-md-11">{{ record.title }}</h1>

<!-- EDITION STATEMENT-->
{% if record.editionStatement %}
{{ dl_list(_('Edition'), record.editionStatement | edition_format) }}
{{ dl_list(_('Edition'), record.editionStatement|edition_format) }}
{% endif %}

<!-- PUBLICATION STATEMENT -->
{% for provision_activity in record.provisionActivity %}
{{ dl_dict(_(provision_activity.type), provision_activity|create_publication_statement ) }}
{{ dl_list(_(provision_activity.type), provision_activity|create_publication_statement ) }}
{% endfor %}

<!-- COPYRIGHT DATE -->
Expand Down
21 changes: 14 additions & 7 deletions rero_ils/modules/documents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ def publication_statement_text(provision_activity):
statement_type = statement['type']

# date field: remove ';' and append
statement_text = []
for key, value in statement_with_language.items():
value = remove_trailing_punctuation(value)
statement_with_language[key] = value
return statement_with_language
if key == 'default':
statement_text.insert(0, {'value': value, 'language': key})
else:
statement_text.append({'value': value, 'language': key})
return statement_text


def series_format_text(serie):
Expand All @@ -101,7 +105,6 @@ def series_format_text(serie):

def edition_format_text(edition):
"""Format edition for _text."""
edition_with_language = {'default': ''}
designations = edition.get('editionDesignation', [])
responsibilities = edition.get('responsibility', [])
designation_output = {}
Expand All @@ -115,13 +118,17 @@ def edition_format_text(edition):
value = responsibility.get('value', '')
responsibility_output[language] = value

edition_text = []
for key, value in designation_output.items():
output_value = remove_trailing_punctuation(
value = remove_trailing_punctuation(
'{designation} / {responsibility}'.format(
designation=value,
designation=designation_output.get(key),
responsibility=responsibility_output.get(key, ''),
)
)
edition_with_language[key] = output_value
if key == 'default':
edition_text.insert(0, {'value': value, 'language': key})
else:
edition_text.append({'value': value, 'language': key})

return edition_with_language
return edition_text
12 changes: 7 additions & 5 deletions rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,8 @@ def edition_format(editions):
for edition in editions:
languages = edition_format_text(edition)
if languages:
output.append(languages['default'])
del languages['default']
for key, value in languages.items():
output.append(value)
for edition_text in languages:
output.append(edition_text.get('value'))
return output


Expand Down Expand Up @@ -431,4 +429,8 @@ def document_availability(document_pid):
@blueprint.app_template_filter()
def create_publication_statement(provision_activity):
"""Create publication statement from place, agent and date values."""
return publication_statement_text(provision_activity)
output = []
publication_texts = publication_statement_text(provision_activity)
for publication_text in publication_texts:
output.append(publication_text.get('value'))
return output
7 changes: 7 additions & 0 deletions rero_ils/modules/fees/mappings/v6/fees/fee-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"fee_type": {
"type": "keyword"
},
"organisation": {
"properties": {
"pid": {
"type": "keyword"
}
}
},
"notification": {
"properties": {
"pid": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
}
}
},
"library": {
"properties": {
"pid": {
"type": "keyword"
}
}
},
"organisation": {
"properties": {
"pid": {
"type": "keyword"
}
}
},
"_created": {
"type": "date"
},
Expand All @@ -59,4 +73,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
},
"period": {
"type": "keyword"
},
"data": {
"type": "long"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions rero_ils/modules/loans/mappings/v6/loans/loan-ils-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"end_date": {
"type": "date"
},
"extension_count": {
"type": "long"
},
"state": {
"type": "keyword"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
}
}
},
"organisation": {
"properties": {
"pid": {
"type": "keyword"
}
}
},
"_created": {
"type": "date"
},
Expand All @@ -46,4 +53,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
}
}
},
"organisation": {
"properties": {
"pid": {
"type": "keyword"
}
}
},
"_created": {
"type": "date"
},
Expand Down
31 changes: 31 additions & 0 deletions rero_ils/modules/vendors/mappings/v6/vendors/vendor-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@
"vendor_name": {
"type": "keyword"
},
"note": {
"type": "text"
},
"website": {
"type": "text"
},
"currency": {
"type": "keyword"
},
"communication_language": {
"type": "keyword"
},
"tva_rate": {
"type": "keyword"
},
Expand All @@ -36,6 +45,28 @@
}
}
},
"default_contact": {
"properties": {
"city": {
"type": "keyword"
},
"country": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"phone": {
"type": "keyword"
},
"postal_code": {
"type": "keyword"
},
"street": {
"type": "text"
}
}
},
"_created": {
"type": "date"
},
Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ if [ "$1" = "external" ]
fi

success_msg "Perfect ${PROGRAM}! See you soon…"
exit 0
exit 0
Loading