Skip to content

Commit 165ccb4

Browse files
committed
Upgrade lucene 9.12.3 -> 10.3.2
1 parent a5f2ed5 commit 165ccb4

6 files changed

Lines changed: 82 additions & 48 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Upgrade Lucene to 10.3.2
2+
SELECT core.executeJavaUpgradeCode('reindex');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Upgrade Lucene to 10.3.2
2+
EXEC core.executeJavaUpgradeCode 'reindex';

search/src/org/labkey/search/SearchMcp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class SearchMcp implements McpService.McpImpl
2323
{
2424
final static String mdSearchHelp = """
25-
The search functionality is implmeneted by Lucene. The query syntax is
25+
The search functionality is implemented by Lucene. The query syntax is
2626
2727
Core Syntax Elements
2828

search/src/org/labkey/search/SearchModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public String getName()
8585
@Override
8686
public Double getSchemaVersion()
8787
{
88-
return 26.000;
88+
return 26.001;
8989
}
9090

9191
@Override

search/src/org/labkey/search/model/LuceneSearchServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
import org.labkey.api.files.FileSystemDirectoryListener;
8181
import org.labkey.api.files.FileSystemWatchers;
8282
import org.labkey.api.mbean.SearchMXBean;
83-
import org.labkey.api.module.ModuleLoader;
8483
import org.labkey.api.portal.ProjectUrls;
8584
import org.labkey.api.resource.Resource;
8685
import org.labkey.api.search.SearchService;
@@ -114,7 +113,6 @@
114113
import org.labkey.api.util.logging.LogHelper;
115114
import org.labkey.api.view.ActionURL;
116115
import org.labkey.api.view.UnauthorizedException;
117-
import org.labkey.api.view.WebPartView;
118116
import org.labkey.api.webdav.FileSystemResource;
119117
import org.labkey.api.webdav.SimpleDocumentResource;
120118
import org.labkey.api.webdav.WebdavResource;
@@ -1428,7 +1426,7 @@ private long getDocCount(Query query) throws IOException
14281426
try
14291427
{
14301428
TopDocs docs = searcher.search(query, 1);
1431-
return docs.totalHits.value;
1429+
return docs.totalHits.value(); // TODO: This may not be exact, could be a lower bound. See totalHits.relation().
14321430
}
14331431
finally
14341432
{
@@ -1842,7 +1840,7 @@ private void processSearchResult(int offset, int hitsToRetrieve, TopDocs topDocs
18421840
}
18431841

18441842
result.offset = offset;
1845-
result.totalHits = topDocs.totalHits.value;
1843+
result.totalHits = topDocs.totalHits.value(); // TODO: This may not be exact, could be a lower bound. See totalHits.relation().
18461844
result.hits = ret;
18471845
}
18481846

search/src/org/labkey/search/model/SecurityQuery.java

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import org.apache.lucene.search.QueryVisitor;
2828
import org.apache.lucene.search.ScoreMode;
2929
import org.apache.lucene.search.Scorer;
30+
import org.apache.lucene.search.ScorerSupplier;
3031
import org.apache.lucene.search.Weight;
3132
import org.apache.lucene.util.BitSetIterator;
3233
import org.apache.lucene.util.BytesRef;
3334
import org.apache.lucene.util.FixedBitSet;
3435
import org.jetbrains.annotations.NotNull;
36+
import org.jetbrains.annotations.Nullable;
3537
import org.labkey.api.data.Container;
3638
import org.labkey.api.data.ContainerManager;
3739
import org.labkey.api.module.Module;
@@ -96,64 +98,94 @@ public boolean isCacheable(LeafReaderContext ctx)
9698

9799
private boolean isReadable(String containerId, String categories)
98100
{
99-
// return _containerIds.containsKey(containerId);
100101
if (StringUtils.isEmpty(categories) || !_categoryContainers.containsKey(categories))
101102
return _containerIds.containsKey(containerId);
102103
else
103104
return _categoryContainers.get(categories).contains(containerId);
104105
}
105106

106107
@Override
107-
public Scorer scorer(LeafReaderContext context) throws IOException
108+
public ScorerSupplier scorerSupplier(LeafReaderContext context)
108109
{
109-
SearchService.SEARCH_PHASE currentPhase = _iTimer.getCurrentPhase();
110-
_iTimer.setPhase(SearchService.SEARCH_PHASE.applySecurityFilter);
111-
112-
LeafReader reader = context.reader();
113-
int maxDoc = reader.maxDoc();
114-
FixedBitSet bits = new FixedBitSet(maxDoc);
110+
return new ScorerSupplier()
111+
{
112+
private final LeafReader _reader;
113+
private final @Nullable BinaryDocValues _securityContextDocValues;
115114

116-
BinaryDocValues securityContextDocValues = reader.getBinaryDocValues(FIELD_NAME.securityContext.name());
115+
{
116+
SearchService.SEARCH_PHASE currentPhase = _iTimer.getCurrentPhase();
117117

118-
try
119-
{
120-
int doc;
118+
try
119+
{
120+
_iTimer.setPhase(SearchService.SEARCH_PHASE.applySecurityFilter);
121+
_reader = context.reader();
122+
_securityContextDocValues = _reader.getBinaryDocValues(FIELD_NAME.securityContext.name());
123+
}
124+
catch (IOException e)
125+
{
126+
throw new RuntimeException(e);
127+
}
128+
finally
129+
{
130+
_iTimer.setPhase(currentPhase);
131+
}
132+
}
121133

122-
// Can be null, if no documents (e.g., shortly after bootstrap or clear index)
123-
if (null != securityContextDocValues)
134+
@Override
135+
public Scorer get(long leadCost) throws IOException
124136
{
125-
while (NO_MORE_DOCS != (doc = securityContextDocValues.nextDoc()))
137+
SearchService.SEARCH_PHASE currentPhase = _iTimer.getCurrentPhase();
138+
139+
try
126140
{
127-
BytesRef bytesRef = securityContextDocValues.binaryValue();
128-
String securityContext = StringUtils.trimToNull(bytesRef.utf8ToString());
129-
130-
final String containerId;
131-
final String resourceId;
132-
final String categories;
133-
String[] parts = StringUtils.split(securityContext, "|");
134-
// SecurityContext is usually just a container ID and a string of categories, but in some cases it adds a resource ID.
135-
containerId = parts[0];
136-
if (parts.length > 1)
137-
categories = parts[1];
138-
else
139-
categories = null;
140-
if (parts.length > 2)
141-
resourceId = parts[2];
142-
else
143-
resourceId = null;
144-
145-
// Must have read permission on the container (always). Must also have read permissions on resource ID, if non-null.
146-
if (isReadable(containerId, categories) && (null == resourceId || canReadResource(resourceId, containerId)))
147-
bits.set(doc);
141+
_iTimer.setPhase(SearchService.SEARCH_PHASE.applySecurityFilter);
142+
int maxDoc = _reader.maxDoc();
143+
FixedBitSet bits = new FixedBitSet(maxDoc);
144+
int doc;
145+
146+
// Can be null, if no documents (e.g., shortly after bootstrap or clear index)
147+
if (null != _securityContextDocValues)
148+
{
149+
while (NO_MORE_DOCS != (doc = _securityContextDocValues.nextDoc()))
150+
{
151+
BytesRef bytesRef = _securityContextDocValues.binaryValue();
152+
String securityContext = StringUtils.trimToNull(bytesRef.utf8ToString());
153+
154+
final String containerId;
155+
final String resourceId;
156+
final String categories;
157+
String[] parts = StringUtils.split(securityContext, "|");
158+
// SecurityContext is usually just a container ID and a string of categories, but in some cases it adds a resource ID.
159+
containerId = parts[0];
160+
if (parts.length > 1)
161+
categories = parts[1];
162+
else
163+
categories = null;
164+
if (parts.length > 2)
165+
resourceId = parts[2];
166+
else
167+
resourceId = null;
168+
169+
// Must have read permission on the container (always). Must also have read permissions on resource ID, if non-null.
170+
if (isReadable(containerId, categories) && (null == resourceId || canReadResource(resourceId, containerId)))
171+
bits.set(doc);
172+
}
173+
}
174+
175+
return new ConstantScoreScorer(score(), scoreMode, new BitSetIterator(bits, bits.approximateCardinality()));
176+
}
177+
finally
178+
{
179+
_iTimer.setPhase(currentPhase);
148180
}
149181
}
150182

151-
return new ConstantScoreScorer(this, score(), scoreMode, new BitSetIterator(bits, bits.approximateCardinality()));
152-
}
153-
finally
154-
{
155-
_iTimer.setPhase(currentPhase);
156-
}
183+
@Override
184+
public long cost()
185+
{
186+
return null == _securityContextDocValues ? 0 : _securityContextDocValues.cost();
187+
}
188+
};
157189
}
158190
};
159191
}

0 commit comments

Comments
 (0)