linagora / james-project

Mirror of Apache James Project
Apache License 2.0
72 stars 62 forks source link

[SearchSnippet] Implement Lucene SearchHighlighter #5256

Open quantranhong1999 opened 1 month ago

quantranhong1999 commented 1 month ago

Why

As we plan to really use Lucene as a search option, we need to back JMAP SearchSnippet extension by implementing a Lucene Search Highlight APIs.

How

  <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-highlighter</artifactId>
      <version>${lucene.version}</version>
  </dependency>
class LuceneSearchHighlighter implements SearchHighlighter {
  Publisher<SearchSnippet> highlightSearch(MultimailboxesSearchQuery expression, MailboxSession session, long limit) {
    ...
  }
}

Using the Lucene highlight APIs: https://lucene.apache.org/core/9_0_0/highlighter/org/apache/lucene/search/highlight/package-summary.html From what I see, with Lucene, highlight works on search result - which mean we need to search again.

POC: https://github.com/quantranhong1999/james-project/commit/a8ddbe51a366ba6567fda9f8fc6e5251a8ece175

DoD

Pass contract tests

vttranlina commented 3 days ago

We can reuse class LuceneMemorySearchHighlighter (In pr Lucene memory impl ) for Lucene FS impl. The fact LuceneMemorySearchHighlighter only use lucene highlight api, it's nothing special just for memory.

vttranlina commented 9 hours ago

Pr: https://github.com/apache/james-project/pull/2438/