问题
I'm new to Lucene and want to call it directly from my Java code in a Maven environment. I have tried for some time to find working examples that I can download and run. The latest tutorial on the official site is 2013 - Lucene 3.* https://cwiki.apache.org/confluence/display/lucene/LuceneFAQ#LuceneFAQ-HowdoIstartusingLucene?. The current latest version in Maven is 8.5.1
. Most non-official tutorials on the web do not contain version numbers or Fully Qualified Names. Lucene appears to change its API, syntax, and names at frequent intervals so that compile errors, ClassNotFound, and deleted methods occur.
I'd like to know:
- the current stable version
- the Lucene packages involved (is a
lucene-query
package required?) - pointers to code that works in 2020 with these versions
回答1:
The home page for the latest version of the documentation is here. This includes links to all the javadoc sections (different sections for different libraries).
It also includes links to some current working code examples (yes, there are breaking changes from pre-8 to 8+). The wiki can be unreliable in this regard, as you have seen.
The main demo is probably the best place to start to see working code examples.
Specifically, see the how to index and how to search examples.
Which packages you need depends entirely on what you are trying to do. It's unlikely that you will need the spatial analysis package, for example, unless you know you need it.
My POM typically includes these:
<properties>
<lucene.version>8.5.0</lucene.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-icu</artifactId>
<version>${lucene.version}</version>
</dependency>
</dependencies>
Sometimes I also use these:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-suggest</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
Hope that helps, or points you in the right direction, at least.
来源:https://stackoverflow.com/questions/62061712/examples-for-using-latest-version-of-lucene