/** * This helper method handles the case when a tuple is being removed from the table, before the * row has actually been removed from the table. All indexes on the table are updated to remove * the row. * * @param tblFileInfo details of the table being updated * @param ptup the tuple about to be removed from the table */ private void removeRowFromIndexes(TableInfo tblFileInfo, PageTuple ptup) { logger.debug( "Removing tuple " + ptup + " from indexes for table " + tblFileInfo.getTableName()); // Iterate over the indexes in the table. TableSchema schema = tblFileInfo.getSchema(); for (ColumnRefs indexDef : schema.getIndexes().values()) { TupleLiteral idxTup = IndexUtils.makeSearchKeyValue(indexDef, ptup, /* findExactTuple */ true); logger.debug("Removing tuple " + idxTup + " from index " + indexDef.getIndexName()); try { IndexInfo indexInfo = indexManager.openIndex(tblFileInfo, indexDef.getIndexName()); TupleFile tupleFile = indexInfo.getTupleFile(); PageTuple idxPageTup = IndexUtils.findTupleInIndex(idxTup, tupleFile); if (idxPageTup == null) { throw new IllegalStateException( "Can't find tuple in " + "index corresponding to table's tuple."); } tupleFile.deleteTuple(idxPageTup); } catch (IOException e) { throw new EventDispatchException( "Couldn't update index " + indexDef.getIndexName() + " for table " + tblFileInfo.getTableName()); } } }
/** gets map for all languages */ public Map<String, String> getCaptionToQueryMap(Collection<Document> docs) { // identify all the langs in the docs, and the corresponding lexicons Set<String> languages = IndexUtils.allLanguagesInDocs(docs); Set<Lexicon1Lang> lexicons = new LinkedHashSet<Lexicon1Lang>(); for (String lang : languages) { Lexicon1Lang lex = languageToLexicon.get(lang); if (lex != null) lexicons.add(lex); // this lexicon doesn't know about this language else log.warn("Warning: no support for " + lang + " in lexicon " + name); } Map<String, String> result = new LinkedHashMap<String, String>(); // aggregate results for each lang into result for (Lexicon1Lang lex : lexicons) { Map<String, String> resultsForThisLang = lex.captionToExpandedQuery; for (String caption : resultsForThisLang.keySet()) { String queryThisLang = resultsForThisLang.get(caption); String query = result.get(caption); // if caption doesn't exist already, create a new entry, or else add to the existing set of // docs that match this caption if (query == null) result.put(caption, queryThisLang); else result.put(caption, query + "|" + queryThisLang); } } return result; }
// identify all the langs in the docs, and the corresponding lexicons private Collection<Lexicon1Lang> getRelevantLexicon1Langs(Collection<Document> docs) { if (docs == null) return languageToLexicon.values(); // just return all lexicons Set<String> languages = IndexUtils.allLanguagesInDocs(docs); Set<Lexicon1Lang> lexicons = new LinkedHashSet<Lexicon1Lang>(); for (String lang : languages) { Lexicon1Lang lex = languageToLexicon.get(lang); if (lex != null) lexicons.add(lex); // this lexicon doesn't know about this language else log.warn("Warning: no support for " + lang + " in lexicon " + name); } return lexicons; }
/** * This helper method handles the case when a tuple is being added to the table, after the row has * already been added to the table. All indexes on the table are updated to include the new row. * * @param tblFileInfo details of the table being updated * @param ptup the new tuple that was inserted into the table */ private void addRowToIndexes(TableInfo tblFileInfo, PageTuple ptup) { logger.debug("Adding tuple " + ptup + " to indexes for table " + tblFileInfo.getTableName()); // Iterate over the indexes in the table. TableSchema schema = tblFileInfo.getSchema(); for (ColumnRefs indexDef : schema.getIndexes().values()) { TupleLiteral idxTup; try { IndexInfo indexInfo = indexManager.openIndex(tblFileInfo, indexDef.getIndexName()); TupleFile tupleFile = indexInfo.getTupleFile(); TableConstraintType constraintType = indexDef.getConstraintType(); if (constraintType != null && constraintType.isUnique()) { // Check if the index already has a tuple with this value. idxTup = IndexUtils.makeSearchKeyValue(indexDef, ptup, /* findExactTuple */ false); if (IndexUtils.findTupleInIndex(idxTup, tupleFile) != null) { // Adding this row would violate the unique index. throw new IllegalStateException( "Unique index " + "already contains a tuple with this value."); } } idxTup = IndexUtils.makeSearchKeyValue(indexDef, ptup, /* findExactTuple */ true); logger.debug("Adding tuple " + idxTup + " to index " + indexDef.getIndexName()); tupleFile.addTuple(idxTup); } catch (IOException e) { throw new EventDispatchException( "Couldn't update index " + indexDef.getIndexName() + " for table " + tblFileInfo.getTableName(), e); } } }
/** * Creates a finder for document of type <code>T</code> for a specific indexName * * @param type */ public Finder(Class<T> type, String indexName) { this.type = type; T t = IndexUtils.getInstanceIndex(type); this.queryPath = t.getIndexPath(indexName); }