Skip to content

Commit

Permalink
Fixed conflict with Lemma-Attestations-Search
Browse files Browse the repository at this point in the history
  • Loading branch information
RDBloese committed Sep 6, 2023
1 parent c420e40 commit e0ca205
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 67 deletions.
108 changes: 52 additions & 56 deletions src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,69 @@
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<TokenSearchQueryBuilder> 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 setTokenID(Collection<Token> tokens) {
System.out.println("tesst");
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<String> textIds) {
if (textIds != null) {
log.info("sentence query: receive {} text IDs", textIds.size());
this.filter(
QueryBuilders.termsQuery(
"context.textId",
textIds
)
);
}
}
public void setTokens(Collection<TokenSearchQueryBuilder> 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<String> textIds) {
if (textIds != null) {
log.info("sentence query: receive {} text999999999999 IDs", textIds.size());
this.filter(QueryBuilders.termsQuery("context.textId", textIds));
}
}

}
11 changes: 0 additions & 11 deletions src/main/java/tla/backend/es/query/TokenSearchQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ public class TokenSearchQueryBuilder extends ESQueryBuilder implements MultiLing
public String nestedPath() {
return "tokens.";
}

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()) {
Expand Down

0 comments on commit e0ca205

Please sign in to comment.