-
Notifications
You must be signed in to change notification settings - Fork 2.6k
LUCENE-9476 Add getBulkPath API for the Taxonomy index #2247
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
Open
gautamworah96
wants to merge
5
commits into
apache:master
Choose a base branch
from
gautamworah96:LUCENE-9476
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a820f1
WIP: LUCENE-9476 Add basic functionality, basic tests
gautamworah96 93bbe5b
Misc. style fixes
gautamworah96 fd73d7b
Fixed small bugs, improved style. Perf test remaining
gautamworah96 f8425e4
Fixed a bug in multiple segments. The API now works for older indexes…
gautamworah96 0c53c3b
Style fix
gautamworah96 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 hidden or 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 |
---|---|---|
|
@@ -18,8 +18,10 @@ | |
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
|
@@ -314,7 +316,6 @@ public int getOrdinal(FacetLabel cp) throws IOException { | |
|
||
@Override | ||
public FacetLabel getPath(int ordinal) throws IOException { | ||
ensureOpen(); | ||
|
||
// Since the cache is shared with DTR instances allocated from | ||
// doOpenIfChanged, we need to ensure that the ordinal is one that this DTR | ||
|
@@ -324,14 +325,9 @@ public FacetLabel getPath(int ordinal) throws IOException { | |
return null; | ||
} | ||
|
||
// TODO: can we use an int-based hash impl, such as IntToObjectMap, | ||
// wrapped as LRU? | ||
Integer catIDInteger = Integer.valueOf(ordinal); | ||
synchronized (categoryCache) { | ||
FacetLabel res = categoryCache.get(catIDInteger); | ||
if (res != null) { | ||
return res; | ||
} | ||
FacetLabel ordinalPath = getPathFromCache(ordinal); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (ordinalPath != null) { | ||
return ordinalPath; | ||
} | ||
|
||
int readerIndex = ReaderUtil.subIndex(ordinal, indexReader.leaves()); | ||
|
@@ -353,12 +349,65 @@ public FacetLabel getPath(int ordinal) throws IOException { | |
} | ||
|
||
synchronized (categoryCache) { | ||
categoryCache.put(catIDInteger, ret); | ||
categoryCache.put(ordinal, ret); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
private FacetLabel getPathFromCache(int ordinal) { | ||
ensureOpen(); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// TODO: can we use an int-based hash impl, such as IntToObjectMap, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooh that is a great idea, and low-hanging fruit, and would greatly reduce the RAM usage for this cache. I think Could you open a spinoff issue? |
||
// wrapped as LRU? | ||
synchronized (categoryCache) { | ||
FacetLabel res = categoryCache.get(ordinal); | ||
if (res != null) { | ||
return res; | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
/* This API is only supported for indexes created with Lucene 8.7+ codec **/ | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public FacetLabel[] getBulkPath(int[] ordinal) throws IOException { | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FacetLabel[] bulkPath = new FacetLabel[ordinal.length]; | ||
Map<Integer, Integer> originalPosition = new HashMap<>(); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int i = 0; i < ordinal.length; i++) { | ||
if (ordinal[i] < 0 || ordinal[i] >= indexReader.maxDoc()) { | ||
return null; | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
FacetLabel ordinalPath = getPathFromCache(ordinal[i]); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (ordinalPath != null) { | ||
bulkPath[i] = ordinalPath; | ||
} | ||
originalPosition.put(ordinal[i], i); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Arrays.sort(ordinal); | ||
int readerIndex = 0; | ||
BinaryDocValues values = null; | ||
|
||
for (int ord : ordinal) { | ||
if (bulkPath[originalPosition.get(ord)] == null) { | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (values == null | ||
|| values.advanceExact(ord - indexReader.leaves().get(readerIndex).docBase) == false) { | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
readerIndex = ReaderUtil.subIndex(ord, indexReader.leaves()); | ||
LeafReader leafReader = indexReader.leaves().get(readerIndex).reader(); | ||
values = leafReader.getBinaryDocValues(Consts.FULL); | ||
assert values.advanceExact(ord - indexReader.leaves().get(readerIndex).docBase); | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
bulkPath[originalPosition.get(ord)] = | ||
new FacetLabel(FacetsConfig.stringToPath(values.binaryValue().utf8ToString())); | ||
synchronized (categoryCache) { | ||
gautamworah96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
categoryCache.put(ord, bulkPath[originalPosition.get(ord)]); | ||
} | ||
} | ||
} | ||
|
||
return bulkPath; | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
ensureOpen(); | ||
|
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.