diff --git a/.gitignore b/.gitignore index 99fa7314..2ceac388 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ settings.gradle gradlew gradle/wrapper/gradle-wrapper.properties src/main/java/tla/domain +src/main/java/tla/error diff --git a/src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java b/src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java index 8236cb4d..e5b0dcfa 100644 --- a/src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java +++ b/src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java @@ -12,73 +12,70 @@ import lombok.extern.slf4j.Slf4j; import tla.backend.es.model.SentenceEntity; import tla.backend.es.model.SentenceEntity.Context; +import tla.backend.es.model.parts.Token; import tla.backend.service.ModelClass; import tla.domain.command.PassportSpec; +import tla.domain.command.SentenceSearch.TokenSpec; @Slf4j @Getter @ModelClass(SentenceEntity.class) public class SentenceSearchQueryBuilder extends ESQueryBuilder implements MultiLingQueryBuilder { - public final static String AGG_ID_TEXT_IDS = "text_ids"; - - public void setContext(Context context) { - BoolQueryBuilder textQuery = boolQuery(); - String textId = context.getTextId(); - if (textId != null) { - - log.info("sentence query: receive {} text IDs", textId); - textQuery.must( - QueryBuilders.termQuery( - "context.textId", - textId - ) - ); - this.filter(textQuery); - } + public final static String AGG_ID_TEXT_IDS = "text_ids"; - } + public void setContext(Context context) { + BoolQueryBuilder textQuery = boolQuery(); + String textId = context.getTextId(); + if (textId != null) { + log.info("sentence query: receive {} textIDs", textId); + textQuery.must(QueryBuilders.termQuery("context.textId", textId)); + this.filter(textQuery); + } - public void setTokens(Collection tokenQueries) { - BoolQueryBuilder tokenQuery = boolQuery(); - if (tokenQueries != null) { - tokenQueries.forEach( - query -> tokenQuery.must( - QueryBuilders.nestedQuery( - "tokens", - query.getNativeRootQueryBuilder(), - ScoreMode.None - ) - ) - ); - } - this.filter(tokenQuery); - } + } - public void setPassport(PassportSpec spec) { - log.info("set sentence search passport specs"); - if (spec != null && !spec.isEmpty()) { - log.info("spawn text search dependency"); - var textSearchQuery = new TextSearchQueryBuilder(); - textSearchQuery.setExpansion(true); - textSearchQuery.setPassport(spec); - this.dependsOn( - textSearchQuery, - this::setTextIds - ); - } - } +/* public void setTokens(Collection tokens) { + if (tokens != null) { + BoolQueryBuilder tokenQuery = boolQuery(); + String tokenId = tokens.iterator().next().getId(); + if (tokenId != null) { + log.info("sentence query: receive {} as tokenID", tokenId); + tokenQuery.must(QueryBuilders.nestedQuery("tokens", QueryBuilders.termQuery("tokens.id", tokenId), + ScoreMode.None)); + this.filter(tokenQuery); + } + } + } */ + - public void setTextIds(Collection textIds) { - if (textIds != null) { - log.info("sentence query: receive {} text IDs", textIds.size()); - this.filter( - QueryBuilders.termsQuery( - "context.textId", - textIds - ) - ); - } - } + public void setTokens(Collection tokenQueries) { + BoolQueryBuilder tokenQuery = boolQuery(); + if (tokenQueries != null) { + tokenQueries.forEach(query -> tokenQuery + .must(QueryBuilders.nestedQuery("tokens", query.getNativeRootQueryBuilder(), ScoreMode.None))); + } + this.filter(tokenQuery); + } + + + public void setPassport(PassportSpec spec) { + log.info("set sentence search passport specs"); + if (spec != null && !spec.isEmpty()) { + log.info("spawn text search dependency"); + var textSearchQuery = new TextSearchQueryBuilder(); + textSearchQuery.setExpansion(true); + textSearchQuery.setPassport(spec); + this.dependsOn(textSearchQuery, this::setTextIds); + } + } + + // TODO + public void setTextIds(Collection textIds) { + if (textIds != null) { + log.info("sentence query: receive {} text IDs", textIds.size()); + this.filter(QueryBuilders.termsQuery("context.textId", textIds)); + } + } } \ No newline at end of file diff --git a/src/main/java/tla/backend/es/query/TokenSearchQueryBuilder.java b/src/main/java/tla/backend/es/query/TokenSearchQueryBuilder.java index ecc43e44..155e885a 100644 --- a/src/main/java/tla/backend/es/query/TokenSearchQueryBuilder.java +++ b/src/main/java/tla/backend/es/query/TokenSearchQueryBuilder.java @@ -6,20 +6,21 @@ public class TokenSearchQueryBuilder extends ESQueryBuilder implements MultiLingQueryBuilder { - @Override - public String nestedPath() { - return "tokens."; - } + @Override + public String nestedPath() { + return "tokens."; + } +//TODO where is this function called + public void setTokenId(String tokenId) { + if (tokenId != null) { + this.must(QueryBuilders.termQuery(String.format("%sid", this.nestedPath()), tokenId)); + } + } - public void setLemma(Lemmatization lemma) { - if (lemma != null && !lemma.isEmpty()) { - this.must( - QueryBuilders.termQuery( - String.format("%slemma.id", this.nestedPath()), - lemma.getId() - ) - ); - } - } + public void setLemma(Lemmatization lemma) { + if (lemma != null && !lemma.isEmpty()) { + this.must(QueryBuilders.termQuery(String.format("%slemma.id", this.nestedPath()), lemma.getId())); + } + } }