Skip to content

Commit

Permalink
[NO_REVIEW] apache#2464 JAMES-4077 Back memory-app with Lucene
Browse files Browse the repository at this point in the history
  • Loading branch information
vttranlina committed Oct 22, 2024
1 parent 81674bb commit 98dacaf
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ enum SearchCapabilities {
Text,
FullText,
Attachment,
AttachmentFileName
AttachmentFileName,
HighlightSearch
}

EnumSet<SearchCapabilities> getSupportedSearchCapabilities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ public org.apache.james.events.Group getDefaultGroup() {

@Override
public EnumSet<SearchCapabilities> getSupportedCapabilities(EnumSet<MailboxManager.MessageCapabilities> messageCapabilities) {
return EnumSet.of(SearchCapabilities.MultimailboxSearch);

return EnumSet.of(SearchCapabilities.MultimailboxSearch,
SearchCapabilities.AttachmentFileName,
SearchCapabilities.HighlightSearch);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.Locale;
import java.util.Optional;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageId;
Expand Down Expand Up @@ -85,6 +88,8 @@ public LuceneSearchHighlighter(LuceneMessageSearchIndex luceneMessageSearchIndex
this.formatter = new SimpleHTMLFormatter(searchHighlighterConfiguration.preTagFormatter(), searchHighlighterConfiguration.postTagFormatter());
}

@Inject
@Singleton
public LuceneSearchHighlighter(LuceneMessageSearchIndex luceneMessageSearchIndex,
SearchHighlighterConfiguration searchHighlighterConfiguration,
MessageId.Factory messageIdFactory,
Expand All @@ -98,7 +103,7 @@ public LuceneSearchHighlighter(LuceneMessageSearchIndex luceneMessageSearchIndex

@Override
public Flux<SearchSnippet> highlightSearch(List<MessageId> messageIds, MultimailboxesSearchQuery expression, MailboxSession session) {
if (messageIds.isEmpty()) {
if (messageIds.isEmpty() || expression.getSearchQuery().getCriteria().isEmpty()) {
return Flux.empty();
}
return storeMailboxManager.getInMailboxIds(expression, session)
Expand Down
4 changes: 4 additions & 0 deletions server/apps/memory-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-lmtp</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-lucene</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-mailbox</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void main(String[] args) throws Exception {

LOGGER.info("Loading configuration {}", configuration.toString());
GuiceJamesServer server = createServer(configuration)
.combineWith(new FakeSearchMailboxModule(), new JMXServerModule())
.combineWith(new JMXServerModule())
.overrideWith(new RunArgumentsModule(args));

JamesServerMain.main(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.apache.james.events.EventListener;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex;
import org.apache.james.mailbox.lucene.search.LuceneSearchHighlighter;
import org.apache.james.mailbox.searchhighligt.SearchHighlighter;
import org.apache.james.mailbox.searchhighligt.SearchHighlighterConfiguration;
import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
import org.apache.lucene.store.Directory;
Expand All @@ -39,6 +42,9 @@ public class LuceneSearchMailboxModule extends AbstractModule {

@Override
protected void configure() {
bind(SearchHighlighter.class).to(LuceneSearchHighlighter.class)
.in(Scopes.SINGLETON);

bind(LuceneMessageSearchIndex.class).in(Scopes.SINGLETON);
bind(MessageSearchIndex.class).to(LuceneMessageSearchIndex.class);
bind(ListeningMessageSearchIndex.class).to(LuceneMessageSearchIndex.class);
Expand All @@ -53,4 +59,10 @@ protected void configure() {
Directory provideDirectory(FileSystem fileSystem) throws IOException {
return FSDirectory.open(fileSystem.getBasedir().toPath());
}

@Provides
@Singleton
SearchHighlighterConfiguration provideSearchHighlighterConfiguration() {
return SearchHighlighterConfiguration.DEFAULT;
}
}
4 changes: 4 additions & 0 deletions server/container/guice/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-jmap</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-lucene</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-mailbox</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
import org.apache.james.mailbox.store.mail.SearchThreadIdGuessingAlgorithm;
import org.apache.james.mailbox.store.mail.ThreadIdGuessingAlgorithm;
import org.apache.james.mailbox.store.mail.UidProvider;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex;
import org.apache.james.mailbox.store.user.SubscriptionMapperFactory;
import org.apache.james.user.api.DeleteUserDataTaskStep;
import org.apache.james.user.api.UsernameChangeTaskStep;
Expand All @@ -99,6 +97,7 @@ protected void configure() {
install(new MemoryDeadLetterModule());
install(new MemoryQuotaModule());
install(new MemoryQuotaSearchModule());
install(new LuceneSearchMailboxModule());

bind(MessageMapperFactory.class).to(InMemoryMailboxSessionMapperFactory.class);
bind(MailboxMapperFactory.class).to(InMemoryMailboxSessionMapperFactory.class);
Expand Down Expand Up @@ -126,7 +125,6 @@ protected void configure() {
bind(AttachmentManager.class).to(StoreAttachmentManager.class);
bind(SessionProvider.class).to(SessionProviderImpl.class);

bind(MessageSearchIndex.class).to(SimpleMessageSearchIndex.class);
bind(TextExtractor.class).to(JsoupTextExtractor.class);
bind(RightManager.class).to(StoreRightManager.class);
bind(AttachmentContentLoader.class).to(AttachmentManager.class);
Expand Down

0 comments on commit 98dacaf

Please sign in to comment.