Skip to content

Commit

Permalink
rename constant
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Jan 17, 2025
1 parent 97787da commit 5e72ef3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions search-commons/src/main/java/no/unit/nva/constants/Words.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public final class Words {

public static final int NAME_AND_SORT_LENGTH = 2;

public static final boolean KEYWORD_TRUE = true;
public static final boolean KEYWORD_FALSE = false;
public static final boolean INCLUDE_KEYWORD = true;
public static final boolean EXCLUDE_KEYWORD = false;

public static final char CHAR_UNDERSCORE = '_';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static no.unit.nva.constants.Words.ALL;
import static no.unit.nva.constants.Words.ASTERISK;
import static no.unit.nva.constants.Words.COMMA;
import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;
import static no.unit.nva.constants.Words.POST_FILTER;
import static no.unit.nva.constants.Words.RELEVANCE_KEY_NAME;
import static no.unit.nva.constants.Words.SORT_LAST;
Expand Down Expand Up @@ -339,7 +339,7 @@ private void handleSorting(SearchSourceBuilder builder) {
}

private Stream<Entry<String, Float>> entryStreamOfPathAndBoost(K key) {
return key.searchFields(KEYWORD_FALSE).map(jsonPath -> entryOfPathAndBoost(key, jsonPath));
return key.searchFields(EXCLUDE_KEYWORD).map(jsonPath -> entryOfPathAndBoost(key, jsonPath));
}

private Entry<String, Float> entryOfPathAndBoost(K key, String jsonPath) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.unit.nva.search.common.builder;

import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;

import java.util.Arrays;
import java.util.Map.Entry;
Expand Down Expand Up @@ -49,7 +49,7 @@ private Stream<QueryBuilder> buildMultiMatchQueryStream(K key, String... values)
}

private QueryBuilder getMultiMatchQueryBuilder(String value, K key) {
final var searchFields = key.searchFields(KEYWORD_FALSE).toArray(String[]::new);
final var searchFields = key.searchFields(EXCLUDE_KEYWORD).toArray(String[]::new);
return QueryBuilders.multiMatchQuery(value, searchFields)
.type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
.operator(Operator.AND);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.unit.nva.search.common.builder;

import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;
import static no.unit.nva.search.common.constant.Functions.queryToEntry;
import static org.opensearch.index.query.QueryBuilders.boolQuery;
import static org.opensearch.index.query.QueryBuilders.existsQuery;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected Stream<Entry<K, QueryBuilder>> buildMatchAllValuesQuery(K key, String.

private Stream<Entry<K, QueryBuilder>> buildExistsQuery(K key, Boolean exists) {
var builder = boolQuery().queryName(EXISTS_ANY);
key.searchFields(KEYWORD_FALSE)
key.searchFields(EXCLUDE_KEYWORD)
.map(fieldName -> createExistsQuery(key, fieldName))
.forEach(existsQueryBuilder -> mustOrNot(exists, builder, existsQueryBuilder));
return queryToEntry(key, builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.unit.nva.search.common.builder;

import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.KEYWORD_TRUE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;
import static no.unit.nva.constants.Words.INCLUDE_KEYWORD;

import java.util.Arrays;
import java.util.Map.Entry;
Expand Down Expand Up @@ -48,7 +48,7 @@ protected Stream<Entry<K, QueryBuilder>> buildMatchAllValuesQuery(K key, String.
}

private DisMaxQueryBuilder buildMatchAnyKeyword(K key, String... values) {
return key.searchFields(KEYWORD_TRUE)
return key.searchFields(INCLUDE_KEYWORD)
.map(searchField -> new TermsQueryBuilder(searchField, values))
.collect(DisMaxQueryBuilder::new, DisMaxQueryBuilder::add, DisMaxQueryBuilder::add)
.boost(key.fieldBoost());
Expand All @@ -61,7 +61,7 @@ private DisMaxQueryBuilder buildMatchAnyFuzzy(K key, String... values) {
}

private QueryBuilder getMultiMatchQueryBuilder(String value, K key) {
final var searchFields = key.searchFields(KEYWORD_FALSE).toArray(String[]::new);
final var searchFields = key.searchFields(EXCLUDE_KEYWORD).toArray(String[]::new);
return QueryBuilders.multiMatchQuery(value, searchFields)
.fuzziness(Fuzziness.ZERO)
.maxExpansions(10)
Expand All @@ -72,7 +72,7 @@ private Stream<DisMaxQueryBuilder> buildMatchAllKeyword(K key, String... values)
return Arrays.stream(values)
.map(
value ->
key.searchFields(KEYWORD_TRUE)
key.searchFields(INCLUDE_KEYWORD)
.map(searchField -> new TermQueryBuilder(searchField, value))
.collect(
DisMaxQueryBuilder::new, DisMaxQueryBuilder::add, DisMaxQueryBuilder::add)
Expand All @@ -89,7 +89,7 @@ private Stream<DisMaxQueryBuilder> buildMatchAllFuzzy(K key, String... values) {
}

private Stream<QueryBuilder> getMatchPhrasePrefixBuilderStream(String singleValue, K key) {
return key.searchFields(KEYWORD_FALSE)
return key.searchFields(EXCLUDE_KEYWORD)
.map(
fieldName ->
QueryBuilders.matchPhrasePrefixQuery(fieldName, singleValue).maxExpansions(10));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.unit.nva.search.common.builder;

import static no.unit.nva.constants.Words.KEYWORD_TRUE;
import static no.unit.nva.constants.Words.INCLUDE_KEYWORD;

import java.util.Arrays;
import java.util.Map.Entry;
Expand Down Expand Up @@ -46,13 +46,13 @@ private Stream<QueryBuilder> buildMatchAllKeywordStream(K key, String... values)
return Arrays.stream(values)
.flatMap(
value ->
key.searchFields(KEYWORD_TRUE)
key.searchFields(INCLUDE_KEYWORD)
.map(searchField -> getTermQueryBuilder(key, value, searchField)));
}

private Stream<DisMaxQueryBuilder> buildMatchAnyKeywordStream(K key, String... values) {
var disMax = QueryBuilders.disMaxQuery().queryName(KEYWORD_ANY + key.asCamelCase());
key.searchFields(KEYWORD_TRUE)
key.searchFields(INCLUDE_KEYWORD)
.forEach(field -> disMax.add(new TermsQueryBuilder(field, values).boost(key.fieldBoost())));
return Stream.of(disMax);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.unit.nva.search.common.builder;

import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;
import static org.opensearch.index.query.QueryBuilders.matchPhrasePrefixQuery;
import static org.opensearch.index.query.QueryBuilders.matchQuery;

Expand Down Expand Up @@ -60,9 +60,9 @@ private Stream<DisMaxQueryBuilder> buildAnyComboMustHitQuery(K key, String... va

private Stream<QueryBuilder> phrasePrefixBuilder(String singleValue, K key) {
return Stream.concat(
key.searchFields(KEYWORD_FALSE)
key.searchFields(EXCLUDE_KEYWORD)
.map(fieldName -> matchPhrasePrefixBuilder(singleValue, key, fieldName)),
key.searchFields(KEYWORD_FALSE)
key.searchFields(EXCLUDE_KEYWORD)
.map(fieldName -> matchQueryBuilder(singleValue, key, fieldName)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static no.unit.nva.constants.ErrorMessages.INVALID_VALUE_WITH_SORT;
import static no.unit.nva.constants.ErrorMessages.TOO_MANY_ARGUMENTS;
import static no.unit.nva.constants.Words.COMMA;
import static no.unit.nva.constants.Words.KEYWORD_FALSE;
import static no.unit.nva.constants.Words.EXCLUDE_KEYWORD;
import static no.unit.nva.constants.Words.NAME_AND_SORT_LENGTH;
import static no.unit.nva.constants.Words.NONE;
import static no.unit.nva.constants.Words.POST_FILTER;
Expand Down Expand Up @@ -215,7 +215,7 @@ private String[] statusWithoutNew() {

private MultiMatchQueryBuilder assigneeQuery(String searchByUserName) {
return multiMatchQuery(
searchByUserName, ASSIGNEE.searchFields(KEYWORD_FALSE).toArray(String[]::new))
searchByUserName, ASSIGNEE.searchFields(EXCLUDE_KEYWORD).toArray(String[]::new))
.type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
.autoGenerateSynonymsPhraseQuery(false)
.fuzzyTranspositions(false)
Expand Down

0 comments on commit 5e72ef3

Please sign in to comment.