1 package org.apache.lucene.index;
6 * Copyright 2007 The Apache Software Foundation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * For each Field, store a sorted collection of {@link TermVectorEntry}s
24 * This is not thread-safe.
26 public class FieldSortedTermVectorMapper extends TermVectorMapper{
27 private Map<String,SortedSet<TermVectorEntry>> fieldToTerms = new HashMap<String,SortedSet<TermVectorEntry>>();
28 private SortedSet<TermVectorEntry> currentSet;
29 private String currentField;
30 private Comparator<TermVectorEntry> comparator;
34 * @param comparator A Comparator for sorting {@link TermVectorEntry}s
36 public FieldSortedTermVectorMapper(Comparator<TermVectorEntry> comparator) {
37 this(false, false, comparator);
41 public FieldSortedTermVectorMapper(boolean ignoringPositions, boolean ignoringOffsets, Comparator<TermVectorEntry> comparator) {
42 super(ignoringPositions, ignoringOffsets);
43 this.comparator = comparator;
47 public void map(String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions) {
48 TermVectorEntry entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
49 currentSet.add(entry);
53 public void setExpectations(String field, int numTerms, boolean storeOffsets, boolean storePositions) {
54 currentSet = new TreeSet<TermVectorEntry>(comparator);
56 fieldToTerms.put(field, currentSet);
60 * Get the mapping between fields and terms, sorted by the comparator
62 * @return A map between field names and {@link java.util.SortedSet}s per field. SortedSet entries are {@link TermVectorEntry}
64 public Map<String,SortedSet<TermVectorEntry>> getFieldToTerms() {
69 public Comparator<TermVectorEntry> getComparator() {