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

rest api: add simple query support #973

Merged
merged 1 commit into from
May 15, 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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include .tx/config
include docker/haproxy/Dockerfile
include docker/nginx/Dockerfile
include docker/postgres/Dockerfile
include docker/elasticsearch/Dockerfile
include Dockerfile
exclude scripts/all_year_days
include scripts/bootstrap
Expand Down
3 changes: 2 additions & 1 deletion docker-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ services:
- "15672:15672"
- "5672:5672"
es:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.2
build: ./docker/elasticsearch/
image: elasticsearch-icu
restart: "always"
environment:
- bootstrap.memory_lock=true
Expand Down
2 changes: 2 additions & 0 deletions docker/elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.2
RUN bin/elasticsearch-plugin install analysis-icu
48 changes: 24 additions & 24 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
ItemAtDeskToItemOnLoan, ItemOnLoanToItemInTransitHouse, \
ItemOnLoanToItemOnLoan, PendingToItemAtDesk, \
PendingToItemInTransitPickup, ToItemOnLoan
from invenio_records_rest.facets import terms_filter
from invenio_records_rest.utils import allow_all, deny_all

from .modules.acq_accounts.api import AcqAccount
Expand Down Expand Up @@ -95,6 +94,7 @@
librarian_delete_permission_factory, librarian_permission_factory, \
librarian_update_permission_factory, wiki_edit_ui_permission, \
wiki_edit_view_permission
from .query import and_term_filter
from .utils import get_current_language


Expand Down Expand Up @@ -1180,18 +1180,18 @@ def _(x):
)
),
filters={
_('document_type'): terms_filter('type'),
_('organisation'): terms_filter(
_('document_type'): and_term_filter('type'),
_('organisation'): and_term_filter(
'holdings.organisation.organisation_pid'
),
_('library'): terms_filter('holdings.organisation.library_pid'),
_('author__en'): terms_filter('facet_authors_en'),
_('author__fr'): terms_filter('facet_authors_fr'),
_('author__de'): terms_filter('facet_authors_de'),
_('author__it'): terms_filter('facet_authors_it'),
_('language'): terms_filter('language.value'),
_('subject'): terms_filter('facet_subjects'),
_('status'): terms_filter('holdings.items.status'),
_('library'): and_term_filter('holdings.organisation.library_pid'),
_('author__en'): and_term_filter('facet_authors_en'),
_('author__fr'): and_term_filter('facet_authors_fr'),
_('author__de'): and_term_filter('facet_authors_de'),
_('author__it'): and_term_filter('facet_authors_it'),
_('language'): and_term_filter('language.value'),
_('subject'): and_term_filter('facet_subjects'),
_('status'): and_term_filter('holdings.items.status'),
}
),
patrons=dict(
Expand All @@ -1207,7 +1207,7 @@ def _(x):
)
),
filters={
_('roles'): terms_filter('roles')
_('roles'): and_term_filter('roles')
},
),
acq_accounts=dict(
Expand All @@ -1228,8 +1228,8 @@ def _(x):
)
),
filters={
_('library'): terms_filter('library.pid'),
_('budget'): terms_filter('budget')
_('library'): and_term_filter('library.pid'),
_('budget'): and_term_filter('budget')
},
),
acq_invoices=dict(
Expand All @@ -1250,8 +1250,8 @@ def _(x):
)
),
filters={
_('library'): terms_filter('library.pid'),
_('status'): terms_filter('invoice_status')
_('library'): and_term_filter('library.pid'),
_('status'): and_term_filter('invoice_status')
},
),
acq_orders=dict(
Expand All @@ -1272,8 +1272,8 @@ def _(x):
)
),
filters={
_('library'): terms_filter('library.pid'),
_('status'): terms_filter('order_status')
_('library'): and_term_filter('library.pid'),
_('status'): and_term_filter('order_status')
},
),
persons=dict(
Expand All @@ -1289,15 +1289,15 @@ def _(x):
)
),
filters={
_('sources'): terms_filter('sources')
_('sources'): and_term_filter('sources')
}
),
)

# Elasticsearch fields boosting by index
RERO_ILS_QUERY_BOOSTING = {
'documents': {
'title.*': 3,
'title._text.*': 3,
'titlesProper.*': 3,
'authors.name': 2,
'authors.name_*': 2,
Expand Down Expand Up @@ -1355,7 +1355,7 @@ def _(x):

# ------ BUDGETS SORT
RECORDS_REST_SORT_OPTIONS['budgets']['name'] = dict(
fields=['name'], title='Budget name',
fields=['budget_name'], title='Budget name',
default_order='asc'
)
RECORDS_REST_DEFAULT_SORT['budgets'] = dict(
Expand All @@ -1379,7 +1379,7 @@ def _(x):

# ------ LIBRARIES SORT
RECORDS_REST_SORT_OPTIONS['libraries']['name'] = dict(
fields=['name_sort'], title='Library name',
fields=['library_name'], title='Library name',
default_order='asc'
)
RECORDS_REST_DEFAULT_SORT['libraries'] = dict(
Expand All @@ -1395,11 +1395,11 @@ def _(x):

# ------ LOCATIONS SORT
RECORDS_REST_SORT_OPTIONS['locations']['name'] = dict(
fields=['name'], title='Location name',
fields=['location_name'], title='Location name',
default_order='asc'
)
RECORDS_REST_SORT_OPTIONS['locations']['pickup_name'] = dict(
fields=['pickup_name'], title='Pickup Location name',
fields=['pickup_name.keyword'], title='Pickup Location name',
default_order='asc'
)
RECORDS_REST_DEFAULT_SORT['locations'] = dict(
Expand Down
47 changes: 45 additions & 2 deletions rero_ils/es_templates/v6/record.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
"index_patterns": "*",
"settings": {
"analysis": {
"filter": {
"french_elision": {
"type": "elision",
"articles_case": true,
"articles": [
"l",
"m",
"t",
"qu",
"n",
"s",
"j",
"d",
"c",
"jusqu",
"quoiqu",
"lorsqu",
"puisqu"
]
},
"french_stemmer": {
"type": "stemmer",
"language": "light_french"
}
},
"tokenizer": {
"char_group_tokenizer": {
"type": "char_group",
Expand All @@ -12,12 +37,30 @@
}
},
"analyzer": {
"global_lowercase_asciifolding": {
"custom_keyword": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase",
"icu_folding",
"german_normalization"
]
},
"french": {
"tokenizer": "icu_tokenizer",
"filter": [
"french_elision",
"icu_folding",
"french_stemmer"
]
},
"default": {
"type": "custom",
"tokenizer": "char_group_tokenizer",
"filter": [
"lowercase",
"asciifolding"
"icu_folding",
"german_normalization"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"type": "keyword"
},
"name": {
"type": "keyword"
"type": "text"
},
"description": {
"type": "keyword"
"type": "text"
},
"budget": {
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"type": "keyword"
},
"name": {
"type": "text"
},
"budget_name": {
"type": "keyword"
},
"start_date": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
},
"name": {
"type": "text",
"copy_to": "circ_policy_name",
"analyzer": "global_lowercase_asciifolding"
"copy_to": "circ_policy_name"
},
"circ_policy_name": {
"type": "keyword"
},
"description": {
"type": "text",
"analyzer": "global_lowercase_asciifolding"
"type": "text"
},
"organisation": {
"properties": {
Expand Down Expand Up @@ -99,4 +97,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@
"minItems": 1,
"items": {
"type": "string",
"minLength": 1,
"form": {
"placeholder": "Example: Access only from the library"
}
Expand Down
Loading