//--- Constructors ---
        public SearchInstanceData(string indexPath, Analyzer analyzer, UpdateDelayQueue queue, TimeSpan commitInterval, TaskTimerFactory taskTimerFactory)
        {
            _analyzer  = analyzer;
            _directory = FSDirectory.GetDirectory(indexPath);

            // Note (arnec): Needed with SimpleFSLock, since a hard shutdown will have left the lock dangling
            IndexWriter.Unlock(_directory);
            try {
                _writer = new IndexWriter(_directory, _analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            } catch (CorruptIndexException e) {
                _log.WarnFormat("The Search index at {0} is corrupt. You must repair or delete it before restarting the service. If you delete it, you must rebuild your index after service restart.", indexPath);
                if (e.Message.StartsWith("Unknown format version"))
                {
                    _log.Warn("The index is considered corrupt because it's an unknown version. Did you accidentally downgrade your install?");
                }
                throw;
            }
            _reader           = IndexReader.Open(_directory);
            _searcher         = new IndexSearcher(_reader);
            _queue            = queue;
            _commitInterval   = commitInterval;
            _taskTimerFactory = taskTimerFactory;
            if (_commitInterval != TimeSpan.Zero)
            {
                _commitTimer = _taskTimerFactory.New(_commitInterval, Commit, null, TaskEnv.None);
            }
        }
        //--- Constructors ---
        public SearchInstanceData(string indexPath, Analyzer analyzer, UpdateDelayQueue queue) {
            _analyzer = analyzer;
            _directory = FSDirectory.GetDirectory(indexPath);

            // Note (arnec): Needed with 2.4.0 SimpleFSLock, since a hard shutdown will have left the lock dangling
            IndexWriter.Unlock(_directory);
            try {
                _writer = new IndexWriter(_directory, _analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            } catch(CorruptIndexException e) {
                _log.WarnFormat("The Search index at {0} is corrupt. You must repair or delete it before restarting the service. If you delete it, you must rebuild your index after service restart.", indexPath);
                if(e.Message.StartsWith("Unknown format version")) {
                    _log.Warn("The index is considered corrupt because it's an unknown version. Did you accidentally downgrade your install?");
                }
                throw;
            }
            _reader = IndexReader.Open(_directory);
            _searcher = new IndexSearcher(_reader);
            _queue = queue;
        }
示例#3
0
 public void Setup() {
     _peekQueue = new TransactionalQueue<XDoc>(new SingleFileQueueStream(new MemoryStream()), new XDocQueueItemSerializer());
     _dispatcher = new MockUpdateRecordDispatcher();
     _queue = new UpdateDelayQueue(TimeSpan.FromSeconds(3), _dispatcher, _peekQueue);
 }
示例#4
0
 private SearchInstanceData GetInstance(string wikiid) {
     SearchInstanceData instance;
     lock(_instances) {
         var entry = _instances[wikiid];
         if(entry == null) {
             var indexPath = string.Format(_indexPath, wikiid);
             var queuePath = string.Format(_queuePathBase, wikiid);
             var persistentQueue = new TransactionalQueue<XDoc>(new MultiFileQueueStream(queuePath), new XDocQueueItemSerializer());
             var queue = new UpdateDelayQueue(_indexAccumulationTime, new UpdateRecordDispatcher(OnQueueExpire, _indexerParallelism, _indexerMaxRetry, _indexerRetrySleep), persistentQueue);
             instance = new SearchInstanceData(indexPath, _defaultAnalyzer, queue, _instanceCommitInterval, TimerFactory);
             _instances.Set(wikiid, instance, _instanceTtl);
             _log.DebugFormat("created instance '{0}'", wikiid);
         } else {
             instance = entry.Value;
         }
     }
     return instance;
 }