Skip to content

Commit

Permalink
fix(cn-browse): No highlighted match for call number with suffix when…
Browse files Browse the repository at this point in the history
… Call number type is specified

- modify comparison of shelfKey with anchor to ignore suffix if exist

Closes: MSEARCH-558
  • Loading branch information
ArtHov committed Sep 8, 2023
1 parent e4b567a commit 6e2ce29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.folio.search.cql.CqlSearchQueryConverter;
import org.folio.search.domain.dto.CallNumberBrowseItem;
import org.folio.search.model.BrowseResult;
Expand Down Expand Up @@ -146,7 +147,7 @@ private static void highlightMatchingCallNumber(BrowseContext ctx,
}

var firstBrowseItem = items.get(0);
if (!StringUtils.equals(firstBrowseItem.getShelfKey(), anchor)) {
if (!isAnchorMatching(firstBrowseItem, anchor)) {
var browseItemsWithEmptyValue = new ArrayList<CallNumberBrowseItem>();
browseItemsWithEmptyValue.add(getEmptyCallNumberBrowseItem(callNumber, anchor));
browseItemsWithEmptyValue.addAll(items);
Expand All @@ -157,6 +158,15 @@ private static void highlightMatchingCallNumber(BrowseContext ctx,
firstBrowseItem.setIsAnchor(true);
}

private static boolean isAnchorMatching(CallNumberBrowseItem browseItem, String anchor) {
var suffix = browseItem.getInstance().getItems().get(0).getEffectiveCallNumberComponents().getSuffix();
var shelfKey = browseItem.getShelfKey();
if (Strings.isNotBlank(suffix)) {
shelfKey = StringUtils.removeEnd(shelfKey, suffix).trim();
}
return StringUtils.equals(shelfKey, anchor);
}

private static CallNumberBrowseItem getEmptyCallNumberBrowseItem(String callNumber, String shelfKey) {
return new CallNumberBrowseItem()
.fullCallNumber(callNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ void browse_positive_around_noHighlightMatch() {
cnBrowseItem(instance("C 11"), "C 11"))));
}

@Test
void browse_positive_around_highlightMatchWithSuffix() {
var request = request("callNumber >= B or callNumber < B", true);

when(cqlSearchQueryConverter.convertToTermNode(anyString(), anyString()))
.thenReturn(new CQLTermNode(null, null, "B"));

prepareMockForBrowsingAround(request,
contextAroundIncluding(),
BrowseResult.empty(),
BrowseResult.of(1, List.of(browseItemWithSuffix("B", "2005"))));

var actual = callNumberBrowseService.browse(request);

assertThat(actual.getRecords().get(0).getIsAnchor()).isTrue();
}

@Test
void browse_positive_around_noResults() {
var request = request("callNumber >= B or callNumber < B", false);
Expand Down Expand Up @@ -362,6 +379,16 @@ private static CallNumberBrowseItem browseItem(String callNumber) {
.totalRecords(1);
}

private static CallNumberBrowseItem browseItemWithSuffix(String callNumber, String suffix) {
var instance = instance(callNumber);
instance.getItems().get(0).getEffectiveCallNumberComponents().setSuffix(suffix);
return new CallNumberBrowseItem()
.fullCallNumber(callNumber)
.shelfKey(getShelfKeyFromCallNumber(callNumber) + " " + suffix)
.instance(instance)
.totalRecords(1);
}

private static List<CallNumberBrowseItem> browseItems(String... shelfKeys) {
return stream(shelfKeys)
.map(CallNumberBrowseServiceTest::browseItem)
Expand Down

0 comments on commit 6e2ce29

Please sign in to comment.