/*
* 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.Collections.Generic;
using Lucene.Net.Support;
namespace Lucene.Net.Index
{
/// For each Field, store a sorted collection of s
///
/// This is not thread-safe.
///
public class FieldSortedTermVectorMapper:TermVectorMapper
{
private readonly IDictionary> fieldToTerms = new HashMap>();
private SortedSet currentSet;
private System.String currentField;
private readonly IComparer comparator;
///
/// A Comparator for sorting s
///
public FieldSortedTermVectorMapper(IComparer comparator)
: this(false, false, comparator)
{
}
public FieldSortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, IComparer comparator)
: base(ignoringPositions, ignoringOffsets)
{
this.comparator = comparator;
}
public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
{
var entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
currentSet.Add(entry);
}
public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions)
{
currentSet = new SortedSet(comparator);
currentField = field;
fieldToTerms[field] = currentSet;
}
/// Get the mapping between fields and terms, sorted by the comparator
///
///
/// A map between field names and <see cref="System.Collections.Generic.SortedDictionary{Object,Object}" />s per field. SortedSet entries are <see cref="TermVectorEntry" />
public virtual IDictionary> FieldToTerms
{
get { return fieldToTerms; }
}
public virtual IComparer Comparator
{
get { return comparator; }
}
}
}