/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Lucene.Net.Index { /// For each Field, store a sorted collection of {@link TermVectorEntry}s ///

/// This is not thread-safe. ///

public class FieldSortedTermVectorMapper : TermVectorMapper { private System.Collections.IDictionary fieldToTerms = new System.Collections.Hashtable(); private System.Collections.Generic.SortedDictionary currentSet; private System.String currentField; private System.Collections.Generic.IComparer comparator; /// /// A Comparator for sorting {@link TermVectorEntry}s /// public FieldSortedTermVectorMapper(System.Collections.Generic.IComparer comparator) : this(false, false, comparator) { } public FieldSortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, System.Collections.Generic.IComparer comparator) : base(ignoringPositions, ignoringOffsets) { this.comparator = comparator; } public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions) { TermVectorEntry entry = new TermVectorEntry(currentField, term, frequency, offsets, positions); currentSet.Add(entry, entry); } public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions) { currentSet = new System.Collections.Generic.SortedDictionary(comparator); currentField = field; fieldToTerms[field] = currentSet; } /// Get the mapping between fields and terms, sorted by the comparator /// /// /// A map between field names and {@link java.util.SortedSet}s per field. SortedSet entries are {@link TermVectorEntry} /// public virtual System.Collections.IDictionary GetFieldToTerms() { return fieldToTerms; } public virtual System.Collections.Generic.IComparer GetComparator() { return comparator; } } }