Skip to content

Commit

Permalink
feat(cn-browse): modify usage of shelving order (#675)
Browse files Browse the repository at this point in the history
Closes: MSEARCH-831
  • Loading branch information
psmagin authored Oct 15, 2024
1 parent 3e4848d commit 9a01db4
Show file tree
Hide file tree
Showing 33 changed files with 323 additions and 444 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Implement Reindexing of Institutions ([MSEARCH-768](https://issues.folio.org/browse/MSEARCH-768))
* Create computed field for sorting and filtering Date 1 ([MSEARCH-806](https://folio-org.atlassian.net/browse/MSEARCH-806))
* Support filters for subject source and type on subject browse ([MSEARCH-805](https://folio-org.atlassian.net/browse/MSEARCH-805))
* Modify usage of shelving order for call number browse ([MSEARCH-831](https://folio-org.atlassian.net/browse/MSEARCH-831))
* Implement new re-index flow for instance records ([MSEARCH-793](https://folio-org.atlassian.net/issues/MSEARCH-793), [MSEARCH-794](https://folio-org.atlassian.net/issues/MSEARCH-794), [MSEARCH-796](https://folio-org.atlassian.net/issues/MSEARCH-796), [MSEARCH-797](https://folio-org.atlassian.net/issues/MSEARCH-797), [MSEARCH-798](https://folio-org.atlassian.net/issues/MSEARCH-798), [MSEARCH-799](https://folio-org.atlassian.net/issues/MSEARCH-799), [MSEARCH-800](https://folio-org.atlassian.net/issues/MSEARCH-800), [MSEARCH-801](https://folio-org.atlassian.net/issues/MSEARCH-801), [MSEARCH-802](https://folio-org.atlassian.net/issues/MSEARCH-802))
* Implement Linked Data HUB index and search API ([MSEARCH-844](https://folio-org.atlassian.net/browse/MSEARCH-844))

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.search.cql;

import static org.folio.search.utils.CallNumberUtils.getShelfKeyFromCallNumber;
import static org.folio.search.utils.CallNumberUtils.normalizeEffectiveShelvingOrder;

import java.util.ArrayList;
Expand All @@ -26,7 +27,7 @@ public class EffectiveShelvingOrderTermProcessor implements SearchTermProcessor

@Override
public String getSearchTerm(String inputTerm) {
return normalizeEffectiveShelvingOrder(inputTerm);
return getShelfKeyFromCallNumber(inputTerm).orElse(inputTerm);
}

public String getSearchTerm(String inputTerm, String callNumberTypeName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.folio.search.model.BrowseResult;
import org.folio.search.model.SearchResult;
import org.folio.search.model.service.BrowseContext;
import org.folio.search.model.service.BrowseRequest;
import org.folio.search.model.types.CallNumberType;
import org.folio.search.service.consortium.FeatureConfigServiceDecorator;
import org.folio.search.service.converter.ElasticsearchDocumentConverter;
import org.opensearch.action.search.SearchResponse;
Expand All @@ -49,22 +51,25 @@ public class CallNumberBrowseResultConverter {
*
* @param resp - Elasticsearch {@link SearchResponse} object
* @param ctx - {@link BrowseContext} value
* @param request - initial request
* @param isBrowsingForward - direction of browsing
* @return converted {@link SearchResult} object with {@link CallNumberBrowseItem} values
*/
public BrowseResult<CallNumberBrowseItem> convert(SearchResponse resp, BrowseContext ctx, boolean isBrowsingForward) {
public BrowseResult<CallNumberBrowseItem> convert(SearchResponse resp, BrowseContext ctx, BrowseRequest request,
boolean isBrowsingForward) {
var searchResult = documentConverter.convertToSearchResult(resp, Instance.class, this::mapToBrowseItem);
var browseResult = BrowseResult.of(searchResult);
var browseItems = browseResult.getRecords();
if (CollectionUtils.isEmpty(browseItems)) {
return browseResult;
}

var typeId = CallNumberType.fromName(request.getRefinedCondition()).map(CallNumberType::getId).orElse(null);
boolean includeIntermediateItems = featureConfigService.isEnabled(BROWSE_CN_INTERMEDIATE_VALUES);
boolean removeIntermediateDuplicates = featureConfigService.isEnabled(BROWSE_CN_INTERMEDIATE_REMOVE_DUPLICATES);
var items = isBrowsingForward ? browseItems : reverse(browseItems);
var populatedItems = includeIntermediateItems
? populateItemsWithIntermediateResults(items, ctx, removeIntermediateDuplicates,
? populateItemsWithIntermediateResults(items, ctx, removeIntermediateDuplicates, typeId,
isBrowsingForward)
: fillItemsWithFullCallNumbers(items, ctx, isBrowsingForward);

Expand All @@ -76,10 +81,13 @@ private CallNumberBrowseItem mapToBrowseItem(SearchHit searchHit, Instance insta
return new CallNumberBrowseItem().totalRecords(1).instance(instance).shelfKey(shelfKey);
}

private static List<CallNumberBrowseItem> populateItemsWithIntermediateResults(
List<CallNumberBrowseItem> browseItems, BrowseContext ctx, boolean removeDuplicates, boolean isBrowsingForward) {
private static List<CallNumberBrowseItem> populateItemsWithIntermediateResults(List<CallNumberBrowseItem> browseItems,
BrowseContext ctx,
boolean removeDuplicates,
String typeId,
boolean isBrowsingForward) {
return browseItems.stream()
.map(item -> getCallNumberBrowseItemsBetween(item, removeDuplicates))
.map(item -> getCallNumberBrowseItemsBetween(item, typeId, removeDuplicates))
.flatMap(Collection::stream)
.filter(browseItem -> isValidBrowseItem(browseItem, ctx, isBrowsingForward))
.sorted(comparing(CallNumberBrowseItem::getShelfKey))
Expand All @@ -104,12 +112,14 @@ private static boolean isValidBrowseItem(CallNumberBrowseItem item, BrowseContex
}

private static List<CallNumberBrowseItem> getCallNumberBrowseItemsBetween(CallNumberBrowseItem browseItem,
boolean removeDuplicates) {
String typeId, boolean removeDuplicates) {
var itemsByShelfKeys = toStreamSafe(browseItem.getInstance().getItems())
.filter(item -> StringUtils.isNotBlank(item.getEffectiveShelvingOrder()))
.collect(groupingBy(item -> toRootUpperCase(item.getEffectiveShelvingOrder()), LinkedHashMap::new, toList()));

var callNumbersStream = toStreamSafe(browseItem.getInstance().getItems())
.filter(item -> typeId == null || item.getEffectiveCallNumberComponents() != null
&& typeId.equals(item.getEffectiveCallNumberComponents().getTypeId()))
.map(Item::getEffectiveShelvingOrder).distinct()
.filter(StringUtils::isNotBlank)
.map(StringUtils::toRootUpperCase)
Expand Down
Loading

0 comments on commit 9a01db4

Please sign in to comment.