Search icon
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
Introducing Lucene Analyzing Your Text Indexing Your Data Searching Your Indexes Near Real-time Searching Querying and Filtering Data Flexible Scoring Introducing Elasticsearch Extending Lucene with Modules Index

Creating a TextField


Don't be confused between a StringField and TextField. Although both the fields contain textual data, there are major differences between these two fields. A StringField is not tokenized and it's a good tool for exact match and sorting. A TextField is tokenized and it's useful for storing any unstructured text for indexing. When you pass the text into an Analyzer for indexing, a TextField is what's used to store the text content.

How to do it...

Similar to the way in which a StringField is set, adding a TextField is also very straightforward. Let's review how it's done:

    Document document = new Document();
    String text = "Lucene is an Information Retrieval library written in Java.";
    doc.add(new TextField("text", text, Field.Store.YES));
    indexWriter.addDocument(document);
    indexWriter.commit();

How it works...

This is a very simple example showing how a TextField is added, assuming that you have an Analyzer already created for the IndexWriter on the text field...

lock icon The rest of the chapter is locked
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}