Bug 20607

Summary: Elasticsearch - ability to add a relevancy weight in mappings.yaml file
Product: Koha Reporter: claire.hernandez <claire.hernandez>
Component: Searching - ElasticsearchAssignee: Alex Arnaud <alex.arnaud>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P5 - low CC: alex.arnaud, bjorn.nylen, black23, fridolin.somers, marjorie.barry-vila, martin.renvoize, nick, nicolas.legrand, severine.queune
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
19.11.00,19.05.03
Bug Depends on: 18316    
Bug Blocks:    
Attachments: Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account
Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account
Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account
Bug 20607: Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account
Bug 20607: (QA follow-up)

Description claire.hernandez@biblibre.com 2018-04-18 13:40:59 UTC
The code could be able to inject mappings and weight if a mapping in mappings.yaml file contains boost-in-simple-search:

Exemple:

  Personal-name:                                                                                                                                                                         
    label: Personal-name                                                                                                                                                                 
    mappings:                                                                                                                                                                            
      - facet: ''                                                                                                                                                                        
        marc_field: 100abcdefghjklmnopqrstvxyz                                                                                                                                           
        marc_type: marc21                                                                                                                                                                
        sort: ~                                                                                                                                                                          
        suggestible: ''                                                                                                                                                                  
      - facet: ''                                                                                                                                                                        
        marc_field: 100abcdefghjklmnopqrstvxyz                                                                                                                                           
        marc_type: normarc                                                                                                                                                               
        sort: ~                                                                                                                                                                          
        suggestible: ''                                                                                                                                                                  
    type: '' 
    boost-in-simple-search: 4              

4 is added in field weight in table search_field.
Comment 1 claire.hernandez@biblibre.com 2018-04-18 13:42:35 UTC
(Maybe an enhancement could be :

```
mappings:
    - ...
settings:
    boost-in-simple-search: 4
```

in replacement of

```
mappings:
    - ...
boost-in-simple-search: 4
```

but not sure)
Comment 2 Alex Arnaud 2018-04-24 13:15:29 UTC
Created attachment 74805 [details] [review]
Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account

Test plan:
  - apply BZ 18316 and this one,
  - update DB and schema files,
  - edit admin/searchengine/elasticsearch/mappings.yaml
    to add weight for some fields,
  - go to admin > search engine configuration,
  - reset your mappings (add ?op=reset&i_know_what_i_am_doing=1 to url),
  - check that weights you've added are set
Comment 3 Björn Nylén 2019-03-12 13:18:10 UTC
The functionality works but the tests fail due to the weight is beeing returned as a decimal number.

#   Failed test 'Match search field is weighted with 15'
#   at t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t line 61.
#          got: '15.00'
#     expected: '15'

#   Failed test 'Title search field is weighted with 20'
#   at t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t line 64.
#          got: '20.00'
#     expected: '20'
# Looks like you failed 2 tests of 4.
Comment 4 Michal Denar 2019-04-04 07:49:52 UTC
Alex, can you rebase this bug on master?

Thank you.
Comment 5 Alex Arnaud 2019-04-04 09:01:24 UTC
Created attachment 87402 [details] [review]
Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account

Test plan:
  - apply this patch,
  - edit admin/searchengine/elasticsearch/mappings.yaml
    to add weight for some fields,
  - go to admin > search engine configuration,
  - reset your mappings (add ?op=reset&i_know_what_i_am_doing=1 to url),
  - check that weights you've added are set
Comment 6 Alex Arnaud 2019-04-04 09:02:58 UTC
(In reply to Michal Denar from comment #4)
> Alex, can you rebase this bug on master?
> 
> Thank you.

Done! Thank you for reminding me of that BZ
Comment 7 Nicolas Legrand 2019-04-12 09:24:13 UTC
Created attachment 87874 [details] [review]
Bug 20607 - Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account

Test plan:
  - apply this patch,
  - edit admin/searchengine/elasticsearch/mappings.yaml
    to add weight for some fields,
  - go to admin > search engine configuration,
  - reset your mappings (add ?op=reset&i_know_what_i_am_doing=1 to url),
  - check that weights you've added are set

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Comment 8 Nick Clemens (kidclamp) 2019-06-11 13:36:51 UTC
Patches work, however, the tests delete all my data, then start a transaction at the end?

QA tool doesn't like commit title
Comment 9 Nick Clemens (kidclamp) 2019-07-16 18:15:01 UTC
Created attachment 91560 [details] [review]
Bug 20607: Make Koha::SearchEngine::Elasticsearch::reset_elasticsearch_mappings take weight into account

Test plan:
  - apply this patch,
  - edit admin/searchengine/elasticsearch/mappings.yaml
    to add weight for some fields,
  - go to admin > search engine configuration,
  - reset your mappings (add ?op=reset&i_know_what_i_am_doing=1 to url),
  - check that weights you've added are set

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 10 Nick Clemens (kidclamp) 2019-07-16 18:15:06 UTC
Created attachment 91561 [details] [review]
Bug 20607: (QA follow-up)

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 11 Martin Renvoize 2019-07-19 09:10:03 UTC
Nice work!

Pushed to master for 19.11.00
Comment 12 Fridolin Somers 2019-08-06 13:55:00 UTC
Pushed to 19.05.x for 19.05.03