Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public IndexAnalysisSettings3[] read(IndexReader reader, int n) throws IOExcepti
}
TopDocs top = searcher.search(q, n);

int nres = top.totalHits.value > n ? n : (int) top.totalHits.value;
int nres = top.totalHits.value() > n ? n : (int) top.totalHits.value();
IndexAnalysisSettings3[] res = new IndexAnalysisSettings3[nres];

IndexAnalysisSettingsUpgrader upgrader = new IndexAnalysisSettingsUpgrader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2088,10 +2088,10 @@ public static Document getDocument(File file) throws ParseException, IOException
Statistics stat = new Statistics();
TopDocs top = searcher.search(q, 1);
stat.report(LOGGER, Level.FINEST,
String.format("search via getDocument(%s) done (%d hits)", file, top.totalHits.value),
String.format("search via getDocument(%s) done (%d hits)", file, top.totalHits.value()),
"search.latency", new String[]{"category", "getdocument",
"outcome", top.totalHits.value == 0 ? "empty" : "success"});
if (top.totalHits.value == 0) {
"outcome", top.totalHits.value() == 0 ? "empty" : "success"});
if (top.totalHits.value() == 0) {
// No hits, no document...
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class NumLinesLOCAccessor {
*/
public boolean hasStored(IndexReader reader) throws IOException {
DSearchResult searchResult = newDSearch(reader, 1);
return searchResult.hits.totalHits.value > 0;
return searchResult.hits.totalHits.value() > 0;
}

/**
Expand Down Expand Up @@ -121,8 +121,8 @@ private void storeBulk(IndexWriter writer, IndexReader reader,

// Index the existing document IDs by QueryBuilder.D.
HashMap<String, Integer> byDir = new HashMap<>();
int intMaximum = Integer.MAX_VALUE < searchResult.hits.totalHits.value ?
Integer.MAX_VALUE : (int) searchResult.hits.totalHits.value;
int intMaximum = Integer.MAX_VALUE < searchResult.hits.totalHits.value() ?
Integer.MAX_VALUE : (int) searchResult.hits.totalHits.value();
StoredFields storedFields = searchResult.searcher.storedFields();
for (int i = 0; i < intMaximum; ++i) {
int docID = searchResult.hits.scoreDocs[i].doc;
Expand All @@ -148,7 +148,7 @@ private void storeIterative(IndexWriter writer, IndexReader reader,
TopDocs hits = searcher.search(query, 1);

Integer docID = null;
if (hits.totalHits.value > 0) {
if (hits.totalHits.value() > 0) {
docID = hits.scoreDocs[0].doc;
}
updateDocumentData(writer, searcher, entry, docID, isAggregatingDeltas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ protected Query buildQuery(String field, String queryText)
*/
private boolean hasClause(BooleanQuery query, Occur occur) {
for (BooleanClause clause : query) {
if (clause.getOccur().equals(occur)) {
if (clause.occur().equals(occur)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void searchIndex(IndexSearcher searcher, boolean paging) throws IOExcept
topDocs = searcher.search(query, new TopFieldCollectorManager(luceneSort, numHits, Short.MAX_VALUE));
}
hits = topDocs.scoreDocs;
totalHits = (int) topDocs.totalHits.value;
totalHits = (int) topDocs.totalHits.value();

Statistics stat = new Statistics();
stat.report(LOGGER, Level.FINEST, "search via SearchEngine done",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void getTerms(Query query) {
private void getBooleans(BooleanQuery query) {
for (BooleanClause clause : query) {
if (!clause.isProhibited()) {
getTerms(clause.getQuery());
getTerms(clause.query());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected List<CharSequence[]> loadFieldValues(String[] fields,
protected OffsetSource getOptimizedOffsetSource(UHComponents components) {

OffsetSource res = super.getOptimizedOffsetSource(components);
String field = components.getField();
String field = components.field();
if (res == OffsetSource.ANALYSIS) {
/*
Testing showed that UnifiedHighlighter falls back to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void getRegexp(RegexpQuery query) {
private void getBooleans(BooleanQuery query) {
for (BooleanClause clause : query) {
if (!clause.isProhibited()) {
getTerms(clause.getQuery());
getTerms(clause.query());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public SearchHelper executeQuery() {
}
try {
TopFieldDocs fdocs = searcher.search(query, start + maxItems, sort);
totalHits = fdocs.totalHits.value;
totalHits = fdocs.totalHits.value();
hits = fdocs.scoreDocs;

/*
Expand Down Expand Up @@ -743,7 +743,7 @@ public int searchSingle(File file) throws IOException,
query = singleBuilder.setPath(path).build();

TopDocs top = searcher.search(query, 1);
if (top.totalHits.value == 0) {
if (top.totalHits.value() == 0) {
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOBooleanSupplier;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -109,6 +110,11 @@ public boolean seekExact(BytesRef bytesRef) throws IOException {
return false;
}

@Override
public IOBooleanSupplier prepareSeekExact(BytesRef bytesRef) throws IOException {
return null;
}

@Override
public SeekStatus seekCeil(BytesRef bytesRef) throws IOException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ protected Query getBooleanQuery(final List<BooleanClause> clauses) throws ParseE
return super.getBooleanQuery(clauses);
}
var reducedList = clauses.stream()
.filter(booleanClause -> BooleanClause.Occur.SHOULD != booleanClause.getOccur())
.filter(booleanClause -> BooleanClause.Occur.SHOULD != booleanClause.occur())
.collect(Collectors.toList());
inSuggesterClausesList.stream()
.filter(booleanClause -> BooleanClause.Occur.SHOULD == booleanClause.getOccur())
.filter(booleanClause -> BooleanClause.Occur.SHOULD == booleanClause.occur())
.forEach(reducedList::add);
return super.getBooleanQuery(reducedList);
}

private boolean isInSuggesterClauses(BooleanClause clause) {
return suggesterClauses.stream()
.anyMatch(itemClause ->
clause.getQuery().equals(itemClause.getQuery())
clause.query().equals(itemClause.query())
);
}

Expand All @@ -157,7 +157,7 @@ protected BooleanClause newBooleanClause(final Query q, final BooleanClause.Occu
bc = super.newBooleanClause(((SuggesterPhraseQuery) q).getPhraseQuery(), BooleanClause.Occur.MUST);
suggesterClauses.add(bc);
} else if (q instanceof SuggesterQuery) {
bc = super.newBooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bc = super.newBooleanClause(MatchAllDocsQuery.INSTANCE, BooleanClause.Occur.MUST);
suggesterClauses.add(bc);
} else if (q instanceof BooleanQuery) {
bc = super.newBooleanClause(q, occur);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Portions Copyright (c) 2018, 2020, Chris Fraire <cfraire@me.com>.
</scm>

<properties>
<lucene.version>9.12.3</lucene.version>
<lucene.version>10.4.0</lucene.version>
<mavenjavadocplugin.version>3.6.0</mavenjavadocplugin.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public void setScorer(Scorable scorer) throws IOException {
// it is mentioned in the documentation that #getChildren should not be called
// in #setScorer but no better way was found
for (var childScorer : scorer.getChildren()) {
if (childScorer.child instanceof PhraseScorer) {
data.scorer = (PhraseScorer) childScorer.child;
if (childScorer.child() instanceof PhraseScorer) {
data.scorer = (PhraseScorer) childScorer.child();
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private boolean needPositionsAndFrequencies(final Query query) {

if (query instanceof BooleanQuery) {
for (BooleanClause bc : ((BooleanQuery) query).clauses()) {
if (needPositionsAndFrequencies(bc.getQuery())) {
if (needPositionsAndFrequencies(bc.query())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static List<Term> intoTerms(final Query query) {

if (q instanceof BooleanQuery) {
for (BooleanClause bc : ((BooleanQuery) q).clauses()) {
queue.add(bc.getQuery());
queue.add(bc.query());
}
} else if (q instanceof TermQuery) {
terms.add(((TermQuery) q).getTerm());
Expand Down Expand Up @@ -164,7 +164,7 @@ public static List<Term> intoTermsExceptPhraseQuery(final Query query) {

if (q instanceof BooleanQuery) {
for (BooleanClause bc : ((BooleanQuery) q).clauses()) {
queue.add(bc.getQuery());
queue.add(bc.query());
}
} else if (q instanceof TermQuery) {
terms.add(((TermQuery) q).getTerm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.search.Weight;
import org.jetbrains.annotations.NotNull;
import org.opengrok.suggest.query.PhraseScorer;
import org.opengrok.suggest.query.data.BitIntsHolder;
Expand Down Expand Up @@ -71,11 +70,10 @@ private static class PostingsAndPosition {
* @param offset the offset that is added to the found match position
*/
CustomExactPhraseScorer(
final Weight weight,
final CustomPhraseQuery.PostingsAndFreq[] postings,
final int offset
) {
super(weight);
super();

this.offset = offset; // custom

Expand Down Expand Up @@ -128,7 +126,7 @@ public DocIdSetIterator iterator() {

@Override
public String toString() {
return "CustomExactPhraseScorer(" + weight + ")"; // custom – renamed class
return "CustomExactPhraseScorer(" + this.offset + ")"; // custom – renamed class
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryVisitor;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.ScorerSupplier;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
Expand Down Expand Up @@ -224,7 +224,7 @@ public String toString(String f) {
@Override
public Query rewrite(IndexSearcher indexSearcher) {
if (terms.length == 0) {
return new MatchAllDocsQuery();
return MatchAllDocsQuery.INSTANCE;
}

return this;
Expand Down Expand Up @@ -263,8 +263,8 @@ public Explanation explain(LeafReaderContext leafReaderContext, int i) {
}

@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
LeafReader reader = context.reader();
public ScorerSupplier scorerSupplier(LeafReaderContext leafReaderContext) throws IOException {
LeafReader reader = leafReaderContext.reader();

CustomPhraseQuery.PostingsAndFreq[] postingsFreqs = new CustomPhraseQuery.PostingsAndFreq[query.terms.length];

Expand All @@ -281,7 +281,7 @@ public Scorer scorer(LeafReaderContext context) throws IOException {

for(int i = 0; i < query.terms.length; ++i) {
Term t = query.terms[i];
TermState state = this.states[i].get(context);
TermState state = this.states[i].get(leafReaderContext).get();
if (state == null) {
return null;
}
Expand All @@ -294,9 +294,13 @@ public Scorer scorer(LeafReaderContext context) throws IOException {
if (query.slop == 0) {
ArrayUtil.timSort(postingsFreqs);

return new CustomExactPhraseScorer(this, postingsFreqs, query.offset);
//FIXME
//return new CustomExactPhraseScorer(postingsFreqs, query.offset);
return scorerSupplier(leafReaderContext);
} else {
return new CustomSloppyPhraseScorer(this, postingsFreqs, query.slop, query.offset);
//FIXME
//return new CustomSloppyPhraseScorer(postingsFreqs, query.slop, query.offset);
return scorerSupplier(leafReaderContext);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above will need to be addressed, I'd like to see test runs first

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.FixedBitSet;
import org.jetbrains.annotations.NotNull;
import org.opengrok.suggest.query.PhraseScorer;
Expand Down Expand Up @@ -78,12 +77,11 @@ final class CustomSloppyPhraseScorer extends Scorer implements PhraseScorer { //
* @param offset the offset that is added to the found match position
*/
CustomSloppyPhraseScorer(
final Weight weight,
final CustomPhraseQuery.PostingsAndFreq[] postings,
final int slop,
final int offset
) {
super(weight);
super();
this.slop = slop;
this.offset = offset; // custom
this.numPostings = postings.length;
Expand Down Expand Up @@ -628,7 +626,7 @@ public float score() {

@Override
public String toString() {
return "CustomSloppyPhraseScorer(" + weight + ")"; // custom – renamed class
return "CustomSloppyPhraseScorer(" + this.numPostings + ")"; // custom – renamed class
}

@Override
Expand Down
Loading