Skip to content

Commit

Permalink
refactor: used StoredFields recommended in apache/lucene#11998
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Van committed Aug 25, 2023
1 parent 87be688 commit 90b02d0
Showing 1 changed file with 8 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.StoredFields;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
Expand Down Expand Up @@ -490,9 +491,10 @@ private boolean loadDocs() {
query = addDescendantClauseIfRequired(query, plan);

TopDocs topDocs = searcher.search(query, 100);
StoredFields storedFields = searcher.storedFields();
if (topDocs.totalHits.value > 0) {
for (ScoreDoc doc : topDocs.scoreDocs) {
Document retrievedDoc = searcher.doc(doc.doc);
Document retrievedDoc = storedFields.document(doc.doc);
String prefix = filter.getPath();
if (prefix.length() == 1) {
prefix = "";
Expand Down Expand Up @@ -522,9 +524,10 @@ private boolean loadDocs() {
query = addDescendantClauseIfRequired(query, plan);

TopDocs topDocs = searcher.search(query, 100);
StoredFields storedFields = searcher.storedFields();
if (topDocs.totalHits.value > 0) {
for (ScoreDoc doc : topDocs.scoreDocs) {
Document retrievedDoc = searcher.doc(doc.doc);
Document retrievedDoc = storedFields.document(doc.doc);
String prefix = filter.getPath();
if (prefix.length() == 1) {
prefix = "";
Expand Down Expand Up @@ -1475,26 +1478,7 @@ public boolean visit(FullTextAnd and) {
public boolean visit(FullTextTerm term) {
return visitTerm(term.getPropertyName(), term.getText(), term.getBoost(), term.isNot());
}

// private boolean visitTerm(String propertyName, String text, String boost, boolean not) {
// String p = getLuceneFieldName(propertyName, pr);
// Query q = tokenToQuery(text, p, pr, analyzer, augmentor);
// if (q == null) {
// return false;
// }
// if (boost != null) {
//
// q.setBoost(Float.parseFloat(boost));
// }
// if (not) {
// BooleanQuery bq = new BooleanQuery();
// bq.add(q, MUST_NOT);
// result.set(bq);
// } else {
// result.set(q);
// }
// return true;
// }

private boolean visitTerm(String propertyName, String text, String boost, boolean not) {
String p = getLuceneFieldName(propertyName, pr);
Query q = tokenToQuery(text, p, pr, analyzer, augmentor);
Expand Down Expand Up @@ -1547,53 +1531,7 @@ static String getLuceneFieldName(@Nullable String p, PlanResult pr) {
}
return p;
}

// private static Query tokenToQuery(String text, String fieldName, PlanResult pr, Analyzer analyzer,
// FulltextQueryTermsProvider augmentor) {
// Query ret;
// IndexingRule indexingRule = pr.indexingRule;
// //Expand the query on fulltext field
// if (FieldNames.FULLTEXT.equals(fieldName) &&
// !indexingRule.getNodeScopeAnalyzedProps().isEmpty()) {
// BooleanQuery in = new BooleanQuery();
// for (PropertyDefinition pd : indexingRule.getNodeScopeAnalyzedProps()) {
// Query q = tokenToQuery(text, FieldNames.createAnalyzedFieldName(pd.name), analyzer);
// q.setBoost(pd.boost);
// in.add(q, BooleanClause.Occur.SHOULD);
// }
//
// //Add the query for actual fulltext field also. That query would
// //not be boosted
// in.add(tokenToQuery(text, fieldName, analyzer), BooleanClause.Occur.SHOULD);
// ret = in;
// } else {
// ret = tokenToQuery(text, fieldName, analyzer);
// }
//
// //Augment query terms if available (as a 'SHOULD' clause)
// if (FieldNames.FULLTEXT.equals(fieldName)) {
// Query subQuery = new BooleanQuery();
// if (pr.indexDefinition.isDynamicBoostLiteEnabled()) {
// subQuery = tokenToQuery(text, FieldNames.SIMILARITY_TAGS, analyzer);
// // De-boosting dynamic boost based query so other clauses will have more relevance
// subQuery.setBoost(DYNAMIC_BOOST_WEIGHT);
// } else if (augmentor != null) {
// subQuery = augmentor.getQueryTerm(text, analyzer, pr.indexDefinition.getDefinitionNodeState());
// }
//
// if (subQuery != null) {
// BooleanQuery query = new BooleanQuery();
//
// query.add(ret, BooleanClause.Occur.SHOULD);
// query.add(subQuery, BooleanClause.Occur.SHOULD);
//
// ret = query;
// }
// }
//
// return ret;
// }


private static Query tokenToQuery(String text, String fieldName, PlanResult pr, Analyzer analyzer, FulltextQueryTermsProvider augmentor) {
Query ret;
IndexingRule indexingRule = pr.indexingRule;
Expand All @@ -1619,7 +1557,7 @@ private static Query tokenToQuery(String text, String fieldName, PlanResult pr,
} else if (augmentor != null) {
subQuery = augmentor.getQueryTerm(text, analyzer, pr.indexDefinition.getDefinitionNodeState());
}

if (subQuery != null) {
BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
queryBuilder.add(ret, BooleanClause.Occur.SHOULD);
Expand Down Expand Up @@ -1653,7 +1591,6 @@ private static Query newDepthQuery(String path, PlanResult planResult) {
return IntPoint.newExactQuery(FieldNames.PATH_DEPTH, depth);
}

@SuppressWarnings("Guava")
private static Iterator<FulltextResultRow> mergePropertyIndexResult(IndexPlan plan, NodeState rootState,
Iterator<FulltextResultRow> itr) {
PlanResult pr = getPlanResult(plan);
Expand Down

0 comments on commit 90b02d0

Please sign in to comment.