Skip to content

Commit

Permalink
Upgrade lucence to 9.x with proper JPMS (#8362)
Browse files Browse the repository at this point in the history
* Upgrade lucence to 9.x with proper JPMS

* Pass IndexWriter on search, use try with resources

* checkstyle

* Added lucene.codecs to build.gradle and module.info

* test with providing info in merged module

* add uses

* further testing
check if index exists

* try debug mode

* add analysis and highlighter to module info

* fix some potential resource leaks

* Step lucene index version

Makes sure that all indexes are deleted before switching to lucene 9.

* reenable normale options

* try init directly

* try excluding useless codecs

* update to lucence 9.1

* try wit explicit dependency

* state use

* remove from merged

* reenable options

* cleanup some modules
Fix exception in document viewer if doc is not pdf

* checkstyle

* use old index path

* Add changelog

Co-authored-by: Carl Christian Snethlage <cc.snethlage@gmail.com>
Co-authored-by: Benedikt Tutzer <btut@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 10, 2022
1 parent b229618 commit 93177fa
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Changed

- We upgraded to Lucene 9.1 for the fulltext search. Thus, the now created search index cannot be read from older versions of JabRef anylonger and would need to be recreated if you switch back to an older version [#8362](https://github.com/JabRef/jabref/pull/8362)
- We changed the list of CSL styles to those that support formatting bibliographies [#8421](https://github.com/JabRef/jabref/issues/8421) [citeproc-java#116](https://github.com/michel-kraemer/citeproc-java/issues/116)
- The CSL preview styles now also support displaying data from cross references entries that are linked via the `crossref` field [#7378](https://github.com/JabRef/jabref/issues/7378)
- We made the Search button in Web Search wider. We also skewed the panel titles to the left [#8397](https://github.com/JabRef/jabref/issues/8397)
Expand Down
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ dependencies {
implementation 'org.apache.pdfbox:fontbox:3.0.0-RC1'
implementation 'org.apache.pdfbox:xmpbox:3.0.0-RC1'

implementation 'org.apache.lucene:lucene-core:9.1.0'
implementation 'org.apache.lucene:lucene-queryparser:9.1.0'
implementation 'org.apache.lucene:lucene-queries:9.1.0'
implementation 'org.apache.lucene:lucene-analysis-common:9.1.0'
implementation 'org.apache.lucene:lucene-highlighter:9.1.0'

implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.9.0'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation 'com.h2database:h2-mvstore:2.1.210'
Expand Down Expand Up @@ -557,7 +563,6 @@ jlink {
requires 'com.google.gson'
requires 'org.slf4j'
requires 'jakarta.xml.bind'
uses 'org.controlsfx.glyphfont.GlyphFont'
uses 'com.airhacks.afterburner.views.ResourceLocator'
uses 'com.airhacks.afterburner.injection.PresenterFactory'
uses 'org.mariadb.jdbc.credential.CredentialPlugin'
Expand All @@ -566,11 +571,7 @@ jlink {
uses 'org.mariadb.jdbc.LocalInfileInterceptor'
uses 'org.eclipse.jgit.transport.SshSessionFactory'
uses 'org.eclipse.jgit.lib.GpgSigner'
provides 'org.apache.lucene.codecs.DocValuesFormat' with 'org.apache.lucene.codecs.lucene80.Lucene80DocValuesFormat'
provides 'org.controlsfx.glyphfont.GlyphFont' with 'org.controlsfx.glyphfont.FontAwesome'
provides 'org.mariadb.jdbc.tls.TlsSocketPlugin' with 'org.mariadb.jdbc.internal.protocol.tls.DefaultTlsSocketPlugin'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.ServerProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.netty.shaded.io.grpc.netty.NettyServerProvider'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.NameResolverProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.internal.DnsNameResolverProvider'
provides 'java.sql.Driver' with 'org.postgresql.Driver'
provides 'org.mariadb.jdbc.authentication.AuthenticationPlugin' with 'org.mariadb.jdbc.internal.com.send.authentication.CachingSha2PasswordPlugin',
'org.mariadb.jdbc.internal.com.send.authentication.ClearPasswordPlugin',
Expand All @@ -584,9 +585,7 @@ jlink {
'org.mariadb.jdbc.credential.env.EnvCredentialPlugin',
'org.mariadb.jdbc.credential.system.PropertiesCredentialPlugin'
provides 'java.security.Provider' with 'org.bouncycastle.jce.provider.BouncyCastleProvider',
'org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.ManagedChannelProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider'
}
'org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider' }

jpackage {
outputDir = "distribution"
Expand Down
Binary file removed lib/lucene.jar
Binary file not shown.
23 changes: 0 additions & 23 deletions lucene-jar/lib/build.gradle

This file was deleted.

11 changes: 0 additions & 11 deletions lucene-jar/settings.gradle

This file was deleted.

17 changes: 12 additions & 5 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
with org.jabref.gui.logging.GuiWriter,
org.jabref.gui.logging.ApplicationInsightsWriter;

requires applicationinsights.logging.log4j2;

// Preferences and XML
requires java.prefs;
requires jakarta.xml.bind;
Expand All @@ -65,7 +63,6 @@
requires org.libreoffice.uno;

// Other modules
requires commons.logging;
requires com.google.common;
requires jakarta.inject;
requires reactfx;
Expand Down Expand Up @@ -101,10 +98,20 @@
requires flexmark.util.ast;
requires flexmark.util.data;
requires com.h2database.mvstore;
requires lucene;
requires org.eclipse.jgit;

// fulltext search
requires org.apache.lucene.core;
uses org.apache.lucene.codecs.lucene91.Lucene91Codec;

requires org.apache.lucene.queryparser;
uses org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
requires org.apache.lucene.analysis.common;
requires org.apache.lucene.highlighter;


requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.dataformat.yaml;
requires com.fasterxml.jackson.datatype.jsr310;
requires net.harawata.appdirs;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.StateManager;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.preferences.PreferencesService;
Expand Down Expand Up @@ -105,10 +106,13 @@ private void setCurrentEntry(BibEntry entry) {
}

private void setCurrentDocument(Path path) {
try (PDDocument document = Loader.loadPDF(path.toFile())) {
currentDocument.set(new PdfDocumentViewModel(document));
try {
if (FileUtil.isPDFFile(path)) {
PDDocument document = Loader.loadPDF(path.toFile());
currentDocument.set(new PdfDocumentViewModel(document));
}
} catch (IOException e) {
LOGGER.error("Could not set Document Viewer", e);
LOGGER.error("Could not set Document Viewer for path {}", path, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.model.pdf.search.SearchResult;
import org.jabref.model.strings.StringUtil;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
Expand All @@ -35,6 +36,8 @@ public final class PdfSearcher {

private PdfSearcher(Directory indexDirectory) {
this.indexDirectory = indexDirectory;
Codec.forName("Lucene91");

}

public static PdfSearcher of(BibDatabaseContext databaseContext) throws IOException {
Expand Down Expand Up @@ -72,6 +75,7 @@ public PdfSearchResults search(final String searchString, final int maxHits)
resultDocs.add(new SearchResult(searcher, query, scoreDoc));
}
return new PdfSearchResults(resultDocs);

} catch (ParseException e) {
LOGGER.warn("Could not parse query: '{}'!\n{}", searchString, e.getMessage());
return new PdfSearchResults();
Expand Down

0 comments on commit 93177fa

Please sign in to comment.