Exemplo n.º 1
0
        private ObjectIntHashMap <string> CreateUnresolvedTokens(IntSet unresolvedIndexes, string[] names, int[] ids)
        {
            try
            {
                // First, we need to filter out all of the tokens that are already resolved, so we only create tokens for
                // indexes that are in the unresolvedIndexes set.
                // However, we also need to deal with duplicate token names. For any token index we decide needs to have a
                // token created, we will add a mapping from the token name, to the ids-index into which the token id will
                // be written. This is the 'createdTokens' map. It maps token names to indexes into the 'ids' array.
                // If we find that the 'created'Tokens' map already has an entry for a given name, then that name is a
                // duplicate, and we will need to "remap" it later, by reading the token id from the correct index in the
                // 'ids' array, and storing it at the indexes of the duplicates. This is what the 'remappingIndexes' map is
                // for. This is a map from 'a' to 'b', where both 'a' and 'b' are indexes into the 'ids' array, and where
                // the corresponding name for 'a' is a duplicate of the name for 'b', and where we have already decided
                // that we will create a token id for index 'b'. After the token ids have been created, we go through the
                // 'remappingIndexes' map, and for every '(a,b)' entry, we store the token id created for 'b' and 'ids'
                // index 'a'.
                ObjectIntHashMap <string> createdTokens     = new ObjectIntHashMap <string>();
                IntIntHashMap             remappingIndexes  = new IntIntHashMap();
                System.Func <int, bool>   tokenCreateFilter = index =>
                {
                    bool needsCreate = unresolvedIndexes.contains(index);
                    if (needsCreate)
                    {
                        // The name at this index is unresolved.
                        string name          = names[index];
                        int    creatingIndex = createdTokens.getIfAbsentPut(name, index);
                        if (creatingIndex != index)
                        {
                            // This entry has a duplicate name, so we need to remap this entry instead of creating a token
                            // for it.
                            remappingIndexes.put(index, creatingIndex);
                            needsCreate = false;
                        }
                    }
                    return(needsCreate);
                };

                // Create tokens for all the indexes that we don't filter out.
                _tokenCreator.createTokens(names, ids, tokenCreateFilter);

                // Remap duplicate tokens to the token id we created for the first instance of any duplicate token name.
                if (remappingIndexes.notEmpty())
                {
                    remappingIndexes.forEachKeyValue((index, creatingIndex) => ids[index] = ids[creatingIndex]);
                }

                return(createdTokens);
            }
            catch (ReadOnlyDbException e)
            {
                throw new TransactionFailureException(e.Message, e);
            }
            catch (Exception e)
            {
                throw new TransactionFailureException("Could not create tokens.", e);
            }
        }
 internal FulltextIndexTransactionStateVisitor(FulltextIndexDescriptor descriptor, MutableLongSet modifiedEntityIdsInThisTransaction, TransactionStateLuceneIndexWriter writer)
 {
     this._descriptor = descriptor;
     this._schema     = descriptor.Schema();
     this._modifiedEntityIdsInThisTransaction = modifiedEntityIdsInThisTransaction;
     this._writer        = writer;
     this._visitingNodes = _schema.entityType() == EntityType.NODE;
     _entityTokenIds     = _schema.EntityTokenIds;
     int[] propertyIds = _schema.PropertyIds;
     _propertyValues = new Value[propertyIds.Length];
     _propKeyToIndex = new IntIntHashMap();
     for (int i = 0; i < propertyIds.Length; i++)
     {
         _propKeyToIndex.put(propertyIds[i], i);
     }
 }