Skip to content

Commit

Permalink
search: Replace AND default operator by OR.
Browse files Browse the repository at this point in the history
* Adds a new display_score url parameters `display_score=1`.
* Restore OR default search operator, closes #384.
* Improves Elasticsearch mappings and JSONSchema for documents:
  * two JSONSchema: one minimal for havested records and one for
  internal record.
  * unique elasticsearch mapping
* Put cantook and internal records in the same Elasticsearch index.
* Improves search page layout.
* Improves serializers permissions, closes #89.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
jma and Garfield-fr committed Jul 12, 2019
1 parent b85e5b5 commit 7a7543c
Show file tree
Hide file tree
Showing 29 changed files with 305 additions and 385 deletions.
12 changes: 7 additions & 5 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
can_create_organisation_records_factory, \
can_delete_organisation_records_factory, \
can_update_organisation_records_factory, \
librarian_delete_permission_factory, librarian_permission_factory
librarian_delete_permission_factory, librarian_permission_factory, \
librarian_update_permission_factory


def _(x):
Expand Down Expand Up @@ -321,7 +322,7 @@ def _(x):
RECORDS_REST_DEFAULT_READ_PERMISSION_FACTORY = librarian_permission_factory
"""Default read permission factory: check if the record exists."""

RECORDS_REST_DEFAULT_UPDATE_PERMISSION_FACTORY = librarian_permission_factory
RECORDS_REST_DEFAULT_UPDATE_PERMISSION_FACTORY = librarian_update_permission_factory
"""Default update permission factory: reject any request."""

RECORDS_REST_DEFAULT_DELETE_PERMISSION_FACTORY = librarian_delete_permission_factory
Expand Down Expand Up @@ -363,7 +364,7 @@ def _(x):
# ),
default_media_type='application/json',
max_result_window=5000000,
search_factory_imp='rero_ils.query:and_search_factory',
search_factory_imp='rero_ils.query:search_factory',
read_permission_factory_imp=allow_all,
list_permission_factory_imp=allow_all
),
Expand Down Expand Up @@ -522,7 +523,7 @@ def _(x):
item_route='/organisations/<pid(org, record_class="rero_ils.modules.organisations.api:Organisation"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:and_search_factory',
search_factory_imp='rero_ils.query:search_factory',
create_permission_factory_imp=deny_all,
update_permission_factory_imp=deny_all,
delete_permission_factory_imp=deny_all,
Expand Down Expand Up @@ -615,7 +616,7 @@ def _(x):
item_route='/persons/<pid(pers, record_class="rero_ils.modules.mef_persons.api:MefPerson"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:and_search_factory',
search_factory_imp='rero_ils.query:search_factory',
read_permission_factory_imp=allow_all,
list_permission_factory_imp=allow_all,
create_permission_factory_imp=deny_all,
Expand Down Expand Up @@ -932,6 +933,7 @@ def _(x):

# Misc
INDEXER_REPLACE_REFS = True
INDEXER_RECORD_TO_INDEX = 'rero_ils.modules.indexer_utils.record_to_index'

SEARCH_UI_SEARCH_API = '/api/documents/'

Expand Down
9 changes: 8 additions & 1 deletion rero_ils/modules/documents/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ class Document(IlsRecord):
fetcher = document_id_fetcher
provider = DocumentProvider

@property
def harvested(self):
"""Is this record harvested from an external service."""
return bool(self.get('identifiers', {}).get('harvestedID'))

@property
def can_edit(self):
"""Return a boolean for can_edit resource."""
# TODO: Make this condition on data
return 'ebook' != self.get('type')
return not self.harvested

def get_number_of_items(self):
"""Get number of items for document."""
Expand Down Expand Up @@ -106,4 +111,6 @@ def reasons_not_to_delete(self):
links = self.get_links_to_me()
if links:
cannot_delete['links'] = links
if self.harvested:
cannot_delete['others'] = dict(harvested=True)
return cannot_delete
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Schema for ebooks document",
"title": "Schema for document",
"type": "object",
"required": [
"$schema",
"pid",
"type",
"title"
"title",
"languages"
],
"additionalProperties": false,
"properties": {
"$schema": {
"title": "Schema",
"description": "Schema to validate document against.",
"type": "string",
"minLength": 7
"minLength": 7,
"default": "https://ils.rero.ch/schema/documents/document-minimal-v0.0.1.json"
},
"pid": {
"title": "Document ID",
Expand Down Expand Up @@ -76,6 +78,7 @@
"title": "Language",
"description": "Required. Language of the resource, primary or not.",
"type": "string",
"default": "fre",
"validationMessage": "Required. Language of the resource, primary or not.",
"enum": [
"fre",
Expand All @@ -89,8 +92,7 @@
"heb",
"jpn",
"por",
"rus",
"und"
"rus"
]
}
}
Expand All @@ -107,37 +109,29 @@
"validationMessage": "Should be in the ISO 639 format, with 3 characters, ie <code>eng</code> for English."
}
},
"electronic_location": {
"title": "Electronic Location",
"description": "Information needed to locate and access an electronic resource.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"uri"
],
"uri": {
"title": "Uniform Resource Identifier",
"description": "Uniform Resource Identifier (URI), which provides standard syntax for locating an object using existing Internet protocols.",
"type": "string",
"format": "uri"
}
}
},
"authors": {
"title": "Authors",
"description": "Author(s) of the resource. Can be either persons or organisations.",
"type": "array",
"minItems": 1,
"minItems": 0,
"items": {
"type": "object",
"required": [
"name",
"type"
],
"additionalProperties": false,
"properties": {
"$ref": {
"title": "MEF person ref",
"type": "string",
"pattern": "^https://mef.rero.ch/api/mef/.*?$"
},
"pid": {
"title": "pid",
"description": "Corresponding pid of the MEF record.",
"type": "string",
"minLength": 1
},
"name": {
"title": "Name",
"description": "Person's or organisation's name.",
Expand Down Expand Up @@ -311,12 +305,12 @@
"pattern": "^97[8|9][0-9]{10}$",
"validationMessage": "Should be a valid ISBN-13 without dashes."
},
"oai": {
"title": "OAI",
"harvestedID": {
"title": "Identifier in the harvested source.",
"description": "OAI identifiers of the harvested source.",
"type": "string",
"pattern": "^oai:.*",
"validationMessage": "Should be a valid ISBN-13 without dashes."
"pattern": "^[a-z]+:.*",
"validationMessage": "Should start with a chars: prefix i.e. cantook:."
}
}
},
Expand All @@ -330,16 +324,29 @@
"minLength": 1
}
},
"available": {
"title": "Document availability",
"type": "boolean",
"default": false
},
"cover_art": {
"title": "Cover art",
"description": "Vendor cover art URL.",
"type": "string",
"format": "uri"
},
"electronic_location": {
"title": "Electronic Location",
"description": "Information needed to locate and access an electronic resource.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"uri"
],
"uri": {
"title": "Uniform Resource Identifier",
"description": "Uniform Resource Identifier (URI), which provides standard syntax for locating an object using existing Internet protocols.",
"type": "string",
"format": "uri"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@
"type": "string",
"pattern": "^97[8|9][0-9]{10}$",
"validationMessage": "Should be a valid ISBN-13 without dashes."
},
"harvestedID": {
"title": "Identifier in the harvested source.",
"description": "OAI identifiers of the harvested source.",
"type": "string",
"pattern": "^[a-z]+:.*",
"validationMessage": "Should start with a chars: prefix i.e. cantook:."
}
}
},
Expand All @@ -316,6 +323,30 @@
"type": "string",
"minLength": 1
}
},
"cover_art": {
"title": "Cover art",
"description": "Vendor cover art URL.",
"type": "string",
"format": "uri"
},
"electronic_location": {
"title": "Electronic Location",
"description": "Information needed to locate and access an electronic resource.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"uri"
],
"uri": {
"title": "Uniform Resource Identifier",
"description": "Uniform Resource Identifier (URI), which provides standard syntax for locating an object using existing Internet protocols.",
"type": "string",
"format": "uri"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
},
"mappings": {
"document-v0.0.1": {
"document": {
"date_detection": false,
"numeric_detection": false,
"properties": {
Expand Down
Loading

0 comments on commit 7a7543c

Please sign in to comment.