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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 namespace Mono.Lucene.Net.Index
23 /// <summary> For each Field, store position by position information. It ignores frequency information
25 /// This is not thread-safe.
27 public class PositionBasedTermVectorMapper:TermVectorMapper
29 private System.Collections.IDictionary fieldToTerms;
31 private System.String currentField;
32 /// <summary> A Map of Integer and TVPositionInfo</summary>
33 private System.Collections.IDictionary currentPositions;
34 private bool storeOffsets;
42 public PositionBasedTermVectorMapper():base(false, false)
46 public PositionBasedTermVectorMapper(bool ignoringOffsets):base(false, ignoringOffsets)
50 /// <summary> Never ignores positions. This mapper doesn't make much sense unless there are positions</summary>
53 public override bool IsIgnoringPositions()
58 /// <summary> Callback for the TermVectorReader. </summary>
59 /// <param name="term">
61 /// <param name="frequency">
63 /// <param name="offsets">
65 /// <param name="positions">
67 public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
69 for (int i = 0; i < positions.Length; i++)
71 System.Int32 posVal = (System.Int32) positions[i];
72 TVPositionInfo pos = (TVPositionInfo) currentPositions[posVal];
75 pos = new TVPositionInfo(positions[i], storeOffsets);
76 currentPositions[posVal] = pos;
78 pos.addTerm(term, offsets != null?offsets[i]:null);
82 /// <summary> Callback mechanism used by the TermVectorReader</summary>
83 /// <param name="field"> The field being read
85 /// <param name="numTerms">The number of terms in the vector
87 /// <param name="storeOffsets">Whether offsets are available
89 /// <param name="storePositions">Whether positions are available
91 public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions)
93 if (storePositions == false)
95 throw new System.SystemException("You must store positions in order to use this Mapper");
97 if (storeOffsets == true)
101 fieldToTerms = new System.Collections.Hashtable(numTerms);
102 this.storeOffsets = storeOffsets;
103 currentField = field;
104 currentPositions = new System.Collections.Hashtable();
105 fieldToTerms[currentField] = currentPositions;
108 /// <summary> Get the mapping between fields and terms, sorted by the comparator
111 /// <returns> A map between field names and a Map. The sub-Map key is the position as the integer, the value is {@link Mono.Lucene.Net.Index.PositionBasedTermVectorMapper.TVPositionInfo}.
113 public virtual System.Collections.IDictionary GetFieldToTerms()
118 /// <summary> Container for a term at a position</summary>
119 public class TVPositionInfo
121 /// <summary> </summary>
122 /// <returns> The position of the term
124 virtual public int Position
132 /// <summary> Note, there may be multiple terms at the same position</summary>
133 /// <returns> A List of Strings
135 virtual public System.Collections.IList Terms
143 /// <summary> Parallel list (to {@link #getTerms()}) of TermVectorOffsetInfo objects. There may be multiple entries since there may be multiple terms at a position</summary>
144 /// <returns> A List of TermVectorOffsetInfo objects, if offsets are store.
146 virtual public System.Collections.IList Offsets
154 private int position;
156 private System.Collections.IList terms;
157 //A list of TermVectorOffsetInfo
158 private System.Collections.IList offsets;
161 public TVPositionInfo(int position, bool storeOffsets)
163 this.position = position;
164 terms = new System.Collections.ArrayList();
167 offsets = new System.Collections.ArrayList();
171 internal virtual void addTerm(System.String term, TermVectorOffsetInfo info)