Ejemplo n.º 1
0
        internal override void Add(TxDataHolder holder, EntityId entityId, string key, object value)
        {
            try
            {
                EnsureLuceneDataInstantiated();
                long     id       = entityId.Id();
                Document document = FindDocument(id);
                bool     add      = false;
                if (document == null)
                {
                    document = IndexType.NewDocument(entityId);
                    document.add(new StoredField(TX_STATE_KEY, _txStateValue));
                    _cachedDocuments.put(id, document);
                    add = true;
                }

                if (string.ReferenceEquals(key, null) && value == null)
                {
                    // Set a special "always hit" flag
                    document.add(new StringField(ORPHANS_KEY, ORPHANS_VALUE, Store.NO));
                    AddOrphan(null);
                }
                else if (value == null)
                {
                    // Set a special "always hit" flag
                    document.add(new StringField(ORPHANS_KEY, key, Store.NO));
                    AddOrphan(key);
                }
                else
                {
                    Index.type.addToDocument(document, key, value);
                }

                if (add)
                {
                    _writer.addDocument(document);
                }
                else
                {
                    _writer.updateDocument(Index.type.idTerm(id), document);
                }
                InvalidateSearcher();
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
Ejemplo n.º 2
0
 public override void Add(long id, IDictionary <string, object> properties)
 {
     try
     {
         Document document = IndexType.NewDocument(EntityId(id));
         foreach (KeyValuePair <string, object> entry in properties.SetOfKeyValuePairs())
         {
             string key   = entry.Key;
             object value = entry.Value;
             AddSingleProperty(id, document, key, value);
         }
         _writer.addDocument(document);
         if (++_updateCount == _commitBatchSize)
         {
             _writer.commit();
             _updateCount = 0;
         }
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }