Skip to content

Commit

Permalink
feat: removed RQL parser, as it was not used anymore (table values ar…
Browse files Browse the repository at this point in the history
…e not indexed) (#3933)
  • Loading branch information
ymarcon authored Sep 20, 2024
1 parent a142674 commit 51a5208
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 1,001 deletions.
4 changes: 0 additions & 4 deletions opal-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</dependency>
<dependency>
<groupId>net.jazdw</groupId>
<artifactId>rql-parser</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

package org.obiba.opal.search;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.obiba.magma.Initialisable;
import org.obiba.magma.ValueSet;
import org.obiba.magma.ValueTable;
import org.obiba.magma.VariableEntity;
import org.obiba.magma.support.VariableEntityBean;
import org.obiba.magma.views.View;
import org.obiba.opal.core.DeprecatedOperationException;
import org.obiba.opal.core.magma.QueryWhereClause;
import org.obiba.opal.search.service.ValuesIndexManager;
import org.obiba.opal.web.search.support.RQLParserFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand Down Expand Up @@ -48,20 +46,7 @@ public class SearchQueryWhereClause extends AbstractSearchUtility implements Que

@Override
public void initialise() {
if (!entities.isEmpty() || allEntities) return; // already initialised
try {
String esQuery = RQLParserFactory.parse(query, opalSearchService.getValuesIndexManager());
if (Strings.isNullOrEmpty(esQuery)) {
allEntities = true;
return;
}
String safeQuery = "reference:\"" + valueTable.getTableReference() + "\" AND " + esQuery;
opalSearchService.executeAllIdentifiersQuery(
buildQuerySearch(safeQuery, 0, Integer.MAX_VALUE, Lists.newArrayList("identifier"), null, null, null),
getSearchPath()).forEach(id -> entities.add(new VariableEntityBean(valueTable.getEntityType(), id)));
} catch(Exception e) {
log.error("Failed querying: {}", query, e);
}
throw new DeprecatedOperationException("Unsupported operation: since Opal 5 values are not indexed");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,19 @@
package org.obiba.opal.web.search;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;
import net.jazdw.rql.parser.ASTNode;
import org.obiba.magma.VariableEntity;
import org.obiba.magma.support.VariableEntityBean;
import org.obiba.opal.core.DeprecatedOperationException;
import org.obiba.opal.core.service.IdentifiersTableService;
import org.obiba.opal.search.AbstractSearchUtility;
import org.obiba.opal.search.service.ContingencyService;
import org.obiba.opal.search.service.QuerySettings;
import org.obiba.opal.search.service.SearchException;
import org.obiba.opal.web.model.Identifiers;
import org.obiba.opal.web.model.Search;
import org.obiba.opal.web.search.support.RQLIdentifierCriterionParser;
import org.obiba.opal.web.search.support.RQLParserFactory;
import org.obiba.opal.web.search.support.RQLValueSetVariableCriterionParser;
import org.obiba.opal.web.search.support.ValueSetVariableCriterionParser;
import org.obiba.opal.web.ws.SortDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -96,36 +88,7 @@ public Response search(@QueryParam("query") String query,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("10") int limit,
@QueryParam("counts") @DefaultValue("false") boolean withCounts) throws SearchException {
if (!canQueryEsIndex()) return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
if (Strings.isNullOrEmpty(query)) return Response.status(Response.Status.BAD_REQUEST).build();
this.entityType = entityType;

final RQLIdentifierCriterionParser idCriterion = Strings.isNullOrEmpty(idQuery) ? null : new RQLIdentifierCriterionParser(idQuery);

ASTNode queryNode = RQLParserFactory.newParser().parse(query);
List<ValueSetVariableCriterionParser> childQueries = extractChildQueries(queryNode);
List<Search.EntitiesResultDto> partialResults = Lists.newArrayList();
if (withCounts && childQueries.size() > 1) {
for (ValueSetVariableCriterionParser childQuery : childQueries) {
QuerySettings querySettings = buildHasChildQuerySearch(0, 0);
querySettings.childQuery(childQuery.asChildQuery(idCriterion == null ? null : idCriterion.getQuery()));
partialResults.add(opalSearchService.executeEntitiesQuery(querySettings, getSearchPath(), entityType, childQuery.getOriginalQuery()).build());
}
}

// global query

QuerySettings querySettings = buildHasChildQuerySearch(offset, limit);
querySettings.childQueries(childQueries.stream().map(p -> p.asChildQuery(idCriterion == null ? null : idCriterion.getQuery())).collect(Collectors.toList()));
if (childQueries.size() > 1) querySettings.childQueryOperator(queryNode.getName());
try {
Search.EntitiesResultDto.Builder dtoResponseBuilder = opalSearchService.executeEntitiesQuery(querySettings, getSearchPath(), entityType, query);
dtoResponseBuilder.addAllPartialResults(partialResults);
return Response.ok().entity(dtoResponseBuilder.build()).build();
} catch (Exception e) {
// Search engine exception
throw new SearchException("Query failed to be executed: " + query, e.getCause() == null ? e : e.getCause());
}
throw new DeprecatedOperationException("Unsupported operation: since Opal 5 values are not indexed");
}

@GET
Expand All @@ -149,26 +112,4 @@ protected String getSearchPath() {
return opalSearchService.getValuesIndexManager().getName() + "/" + entityType;
}

//
// Private methods
//

private List<ValueSetVariableCriterionParser> extractChildQueries(ASTNode queryNode) {
// for now the query must look like: and(q1,q2,...) or or(q1,q2...) or (q1,q2...) or q1,q2,...
if ("and".equals(queryNode.getName()) || "or".equals(queryNode.getName()) || "".equals(queryNode.getName()))
return queryNode.getArguments().stream().map(q -> new RQLValueSetVariableCriterionParser(opalSearchService.getValuesIndexManager(), (ASTNode) q)).collect(Collectors.toList());
else // single query
return Lists.newArrayList(new RQLValueSetVariableCriterionParser(opalSearchService.getValuesIndexManager(), queryNode));
}

private QuerySettings buildHasChildQuerySearch(int offset, int limit) {
QuerySettings querySettings = new QuerySettings();
querySettings.from(offset).size(limit).sortField("identifier", SortDir.ASC.name()).noDefaultFields();
return querySettings;
}

private boolean canQueryEsIndex() {
return searchServiceAvailable() && opalSearchService.getValuesIndexManager().isReady();
}

}

This file was deleted.

Loading

0 comments on commit 51a5208

Please sign in to comment.