コード例 #1
0
 internal IndexProperties(IndexReader reader)
 {
     Revision              = IndexProperty.GetRevision(reader);
     RepositoryName        = IndexProperty.GetRepositoryName(reader);
     RepositoryLocalUri    = IndexProperty.GetRepositoryLocalUri(reader);
     RepositoryExternalUri = IndexProperty.GetRepositoryExternalUri(reader);
     RepositoryCredentials = IndexProperty.GetRepositoryCredentials(reader);
     SingleRevision        = IndexProperty.GetSingleRevision(reader);
     TotalCount            = reader.MaxDoc();
 }
コード例 #2
0
        public void Run()
        {
            Console.WriteLine("Begin indexing ...");
            DateTime start         = DateTime.UtcNow;
            int      startRevision = 1;
            int      stopRevision  = Math.Min(_args.MaxRevision, _svn.GetYoungestRevision());
            bool     optimize;

            Thread indexThread = new Thread(ProcessIndexQueue);

            indexThread.Name         = "IndexThread";
            indexThread.IsBackground = true;
            indexThread.Start();

            // setup message filter for index writer
            _indexWriterMessageFilter = new FilteredTextWriter(Console.Out,
                                                               // only allow messages starting with "maxFieldLength"
                                                               // example message: "maxFieldLength 500000 reached for field content, ignoring following tokens"
                                                               line => line.ToString().StartsWith("maxFieldLength"));
            _indexWriterMessageFilter.DefaultLineLength = 256;

            using (_indexWriterMessageFilter)
            {
                if (Command.Create == _args.Command)
                {
                    _indexWriter = CreateIndexWriter(true);
                    IndexProperty.SetSingleRevision(_indexWriter, _args.SingleRevision);
                    QueueAnalyzeJob(new PathChange {
                        Path = "/", Revision = 1, Change = Change.Add
                    });                                                                              // add root directory manually
                    optimize = true;
                }
                else // Command.Update
                {
                    IndexReader reader = IndexReader.Open(_indexDirectory); // important: create reader before creating indexWriter!
                    _highestRevision.Reader = reader;
                    startRevision           = IndexProperty.GetRevision(reader) + 1;
                    _args.SingleRevision    = IndexProperty.GetSingleRevision(reader);
                    if (_args.SingleRevision)
                    {
                        Console.WriteLine("SingleRevision index");
                    }
                    _indexWriter = CreateIndexWriter(false);
                    optimize     = stopRevision % _args.Optimize == 0 || stopRevision - startRevision > _args.Optimize;
                }
                IndexProperty.SetRepositoryLocalUri(_indexWriter, _args.RepositoryLocalUri);
                IndexProperty.SetRepositoryExternalUri(_indexWriter, _args.RepositoryExternalUri);
                IndexProperty.SetRepositoryName(_indexWriter, _args.RepositoryName);
                IndexProperty.SetRepositoryCredentials(_indexWriter, _args.Credentials);

                while (startRevision <= stopRevision)
                {
                    IndexRevisionRange(startRevision, Math.Min(startRevision + _args.CommitInterval - 1, stopRevision));
                    startRevision += _args.CommitInterval;

                    if (startRevision <= stopRevision)
                    {
                        if (_highestRevision.Reader != null)
                        {
                            _highestRevision.Reader.Close();
                        }
                        CommitIndex();
                        _highestRevision.Reader = IndexReader.Open(_indexDirectory);
                        _indexWriter            = CreateIndexWriter(false);
                    }
                }
                _stopIndexThread.Set();
                if (_highestRevision.Reader != null)
                {
                    _highestRevision.Reader.Close();
                }
                _highestRevision.Reader = null;
                if (optimize)
                {
                    Console.WriteLine("Optimizing index ...");
                    _indexWriter.Optimize();
                }
                CommitIndex();
            }
            _indexWriterMessageFilter = null;

            TimeSpan time = DateTime.UtcNow - start;

            Console.WriteLine("Finished in {0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);
        }