Skip to content

Commit

Permalink
Merge branch 'master' into MSEARCH-853
Browse files Browse the repository at this point in the history
  • Loading branch information
viacheslavkol authored Oct 17, 2024
2 parents 57eb1b4 + 9e0698b commit 2bc7202
Show file tree
Hide file tree
Showing 63 changed files with 590 additions and 663 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
* 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))
* Simplify indexing for instance child documents ([MSEARCH-851](https://folio-org.atlassian.net/browse/MSEARCH-851))
* 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))
* Extend instance-records reindex endpoint with index settings ([MSEARCH-853](https://folio-org.atlassian.net/browse/MSEARCH-853))
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mvn install

See that it says "BUILD SUCCESS" near the end.

By default the integration tests run against an OpenSearch server.
By default, the integration tests run against an OpenSearch server.
To run them against an Elasticsearch server use

```shell
Expand Down Expand Up @@ -371,7 +371,7 @@ update or sync the aggregated data of those specific Instances, so that the aggr

Upload step queries the aggregated data for the specific Instance resources type and then runs the indexing by populating the data into resource's OpenSearch index.

We can execute both Merge and Upload steps with so called _full reindex_ API:
We can execute both Merge and Upload steps with so-called _full reindex_ API:
```http
POST /search/index/instance-records/reindex/full
```
Expand Down Expand Up @@ -644,7 +644,7 @@ does not produce any values, so the following search options will return an empt
| `modeOfIssuanceId` | term | `modeOfIssuanceId=="123"` | Matches instances that have `123` mode of issuance |
| `natureOfContentTermIds` | term | `natureOfContentTermIds=="123"` | Matches instances that have `123` nature of content |
| `publisher` | full-text | `publisher all "Publisher of Ukraine"` | Matches instances that have `Publisher of Ukraine` publisher |
| `publication.place` | full-text | `publication.place all "Ukraine"` | Matches instances that have `Ukraine` in publication place |
| `publication.place` | full-text | `publication.place all "Ukraine"` | Matches instances that have `Ukraine` in publication place |
| `instanceTags` | term | `instanceTags=="important"` | Matches instances that have `important` tag |
| `classifications.classificationNumber` | term | `classifications.classificationNumber=="cl1"` | Matches instances that have `cl1` classification number |
| `classifications.classificationTypeId` | term | `classifications.classificationTypeId=="123"` | Matches instances that have classification type id `123` |
Expand Down Expand Up @@ -949,7 +949,7 @@ Send a POST request to create a Job
}
```

It is possible to check job status by jobs Id.
It is possible to check job status by job ID.

`GET /search/resources/jobs/{jobId}`

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
@@ -1,13 +1,14 @@
package org.folio.search.model.index;

import java.util.List;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class InstanceSubResource {
private String instanceId;
private String typeId;
private String tenantId;
private Boolean shared;
private int count;
private List<String> typeId;
}
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 2bc7202

Please sign in to comment.