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
FieldSortedTermVectorMapper.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.Collections.Generic;
19 using Lucene.Net.Support;
20 
21 namespace Lucene.Net.Index
22 {
23 
24  /// <summary> For each Field, store a sorted collection of <see cref="TermVectorEntry" />s
25  /// <p/>
26  /// This is not thread-safe.
27  /// </summary>
29  {
30  private readonly IDictionary<string, SortedSet<TermVectorEntry>> fieldToTerms = new HashMap<string, SortedSet<TermVectorEntry>>();
31  private SortedSet<TermVectorEntry> currentSet;
32  private System.String currentField;
33  private readonly IComparer<TermVectorEntry> comparator;
34 
35  /// <summary> </summary>
36  /// <param name="comparator">A Comparator for sorting <see cref="TermVectorEntry" />s
37  /// </param>
38  public FieldSortedTermVectorMapper(IComparer<TermVectorEntry> comparator)
39  : this(false, false, comparator)
40  {
41  }
42 
43 
44  public FieldSortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, IComparer<TermVectorEntry> comparator)
45  : base(ignoringPositions, ignoringOffsets)
46  {
47  this.comparator = comparator;
48  }
49 
50  public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
51  {
52  var entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
53  currentSet.Add(entry);
54  }
55 
56  public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions)
57  {
58  currentSet = new SortedSet<TermVectorEntry>(comparator);
59  currentField = field;
60  fieldToTerms[field] = currentSet;
61  }
62 
63  /// <summary> Get the mapping between fields and terms, sorted by the comparator
64  ///
65  /// </summary>
66  /// <value> A map between field names and &lt;see cref=&quot;System.Collections.Generic.SortedDictionary{Object,Object}&quot; /&gt;s per field. SortedSet entries are &lt;see cref=&quot;TermVectorEntry&quot; /&gt; </value>
67  public virtual IDictionary<string, SortedSet<TermVectorEntry>> FieldToTerms
68  {
69  get { return fieldToTerms; }
70  }
71 
72 
73  public virtual IComparer<TermVectorEntry> Comparator
74  {
75  get { return comparator; }
76  }
77  }
78 }