Skip to content

Commit

Permalink
fix: added missing table ref filter as terms query (#3984)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon authored Jan 12, 2025
1 parent 594021e commit 93ac95b
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@
import com.google.common.collect.Sets;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.StoredFields;
import org.apache.lucene.index.*;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TotalHitCountCollector;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.obiba.opal.search.service.QuerySettings;
import org.obiba.opal.search.service.SearchException;
Expand Down Expand Up @@ -64,8 +57,21 @@ public Search.QueryResultDto execute(QuerySettings querySettings) throws SearchE
// Build a QueryParser
QueryParser parser = new QueryParser("content", analyzer);

// Parse a query (search for books with "Lucene" in the title)
// Parse a query
Query query = parser.parse(querySettings.getQuery());
if (querySettings.hasFilterReferences()) {
// at least one table-ref must match
BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
for (String tableRef : querySettings.getFilterReferences()) {
queryBuilder.add(new TermQuery(new Term("table-ref", tableRef)), BooleanClause.Occur.SHOULD);
}
Query termsQuery = queryBuilder.build();

queryBuilder = new BooleanQuery.Builder();
queryBuilder.add(new BooleanClause(query, BooleanClause.Occur.MUST));
queryBuilder.add(new BooleanClause(termsQuery, BooleanClause.Occur.MUST));
query = queryBuilder.build();
}
String lastDoc = querySettings.getLastDoc();
ScoreDoc lastScoreDoc = Strings.isNullOrEmpty(lastDoc) ? null : ScoreDocSerializer.deserialize(lastDoc);

Expand Down

0 comments on commit 93ac95b

Please sign in to comment.