- Lucene 4 Cookbook
- Edwood Ng Vineeth Mohan
- 240字
- 2021-07-16 14:07:50
Obtaining a TokenStream
TokenStream is an intermediate data format between components within the analysis process. TokenStream acts as both an input and output format in all filters. For tokenizer, it consumes text from a reader and outputs result as TokenStream. Let's explore TokenStream in detail in this section.
Getting ready
The Analyzer
class is an abstract base class containing two methods of interest. The first one is createComponents
(String fieldname, Reader reader). This is where the analyzer is put together by chaining the tokenizer and filters. The second method is tokenStream
(String fieldname, Reader reader). This is the method we will review in this section. We will use the tokenStream method to return a processed TokenStream so we can examine its content after the analysis process.
How to do it...
We need two arguments to call the tokenStream
method. The first is a field name and the second is a reader:
Reader reader = new StringReader("Text to be passed");
Analyzer analyzer = new SimpleAnalyzer();
TokenStream tokenStream = analyzer.tokenStream("myField", reader);
How it works…
An analyzer processes incoming text via a Reader input. Internally, the Reader is passed on to Tokenizer, which turns the text into a TokenStream after it's been processed. From here on, TokenStream is passed around between filters in every step. TokenStream is essentially an enumeration of tokens that you can iterate through. TokenStream extends from AttributeSource
and it provides an interface to return token attributes and value.
- C程序設(shè)計(jì)簡明教程(第二版)
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- MATLAB實(shí)用教程
- TypeScript圖形渲染實(shí)戰(zhàn):基于WebGL的3D架構(gòu)與實(shí)現(xiàn)
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- 微信公眾平臺開發(fā):從零基礎(chǔ)到ThinkPHP5高性能框架實(shí)踐
- 深入分布式緩存:從原理到實(shí)踐
- 51單片機(jī)C語言開發(fā)教程
- HoloLens與混合現(xiàn)實(shí)開發(fā)
- Python機(jī)器學(xué)習(xí)與量化投資
- 零基礎(chǔ)學(xué)編程系列(全5冊)
- Moodle 3.x Developer's Guide
- Microsoft Windows Identity Foundation Cookbook
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)教程