Skip to content

Commit

Permalink
fix(browse-authority): mark all exact matches as anchors if there is …
Browse files Browse the repository at this point in the history
…more then one match (#519)

Closes: MSEARCH-669
Signed-off-by: psmagin <[email protected]>
  • Loading branch information
psmagin authored Feb 19, 2024
1 parent d1e57d4 commit 0b2889e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 52 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Fix clearing following filters in FacetService: items.effectiveLocationId, holdings.tenantId ([MSEARCH-620](https://issues.folio.org/browse/MSEARCH-620))
* Fix shared filter for subjects/contributors ([MSEARCH-639](https://issues.folio.org/browse/MSEARCH-639))
* Fix shadow instance's subjects/contributors indexing ([MSEARCH-647](https://issues.folio.org/browse/MSEARCH-647))
* Mark all exact matches as anchors if there is more then one match ([MSEARCH-669](https://issues.folio.org/browse/MSEARCH-669))

### Tech Dept
* Fix log level and message wording for uniform titles ([MSEARCH-666](https://issues.folio.org/browse/MSEARCH-666))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ protected SearchSourceBuilder getSearchQuery(BrowseRequest request, BrowseContex
}

@Override
protected SearchSourceBuilder getAnchorSearchQuery(BrowseRequest request, BrowseContext context) {
protected SearchSourceBuilder getAnchorSearchQuery(BrowseRequest request, BrowseContext ctx) {
log.debug("getAnchorSearchQuery:: by [browseRequest.field: {}, filters.size: {}]",
request.getTargetField(), collectionToLogMsg(context.getFilters(), true));
request.getTargetField(), collectionToLogMsg(ctx.getFilters(), true));

var boolQuery = boolQuery().filter(FILTER_QUERY).must(termQuery(request.getTargetField(), context.getAnchor()));
context.getFilters().forEach(boolQuery::filter);
var boolQuery = boolQuery().filter(FILTER_QUERY).must(termQuery(request.getTargetField(), ctx.getAnchor()));
ctx.getFilters().forEach(boolQuery::filter);
var query = consortiumSearchHelper.filterQueryForActiveAffiliation(boolQuery, AUTHORITY_RESOURCE);
return searchSource().query(query).from(0).size(1).fetchSource(getIncludedSourceFields(request), null);
return searchSource()
.query(query)
.from(0)
.size(ctx.getLimit(ctx.isBrowsingForward()))
.fetchSource(getIncludedSourceFields(request), null);
}

@Override
Expand Down
96 changes: 59 additions & 37 deletions src/test/java/org/folio/search/controller/BrowseAuthorityIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BrowseAuthorityIT extends BaseIntegrationTest {

@BeforeAll
static void prepare() {
setUpTenant(23, authorities());
setUpTenant(25, authorities());
}

@AfterAll
Expand All @@ -54,18 +54,20 @@ void browseByAuthority_parameterized(String query, String anchor, Integer limit,
void browseByAuthority_browsingAroundWithAdditionalFilters() {
var request = get(authorityBrowsePath())
.param("query", prepareQuery("(headingRef>={value} or headingRef<{value}) "
+ "and isTitleHeadingRef==false "
+ "and tenantId==" + TENANT_ID + " "
+ "and shared==false "
+ "and headingType==(\"Personal Name\")", "\"James Rollins\""))
+ "and isTitleHeadingRef==false "
+ "and tenantId==" + TENANT_ID + " "
+ "and shared==false "
+ "and headingType==(\"Personal Name\")", "\"James Rollins\""))
.param("limit", "7")
.param("precedingRecordsCount", "2");
var actual = parseResponse(doGet(request), AuthorityBrowseResult.class);
assertThat(actual).isEqualTo(new AuthorityBrowseResult()
.totalRecords(1).prev(null).next(null)
.totalRecords(2).prev(null).next(null)
.items(List.of(
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0),
emptyAuthorityBrowseItem("James Rollins"))));
emptyAuthorityBrowseItem("James Rollins"),
authorityBrowseItem("Zappa Frank", 23, "Personal Name", AUTHORIZED, 0)
)));
}

@Test
Expand All @@ -76,7 +78,7 @@ void browseByAuthority_browsingAroundWithPrecedingRecordsCount() {
.param("precedingRecordsCount", "2");
var actual = parseResponse(doGet(request), AuthorityBrowseResult.class);
assertThat(actual).isEqualTo(new AuthorityBrowseResult()
.totalRecords(15).prev("Fantasy").next("Science")
.totalRecords(17).prev("Fantasy").next("Science")
.items(List.of(
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null),
authorityBrowseItem("Harry Potter", 13, "Uniform Title", AUTHORIZED, 0),
Expand All @@ -87,6 +89,21 @@ void browseByAuthority_browsingAroundWithPrecedingRecordsCount() {
authorityBrowseItem("Science", 16, "Topical", AUTHORIZED, 0))));
}

@Test
void browseByAuthority_browsingAroundWithSeveralExactMatches() {
var request = get(authorityBrowsePath())
.param("query", prepareQuery("headingRef < {value} or headingRef >= {value}", "\"Zappa Frank\""))
.param("limit", "3");
var actual = parseResponse(doGet(request), AuthorityBrowseResult.class);
assertThat(actual).isEqualTo(new AuthorityBrowseResult()
.totalRecords(17).prev("War and Peace").next(null)
.items(List.of(
authorityBrowseItem("War and Peace", 14, "Uniform Title", REFERENCE, null),
authorityBrowseItem("Zappa Frank", 23, "Personal Name", AUTHORIZED, 0).isAnchor(true),
authorityBrowseItem("Zappa Frank", 24, "Topical", AUTHORIZED, 0).isAnchor(true)
)));
}

@Test
void browseByAuthority_browsingAroundWithoutHighlightMatch() {
var request = get(authorityBrowsePath())
Expand All @@ -96,7 +113,7 @@ void browseByAuthority_browsingAroundWithoutHighlightMatch() {
var actual = parseResponse(doGet(request), AuthorityBrowseResult.class);

assertThat(actual).isEqualTo(new AuthorityBrowseResult()
.totalRecords(15).prev("Comic-Con").next("James Rollins")
.totalRecords(17).prev("Comic-Con").next("James Rollins")
.items(List.of(
authorityBrowseItem("Comic-Con", 7, "Conference Name", AUTHORIZED, 0),
authorityBrowseItem("Disney", 4, "Corporate Name", AUTHORIZED, 0),
Expand All @@ -115,7 +132,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {

return Stream.of(
arguments(aroundQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Biomedical Symposium").next("Comic-Con")
.totalRecords(17).prev("Biomedical Symposium").next("Comic-Con")
.items(List.of(
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null),
Expand All @@ -124,7 +141,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Comic-Con", 7, "Conference Name", AUTHORIZED, 0)))),

arguments(aroundQuery, "harry", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Disney").next("James Rollins")
.totalRecords(17).prev("Disney").next("James Rollins")
.items(List.of(
authorityBrowseItem("Disney", 4, "Corporate Name", AUTHORIZED, 0),
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null),
Expand All @@ -133,21 +150,21 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("James Rollins", 2, "Personal Name", REFERENCE, null)))),

arguments(aroundQuery, "a", 5, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next("Biomedical Symposium")
.totalRecords(17).prev(null).next("Biomedical Symposium")
.items(List.of(
emptyAuthorityBrowseItem("a"),
authorityBrowseItem("Asia Pacific", 10, "Geographic Name", AUTHORIZED, 0),
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null)))),

arguments(aroundQuery, "z", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Science").next(null)
arguments(aroundQuery, "zz", 5, new AuthorityBrowseResult()
.totalRecords(17).prev("Zappa Frank").next(null)
.items(List.of(
authorityBrowseItem("Science", 16, "Topical", AUTHORIZED, 0),
authorityBrowseItem("War and Peace", 14, "Uniform Title", REFERENCE, null),
emptyAuthorityBrowseItem("z")))),
authorityBrowseItem("Zappa Frank", 24, "Topical", AUTHORIZED, 0),
authorityBrowseItem("Zappa Frank", 23, "Personal Name", AUTHORIZED, 0),
emptyAuthorityBrowseItem("zz")))),

arguments(aroundIncludingQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Biomedical Symposium").next("Comic-Con")
.totalRecords(17).prev("Biomedical Symposium").next("Comic-Con")
.items(List.of(
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null),
Expand All @@ -156,7 +173,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Comic-Con", 7, "Conference Name", AUTHORIZED, 0)))),

arguments(aroundIncludingQuery, "harry", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Disney").next("James Rollins")
.totalRecords(17).prev("Disney").next("James Rollins")
.items(List.of(
authorityBrowseItem("Disney", 4, "Corporate Name", AUTHORIZED, 0),
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null),
Expand All @@ -165,7 +182,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("James Rollins", 2, "Personal Name", REFERENCE, null)))),

arguments(aroundIncludingQuery, "music", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Harry Potter").next("Novel")
.totalRecords(17).prev("Harry Potter").next("Novel")
.items(List.of(
authorityBrowseItem("Harry Potter", 13, "Uniform Title", AUTHORIZED, 0),
authorityBrowseItem("James Rollins", 2, "Personal Name", REFERENCE, null),
Expand All @@ -174,7 +191,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Novel", 19, "Genre", AUTHORIZED, 0)))),

arguments(aroundIncludingQuery, "music", 25, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next(null)
.totalRecords(17).prev(null).next(null)
.items(List.of(
authorityBrowseItem("Asia Pacific", 10, "Geographic Name", AUTHORIZED, 0),
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
Expand All @@ -191,10 +208,13 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Novel", 19, "Genre", AUTHORIZED, 0),
authorityBrowseItem("Poetry", 20, "Genre", REFERENCE, null),
authorityBrowseItem("Science", 16, "Topical", AUTHORIZED, 0),
authorityBrowseItem("War and Peace", 14, "Uniform Title", REFERENCE, null)))),
authorityBrowseItem("War and Peace", 14, "Uniform Title", REFERENCE, null),
authorityBrowseItem("Zappa Frank", 23, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Zappa Frank", 24, "Topical", AUTHORIZED, 0)
))),

arguments(aroundIncludingQuery, "music", 11, new AuthorityBrowseResult()
.totalRecords(15).prev("Comic-Con").next(null)
.totalRecords(17).prev("Comic-Con").next("War and Peace")
.items(List.of(
authorityBrowseItem("Comic-Con", 7, "Conference Name", AUTHORIZED, 0),
authorityBrowseItem("Disney", 4, "Corporate Name", AUTHORIZED, 0),
Expand All @@ -209,7 +229,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("War and Peace", 14, "Uniform Title", REFERENCE, null)))),

arguments(aroundIncludingQuery, "FC", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Disney").next("James Rollins")
.totalRecords(17).prev("Disney").next("James Rollins")
.items(List.of(
authorityBrowseItem("Disney", 4, "Corporate Name", AUTHORIZED, 0),
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null),
Expand All @@ -219,7 +239,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {

// browsing forward
arguments(forwardQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Brian K. Vaughan Title").next("Harry Potter")
.totalRecords(17).prev("Brian K. Vaughan Title").next("Harry Potter")
.items(List.of(
authorityBrowseItem("Brian K. Vaughan Title", 1, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Comic-Con", 7, "Conference Name", AUTHORIZED, 0),
Expand All @@ -228,7 +248,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Harry Potter", 13, "Uniform Title", AUTHORIZED, 0)))),

arguments(forwardQuery, "biology", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Biomedical Symposium").next("Comic-Con")
.totalRecords(17).prev("Biomedical Symposium").next("Comic-Con")
.items(List.of(
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null),
Expand All @@ -238,20 +258,20 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {

// checks if collapsing works in forward direction
arguments(forwardQuery, "F", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Fantasy").next("Novel")
.totalRecords(17).prev("Fantasy").next("Novel")
.items(List.of(
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null),
authorityBrowseItem("Harry Potter", 13, "Uniform Title", AUTHORIZED, 0),
authorityBrowseItem("James Rollins", 2, "Personal Name", REFERENCE, null),
authorityBrowseItem("North America", 11, "Geographic Name", REFERENCE, null),
authorityBrowseItem("Novel", 19, "Genre", AUTHORIZED, 0)))),

arguments(forwardQuery, "Z", 10, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next(null)
arguments(forwardQuery, "ZZ", 10, new AuthorityBrowseResult()
.totalRecords(17).prev(null).next(null)
.items(emptyList())),

arguments(forwardIncludingQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Brian K. Vaughan").next("Fantasy")
.totalRecords(17).prev("Brian K. Vaughan").next("Fantasy")
.items(List.of(
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Brian K. Vaughan Title", 1, "Personal Name", AUTHORIZED, 0),
Expand All @@ -260,7 +280,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null)))),

arguments(forwardIncludingQuery, "biology", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Biomedical Symposium").next("Comic-Con")
.totalRecords(17).prev("Biomedical Symposium").next("Comic-Con")
.items(List.of(
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null),
Expand All @@ -270,14 +290,14 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {

// browsing backward
arguments(backwardQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next("Blumberg Green Beauty")
.totalRecords(17).prev(null).next("Blumberg Green Beauty")
.items(List.of(
authorityBrowseItem("Asia Pacific", 10, "Geographic Name", AUTHORIZED, 0),
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null)))),

arguments(backwardQuery, "fun", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Brian K. Vaughan").next("Fantasy")
.totalRecords(17).prev("Brian K. Vaughan").next("Fantasy")
.items(List.of(
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Brian K. Vaughan Title", 1, "Personal Name", AUTHORIZED, 0),
Expand All @@ -286,7 +306,7 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null)))),

arguments(backwardQuery, "G", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Brian K. Vaughan").next("Fantasy")
.totalRecords(17).prev("Brian K. Vaughan").next("Fantasy")
.items(List.of(
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Brian K. Vaughan Title", 1, "Personal Name", AUTHORIZED, 0),
Expand All @@ -295,19 +315,19 @@ private static Stream<Arguments> authorityBrowsingDataProvider() {
authorityBrowseItem("Fantasy", 17, "Topical", REFERENCE, null)))),

arguments(backwardQuery, "A", 10, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next(null)
.totalRecords(17).prev(null).next(null)
.items(emptyList())),

arguments(backwardIncludingQuery, "Brian K. Vaughan", 5, new AuthorityBrowseResult()
.totalRecords(15).prev(null).next("Brian K. Vaughan")
.totalRecords(17).prev(null).next("Brian K. Vaughan")
.items(List.of(
authorityBrowseItem("Asia Pacific", 10, "Geographic Name", AUTHORIZED, 0),
authorityBrowseItem("Biomedical Symposium", 8, "Conference Name", REFERENCE, null),
authorityBrowseItem("Blumberg Green Beauty", 5, "Corporate Name", REFERENCE, null),
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0)))),

arguments(backwardIncludingQuery, "fun", 5, new AuthorityBrowseResult()
.totalRecords(15).prev("Brian K. Vaughan").next("Fantasy")
.totalRecords(17).prev("Brian K. Vaughan").next("Fantasy")
.items(List.of(
authorityBrowseItem("Brian K. Vaughan", 22, "Personal Name", AUTHORIZED, 0),
authorityBrowseItem("Brian K. Vaughan Title", 1, "Personal Name", AUTHORIZED, 0),
Expand Down Expand Up @@ -342,6 +362,8 @@ private static Authority[] authorities() {
authority(20).sftGenreTerm(List.of("Poetry")),
authority(21).saftGenreTerm(List.of("Prose", "Romance")),
authority(22).personalName("Brian K. Vaughan"),
authority(23).personalName("Zappa Frank"),
authority(24).topicalTerm("Zappa Frank"),
};
}

Expand Down
Loading

0 comments on commit 0b2889e

Please sign in to comment.