Пример #1
0
        public static LuceneAction ToModel(this indexingQueue item)
        {
            var action = new LuceneAction
            {
                type          = (LuceneIndexType)item.type,
                subdomainName = item.MASTERsubdomain.name,
                deleteOnly    = item.deleteOnly,
                itemKey       = item.itemKey
            };

            switch (action.type)
            {
            case LuceneIndexType.CONTACTS:
                action.data = BaseQueueItem.Deserialize <ContactItem>(item.serializedItem);
                break;

            case LuceneIndexType.PRODUCTS:
                action.data = BaseQueueItem.Deserialize <ProductItem>(item.serializedItem);
                break;

            case LuceneIndexType.TRANSACTION:
                action.data = BaseQueueItem.Deserialize <TransactionItem>(item.serializedItem);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(action);
        }
Пример #2
0
        public bool ModifyIndex(LuceneAction action)
        {
            if (writerInUse)
            {
                return(false);
            }

            writer = CreateWriter(action.type, action.subdomainName);
            if (writer == null)
            {
                Syslog.Write("LUCENE: Failed to obtained Lucene IndexWriter, action:{0}, subdomain:{1}", action.type, action.subdomainName);
                return(false);
            }
            if (action.itemKey == 0)
            {
                Syslog.Write("LUCENE: indexKey is 0, action:{0}, subdomain:{1}", action.type, action.subdomainName);
                CloseWriter();
                return(false);
            }
            var termID = new Term("id", action.itemKey.ToString());

            if (action.deleteOnly)
            {
                writer.DeleteDocuments(termID);
            }
            else
            {
                writer.DeleteDocuments(termID);
                Document doc;
                switch (action.type)
                {
                case LuceneIndexType.CONTACTS:
                    doc = IndexContact((ContactItem)action.data);
                    break;

                case LuceneIndexType.TRANSACTION:
                    doc = IndexTransaction((TransactionItem)action.data);
                    break;

                case LuceneIndexType.PRODUCTS:
                    doc = IndexProduct((ProductItem)action.data);
                    break;

                default:
                    Syslog.Write("LUCENE: Unknown action:{0}, subdomain:{1}", action.type, action.subdomainName);
                    CloseWriter();
                    return(false);
                }

                writer.AddDocument(doc);
            }

            writer.Optimize();
            CloseWriter();

            return(true);
        }
Пример #3
0
        private LuceneAction GetLuceneAction(LuceneIndexType type, dynamic data, bool deleteOnly, long itemKey)
        {
            var action = new LuceneAction
            {
                type          = type,
                subdomainName = subdomain.name,
                deleteOnly    = deleteOnly,
                itemKey       = itemKey
            };

            if (data == null)
            {
                action.data = BaseQueueItem.Serialize(new BaseQueueItem(itemKey.ToString(), type));
            }
            else
            {
                switch (type)
                {
                case LuceneIndexType.CONTACTS:
                    action.data = new ContactItem(data);
                    break;

                case LuceneIndexType.PRODUCTS:
                    action.data = new ProductItem(data);
                    break;

                case LuceneIndexType.TRANSACTION:
                    action.data = new TransactionItem(data);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("type");
                }
            }

            return(action);
        }
Пример #4
0
        private void AddActionToQueue(LuceneAction action)
        {
            XElement serialized;

            switch (action.type)
            {
            case LuceneIndexType.CONTACTS:
                serialized = BaseQueueItem.Serialize <ContactItem>(action.data);
                break;

            case LuceneIndexType.PRODUCTS:
                serialized = BaseQueueItem.Serialize <ProductItem>(action.data);
                break;

            case LuceneIndexType.TRANSACTION:
                serialized = BaseQueueItem.Serialize <TransactionItem>(action.data);
                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }
            repository.AddActionToIndexingQueue(action.type, serialized, long.Parse(subdomain.id), action.deleteOnly, action.itemKey);
            repository.Save();
        }