Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Lucene 4 Cookbook

You're reading from  Lucene 4 Cookbook

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781782162285
Pages 220 pages
Edition 1st Edition
Languages
Authors (2):
Edwood Ng Edwood Ng
Profile icon Edwood Ng
Vineeth Mohan Vineeth Mohan
Profile icon Vineeth Mohan
View More author details

Table of Contents (16) Chapters

Lucene 4 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Introducing Lucene 2. Analyzing Your Text 3. Indexing Your Data 4. Searching Your Indexes 5. Near Real-time Searching 6. Querying and Filtering Data 7. Flexible Scoring 8. Introducing Elasticsearch 9. Extending Lucene with Modules Index

Setting up a simple Java Lucene project


Having Lucene downloaded, we can get started working with Lucene. Let's take a look at how a Lucene project is set up.

Getting ready

Java Runtime is required. If you have not installed Java yet, visit Oracle's website to download Java. Here is a link to the Java download page: http://www.oracle.com/technetwork/java/javase/downloads/index.html.

You may also want to use an IDE to work on a Lucene project. Many users prefer Eclipse IDE, but you are free to make your own choice, such as NetBeans, or whatever you prefer. If you want to give Eclipse IDE a try, you can refer to the following link: https://www.eclipse.org/downloads/.

Having set up a development environment, let's proceed to create our first Lucene project.

How to do it...

Thanks to the well-organized and efficient architecture of Lucene, the Lucene core JAR is only 2.4 MB in size. The core library provides the basic functionality to start a Lucene project. By adding it to your Java classpath, you can begin to build a powerful search engine. We will show you a couple ways to do this in Eclipse.

First, we will set up a normal Java project in Eclipse. Then, we will add Lucene libraries to the project. To do so, follow these steps:

  • Click on the Project dropdown

  • Click on Properties

  • Select Java Build Path in left side of navigation

  • Click on the Libraries tab

  • Click on Add External JARs…

  • Browse to the folder where lucene-core is located, and then select the core JAR file

  • Also, add lucene-analyzers-common and lucene-queryparser:

Another way to include the Lucene library is via Apache Maven. Maven is a project management and build tool that provides facilities to manage project development lifecycles. A detailed explanation of Maven is beyond the scope of this book. If you want to know more about Maven, you can check out the following link: http://maven.apache.org/what-is-maven.html.

To set up Lucene in Maven, you need to insert its dependency information into your project's pom.xml. You can visit a Maven repository (http://mvnrepository.com/artifact/org.apache.lucene) where you can find Lucene.

After you have updated pom.xml, the Lucene library will show up in your project after your IDE sync up dependencies.

How it works...

Once the JAR files are made available to the classpath, you can go ahead and start writing code. Both methods we described here would provide access to the Lucene library. The first method adds JARs directly. With Maven, when you add dependency to pom.xml, the JARs will be downloaded automatically.

You have been reading a chapter from
Lucene 4 Cookbook
Published in: Jun 2015 Publisher: ISBN-13: 9781782162285
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}