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

fix(cn-browse): No highlighted match for call number with suffix when Call number type is specified #413

Merged
merged 2 commits into from
Sep 15, 2023
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
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