Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
DocInverterPerThread.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using Lucene.Net.Analysis.Tokenattributes;
20 using Lucene.Net.Util;
21 using TokenStream = Lucene.Net.Analysis.TokenStream;
22 
23 namespace Lucene.Net.Index
24 {
25 
26  /// <summary>This is a DocFieldConsumer that inverts each field,
27  /// separately, from a Document, and accepts a
28  /// InvertedTermsConsumer to process those terms.
29  /// </summary>
30 
32  {
33  private void InitBlock()
34  {
35  singleToken = new SingleTokenAttributeSource();
36  }
37  internal DocInverter docInverter;
38  internal InvertedDocConsumerPerThread consumer;
39  internal InvertedDocEndConsumerPerThread endConsumer;
40  internal SingleTokenAttributeSource singleToken;
41 
42  internal class SingleTokenAttributeSource : AttributeSource
43  {
44  internal ITermAttribute termAttribute;
45  internal IOffsetAttribute offsetAttribute;
46 
47  internal SingleTokenAttributeSource()
48  {
49  termAttribute = AddAttribute<ITermAttribute>();
50  offsetAttribute = AddAttribute<IOffsetAttribute>();
51  }
52 
53  public void Reinit(System.String stringValue, int startOffset, int endOffset)
54  {
55  termAttribute.SetTermBuffer(stringValue);
56  offsetAttribute.SetOffset(startOffset, endOffset);
57  }
58  }
59 
60  internal DocumentsWriter.DocState docState;
61 
62  internal FieldInvertState fieldState = new FieldInvertState();
63 
64  // Used to read a string value for a field
65  internal ReusableStringReader stringReader = new ReusableStringReader();
66 
67  public DocInverterPerThread(DocFieldProcessorPerThread docFieldProcessorPerThread, DocInverter docInverter)
68  {
69  InitBlock();
70  this.docInverter = docInverter;
71  docState = docFieldProcessorPerThread.docState;
72  consumer = docInverter.consumer.AddThread(this);
73  endConsumer = docInverter.endConsumer.AddThread(this);
74  }
75 
76  public override void StartDocument()
77  {
78  consumer.StartDocument();
79  endConsumer.StartDocument();
80  }
81 
82  public override DocumentsWriter.DocWriter FinishDocument()
83  {
84  // TODO: allow endConsumer.finishDocument to also return
85  // a DocWriter
86  endConsumer.FinishDocument();
87  return consumer.FinishDocument();
88  }
89 
90  public override void Abort()
91  {
92  try
93  {
94  consumer.Abort();
95  }
96  finally
97  {
98  endConsumer.Abort();
99  }
100  }
101 
102  public override DocFieldConsumerPerField AddField(FieldInfo fi)
103  {
104  return new DocInverterPerField(this, fi);
105  }
106  }
107 }