IndexBuilder(final DictionaryBuilder dictionaryBuilder, final String shortName, final String longName, final Language language, final String normalizerRules, final Set<String> stoplist, final boolean swapPairEntries) {
this.dictionaryBuilder = dictionaryBuilder;
index = new Index(dictionaryBuilder.dictionary, shortName, longName, language, normalizerRules, swapPairEntries, stoplist);
- tokenToData = new TreeMap<String, TokenData>(new NormalizeComparator(index.normalizer(), language.getCollator()));
+ tokenToData = new TreeMap<String, TokenData>(index.getSortComparator());
this.stoplist = stoplist;
}
public void build() {
- final Set<IndexedEntry> tokenEntryDatas = new HashSet<IndexedEntry>();
+ final Set<IndexedEntry> tokenIndexedEntries = new HashSet<IndexedEntry>();
final List<RowBase> rows = index.rows;
index.mainTokenCount = 0;
for (final TokenData tokenData : tokenToData.values()) {
- tokenEntryDatas.clear();
+ tokenIndexedEntries.clear();
final int indexIndex = index.sortedIndexEntries.size();
final int startRow = rows.size();
- final TokenRow tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
- rows.add(tokenRow);
- if (tokenRow.hasMainEntry) {
- index.mainTokenCount++;
+ TokenRow tokenRow = null;
+ if (!tokenData.htmlEntries.isEmpty()) {
+ tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+ rows.add(tokenRow);
}
-// System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
- int numRows = 0;
+
+// System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
+
+ int numRows = 0; // off by one--doesn't count the token row!
// System.out.println("TOKEN: " + tokenData.token);
- for (final Map.Entry<EntryTypeName, List<IndexedEntry>> typeToEntry : tokenData.typeToEntries.entrySet()) {
- for (final IndexedEntry entryData : typeToEntry.getValue()) {
- if (entryData.index() == -1) {
- entryData.addToDictionary(dictionaryBuilder.dictionary);
- assert entryData.index() >= 0;
+ for (final Map.Entry<EntryTypeName, List<IndexedEntry>> typeToIndexedEntries : tokenData.typeToEntries.entrySet()) {
+ for (final IndexedEntry indexedEntry : typeToIndexedEntries.getValue()) {
+ if (!indexedEntry.isValid) {
+ continue;
+ }
+
+ if (tokenRow == null) {
+ tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+ rows.add(tokenRow);
+ }
+
+ if (indexedEntry.entry.index() == -1) {
+ indexedEntry.entry.addToDictionary(dictionaryBuilder.dictionary);
+ assert indexedEntry.entry.index() >= 0;
}
- if (tokenEntryDatas.add(entryData)) {
- rows.add(new PairEntry.Row(entryData.index(), rows.size(), index));
- ++entryData.entry.entrySource.numEntries;
+ if (tokenIndexedEntries.add(indexedEntry)) {
+ rows.add(indexedEntry.entry.CreateRow(rows.size(), index));
+ ++indexedEntry.entry.entrySource.numEntries;
++numRows;
// System.out.print(" " + typeToEntry.getKey() + ": ");
}
}
}
- index.sortedIndexEntries.add(new Index.IndexEntry(tokenData.token, index
- .normalizer().transliterate(tokenData.token), startRow, numRows));
+
+ if (tokenRow != null) {
+ if (tokenRow.hasMainEntry) {
+ index.mainTokenCount++;
+ }
+
+ final Index.IndexEntry indexEntry = new Index.IndexEntry(index, tokenData.token, index
+ .normalizer().transliterate(tokenData.token), startRow, numRows);
+ indexEntry.htmlEntries.addAll(tokenData.htmlEntries);
+ index.sortedIndexEntries.add(indexEntry);
+ }
}
final List<IndexEntry> entriesSortedByNumRows = new ArrayList<IndexEntry>(index.sortedIndexEntries);
}
}
- static class TokenData {
+ public static class TokenData {
final String token;
final Map<EntryTypeName, List<IndexedEntry>> typeToEntries = new EnumMap<EntryTypeName, List<IndexedEntry>>(EntryTypeName.class);
boolean hasMainEntry = false;
+ public List<HtmlEntry> htmlEntries = new ArrayList<HtmlEntry>();
+
TokenData(final String token) {
assert token.equals(token.trim());
assert token.length() > 0;
}
}
- private TokenData getOrCreateTokenData(final String token) {
+ public TokenData getOrCreateTokenData(final String token) {
TokenData tokenData = tokenToData.get(token);
if (tokenData == null) {
tokenData = new TokenData(token);