-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CandidateMatcher public matching functions #13632
Merged
romseygeek
merged 2 commits into
apache:main
from
bjacobowitz:upstream-public-matcher-funcs
Aug 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
...tor/src/test/org/apache/lucene/monitor/outsidepackage/TestCandidateMatcherVisibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.lucene.monitor.outsidepackage; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import org.apache.lucene.index.BinaryDocValues; | ||
import org.apache.lucene.index.ByteVectorValues; | ||
import org.apache.lucene.index.DocValuesSkipper; | ||
import org.apache.lucene.index.FieldInfos; | ||
import org.apache.lucene.index.FloatVectorValues; | ||
import org.apache.lucene.index.LeafMetaData; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.apache.lucene.index.NumericDocValues; | ||
import org.apache.lucene.index.PointValues; | ||
import org.apache.lucene.index.SortedDocValues; | ||
import org.apache.lucene.index.SortedNumericDocValues; | ||
import org.apache.lucene.index.SortedSetDocValues; | ||
import org.apache.lucene.index.StoredFieldVisitor; | ||
import org.apache.lucene.index.StoredFields; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.index.TermVectors; | ||
import org.apache.lucene.index.Terms; | ||
import org.apache.lucene.monitor.CandidateMatcher; | ||
import org.apache.lucene.monitor.QueryMatch; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.search.KnnCollector; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.util.Bits; | ||
import org.apache.lucene.util.Version; | ||
import org.junit.Test; | ||
|
||
public class TestCandidateMatcherVisibility { | ||
|
||
// Dummy empty IndexReader for use in creating a matcher | ||
private LeafReader dummyIndexReader() { | ||
return new LeafReader() { | ||
@Override | ||
public int maxDoc() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int numDocs() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public FieldInfos getFieldInfos() { | ||
return FieldInfos.EMPTY; | ||
} | ||
|
||
@Override | ||
public Bits getLiveDocs() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Terms terms(String field) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public TermVectors termVectors() { | ||
return TermVectors.EMPTY; | ||
} | ||
|
||
@Override | ||
public NumericDocValues getNumericDocValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public BinaryDocValues getBinaryDocValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SortedDocValues getSortedDocValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SortedNumericDocValues getSortedNumericDocValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SortedSetDocValues getSortedSetDocValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public NumericDocValues getNormValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DocValuesSkipper getDocValuesSkipper(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public PointValues getPointValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public FloatVectorValues getFloatVectorValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ByteVectorValues getByteVectorValues(String field) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void searchNearestVectors( | ||
String field, float[] target, KnnCollector knnCollector, Bits acceptDocs) {} | ||
|
||
@Override | ||
public void searchNearestVectors( | ||
String field, byte[] target, KnnCollector knnCollector, Bits acceptDocs) {} | ||
|
||
@Override | ||
protected void doClose() {} | ||
|
||
@Override | ||
public StoredFields storedFields() { | ||
return new StoredFields() { | ||
@Override | ||
public void document(int doc, StoredFieldVisitor visitor) {} | ||
}; | ||
} | ||
|
||
@Override | ||
public void checkIntegrity() throws IOException {} | ||
|
||
@Override | ||
public LeafMetaData getMetaData() { | ||
return new LeafMetaData(Version.LATEST.major, Version.LATEST, null, false); | ||
} | ||
|
||
@Override | ||
public CacheHelper getCoreCacheHelper() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CacheHelper getReaderCacheHelper() { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
private CandidateMatcher<QueryMatch> newCandidateMatcher() { | ||
// Dummy searcher for use in creating a matcher | ||
final IndexSearcher mockSearcher = new IndexSearcher(dummyIndexReader()); | ||
return QueryMatch.SIMPLE_MATCHER.createMatcher(mockSearcher); | ||
} | ||
|
||
@Test | ||
public void testMatchQueryVisibleOutsidePackage() throws IOException { | ||
CandidateMatcher<QueryMatch> matcher = newCandidateMatcher(); | ||
// This should compile from outside org.apache.lucene.monitor package | ||
// (subpackage org.apache.lucene.monitor.outsidepackage cannot access package-private content | ||
// from org.apache.lucene.monitor) | ||
matcher.matchQuery("test", new TermQuery(new Term("test_field")), Collections.emptyMap()); | ||
} | ||
|
||
@Test | ||
public void testReportErrorVisibleOutsidePackage() { | ||
CandidateMatcher<QueryMatch> matcher = newCandidateMatcher(); | ||
// This should compile from outside org.apache.lucene.monitor package | ||
// (subpackage org.apache.lucene.monitor.outsidepackage cannot access package-private content | ||
// from org.apache.lucene.monitor) | ||
matcher.reportError("test", new RuntimeException("test exception")); | ||
} | ||
|
||
@Test | ||
public void testFinishVisibleOutsidePackage() { | ||
CandidateMatcher<QueryMatch> matcher = newCandidateMatcher(); | ||
// This should compile from outside org.apache.lucene.monitor package | ||
// (subpackage org.apache.lucene.monitor.outsidepackage cannot access package-private content | ||
// from org.apache.lucene.monitor) | ||
matcher.finish(0, 0); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a MemoryIndex here would probably be simpler?