Skip to content

Commit

Permalink
feat(search-instances): make "all" search field option to search by f…
Browse files Browse the repository at this point in the history
…ull-text fields (#562)

Closes: MSEARCH-606
  • Loading branch information
psmagin authored Apr 10, 2024
1 parent fba7115 commit 6b1b697
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Implement reindexing of locations ([MSEARCH-702](https://issues.folio.org/browse/MSEARCH-702))
* Modify diacritics handling in search, browse and sorting ([MSEARCH-690](https://issues.folio.org/browse/MSEARCH-690))
* Instance search: add search option that search instances by normalized classification number ([MSEARCH-697](https://issues.folio.org/browse/MSEARCH-697))
* Instance search: make "all" search field option to search by full-text fields ([MSEARCH-606](https://issues.folio.org/browse/MSEARCH-606))

### Bug fixes
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public boolean isMultilangField(String resourceName, String path) {
return this.getPlainFieldByPath(resourceName, path).filter(PlainFieldDescription::isMultilang).isPresent();
}

@Override
public boolean isFullTextField(String resourceName, String path) {
return this.getPlainFieldByPath(resourceName, path).filter(PlainFieldDescription::hasFulltextIndex).isPresent();
}

@Override
public String getModifiedField(String field, String resource) {
var queryWrapper = new Object() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public interface SearchFieldProvider {
*/
boolean isMultilangField(String resourceName, String path);

/**
* Checks if field by path is full-text or not.
*
* @param resourceName resource name as {@link String} object
* @param path path to the field as {@link String} object
* @return true if field by path is full-text, false - otherwise
*/
boolean isFullTextField(String resourceName, String path);

/**
* Apply resource field modifiers for field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void collectFieldValuesFromEventBody(String path, MultilangValue ctx,
@SuppressWarnings("unchecked")
private void collectFieldValuesFromEventBody(String path, MultilangValue ctx, Object v, Predicate<String> filter) {
if (v instanceof String) {
ctx.addValue(StringUtils.strip((String) v), searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, path));
ctx.addValue(StringUtils.strip((String) v), searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, path));
}

if (v instanceof Collection<?>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ static void cleanUp() {
"Cooperative information systems",
"0262012103",
"2003065165",
"Cambridge, Mass.",
"Antoniou, Grigoris matthew",
"Antoniou matthew",
"HD1691 .I5 1967",
"Cambridge, Mass.",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void setUp() {

@Test
void getFieldValue_positive() {
when(searchFieldProvider.isMultilangField(eq(INSTANCE_RESOURCE), anyString())).thenAnswer(inv ->
when(searchFieldProvider.isFullTextField(eq(INSTANCE_RESOURCE), anyString())).thenAnswer(inv ->
MULTILANG_VALUE_PATHS.contains(inv.<String>getArgument(1)));

var actual = processor.getFieldValue(toMap(
Expand All @@ -59,8 +59,8 @@ void getFieldValue_positive() {

@Test
void getFieldValue_holdingFieldsFromSearchGeneratedValues() {
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "holdingsPublicNotes")).thenReturn(true);
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "holdingsFullCallNumbers")).thenReturn(false);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "holdingsPublicNotes")).thenReturn(true);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "holdingsFullCallNumbers")).thenReturn(false);

var actual = processor.getFieldValue(mapOf(
"holdingsPublicNotes", List.of("note1", "note2"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void getFieldValue_positive_emptyValue() {
@Test
void getFieldValue_positive_multilangTitle() {
var instanceId = randomId();
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "id")).thenReturn(false);
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "title")).thenReturn(true);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "id")).thenReturn(false);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "title")).thenReturn(true);
var actual = processor.getFieldValue(toMap(new Instance().id(instanceId).title("my resource")));
assertThat(actual).isEqualTo(MultilangValue.of(singleton(instanceId), newLinkedHashSet("my resource")));
}

@Test
void getFieldValue_positive_multilangSubjects() {
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "subjects.value")).thenReturn(true);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "subjects.value")).thenReturn(true);
var actual =
processor.getFieldValue(
toMap(new Instance().subjects(List.of(new Subject().value("subject1"), new Subject().value("subject2")))));
Expand All @@ -76,7 +76,7 @@ void getFieldValue_positive_identifiers() {
new Identifiers().identifierTypeId(randomId()).value("1-56619-909-3")))));
assertThat(actual).isEqualTo(MultilangValue.of(
newLinkedHashSet("978-1-56619-909-4", "1-56619-909-3"), emptySet()));
verify(searchFieldProvider, times(2)).isMultilangField(INSTANCE_RESOURCE, "identifiers.value");
verify(searchFieldProvider, times(2)).isFullTextField(INSTANCE_RESOURCE, "identifiers.value");
}

@Test
Expand All @@ -85,27 +85,27 @@ void getFieldValue_positive_instanceNotes() {
new Note().note("public note").staffOnly(false),
new Note().note("private note").staffOnly(true)))));
assertThat(actual).isEqualTo(MultilangValue.of(newLinkedHashSet("public note", "private note"), emptySet()));
verify(searchFieldProvider, times(2)).isMultilangField(INSTANCE_RESOURCE, "notes.note");
verify(searchFieldProvider, times(2)).isFullTextField(INSTANCE_RESOURCE, "notes.note");
}

@Test
void getFieldValue_positive_classification() {
var actual = processor.getFieldValue(mapOf("matchKey", "123456"));
assertThat(actual).isEqualTo(MultilangValue.of(newLinkedHashSet("123456"), emptySet()));
verify(searchFieldProvider).isMultilangField(INSTANCE_RESOURCE, "matchKey");
verify(searchFieldProvider).isFullTextField(INSTANCE_RESOURCE, "matchKey");
}

@Test
void getFieldValue_positive_searchFieldProcessedIsbn() {
var isbnValues = newLinkedHashSet("1-56619-909-3", "1566199093", "9781566199093");
var actual = processor.getFieldValue(mapOf("isbn", isbnValues));
assertThat(actual).isEqualTo(MultilangValue.of(isbnValues, emptySet()));
verify(searchFieldProvider, times(3)).isMultilangField(INSTANCE_RESOURCE, "isbn");
verify(searchFieldProvider, times(3)).isFullTextField(INSTANCE_RESOURCE, "isbn");
}

@Test
void getFieldValue_positive_multilangTitleValue() {
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "title")).thenReturn(true);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "title")).thenReturn(true);

var value = "titleValue";
var actual = processor.getFieldValue(mapOf("plain_title", value, "title", mapOf("src", value, "eng", value)));
Expand Down Expand Up @@ -155,6 +155,6 @@ void getFieldValue_positive_itemsAndHoldings() {
.items(List.of(new Item().id(randomId()).barcode("000333"), new Item().id(randomId()).hrid("i1")))
.holdings(List.of(new Holding().id(randomId()).hrid("h1")))));
assertThat(actual).isEqualTo(MultilangValue.of(singleton(instanceId), emptySet()));
verify(searchFieldProvider).isMultilangField(INSTANCE_RESOURCE, "id");
verify(searchFieldProvider).isFullTextField(INSTANCE_RESOURCE, "id");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void setUp() {

@Test
void getFieldValue_positive() {
when(searchFieldProvider.isMultilangField(eq(INSTANCE_RESOURCE), anyString())).thenAnswer(inv ->
when(searchFieldProvider.isFullTextField(eq(INSTANCE_RESOURCE), anyString())).thenAnswer(inv ->
MULTILANG_VALUE_PATHS.contains(inv.<String>getArgument(1)));

var actual = processor.getFieldValue(toMap(
Expand All @@ -60,8 +60,8 @@ void getFieldValue_positive() {

@Test
void getFieldValue_holdingFieldsFromSearchGeneratedValues() {
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "itemPublicNotes")).thenReturn(true);
when(searchFieldProvider.isMultilangField(INSTANCE_RESOURCE, "itemFullCallNumbers")).thenReturn(false);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "itemPublicNotes")).thenReturn(true);
when(searchFieldProvider.isFullTextField(INSTANCE_RESOURCE, "itemFullCallNumbers")).thenReturn(false);

var actual = processor.getFieldValue(mapOf(
"itemPublicNotes", List.of("note1", "note2"),
Expand Down

0 comments on commit 6b1b697

Please sign in to comment.