- Lucene 4 Cookbook
- Edwood Ng Vineeth Mohan
- 269字
- 2021-07-16 14:07:48
Creating fields
We have learned that indexing information in Lucene requires the creation of document objects. A Lucene document contains one or more field where each one represents a single data point about the document. A field can be a title, description, article ID, and so on. In this section, we will show you the basic structure and how to create a field.
A Lucene field has three attributes:
- Name
- Type
- Value
Name and value are self-explanatory. You can think of a name as a column name in a table, and value as a value in one of the records where record itself is a document. Type determines how the field is treated. You can set FieldType
to control whether to store value, to index it or even tokenize text. A Lucene field can hold the following:
- String
- Reader or preanalyzed TokenStream
- Binary(byte[])
- Numeric value
How to do it...
This code snippet shows you how to create a simple TextField
:
Document doc = new Document(); String text = "Lucene is an Information Retrieval library written in Java."; doc.add(new TextField("fieldname", text, Field.Store.YES));
How It Works
In this scenario, we create a document object, initialize a text, and add a field by creating a TextField
object. We also configure the field to store a value so it can be retrieved during a search.
A Lucene document is a collection of field objects. A field is the name of the value pairs, which you may add to the document. A field is created by simply instantiating one of the Field
classes. Field can be inserted into a document via the add method.
- Architecting the Industrial Internet
- Podman實(shí)戰(zhàn)
- Learning Hunk
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)指導(dǎo)
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- 大數(shù)據(jù)分析與應(yīng)用實(shí)戰(zhàn):統(tǒng)計(jì)機(jī)器學(xué)習(xí)之?dāng)?shù)據(jù)導(dǎo)向編程
- Building Android UIs with Custom Views
- HTML5開發(fā)精要與實(shí)例詳解
- 從零開始學(xué)Android開發(fā)
- Learning Unreal Engine Game Development
- Solr權(quán)威指南(下卷)
- Java自然語言處理(原書第2版)
- 編譯原理學(xué)習(xí)與實(shí)踐指導(dǎo)
- 計(jì)算機(jī)信息技術(shù)實(shí)踐教程
- 亮劍ASP.NET項(xiàng)目開發(fā)案例導(dǎo)航