public void FromSortableString()
 {
     Assert.AreEqual(999, PackedSizeConverter.FromSortableString(PackedSizeConverter.ToSortableString(999)));
     Assert.AreEqual(999, PackedSizeConverter.FromSortableString(PackedSizeConverter.ToSortableString(999 * kb)) / kb);
     Assert.AreEqual(999, PackedSizeConverter.FromSortableString(PackedSizeConverter.ToSortableString(999 * mb)) / mb);
     Assert.AreEqual(1, PackedSizeConverter.FromSortableString(PackedSizeConverter.ToSortableString(1 * gb)) / gb);
 }
 public void ToSortableString_Bytes()
 {
     Assert.AreEqual("b000", PackedSizeConverter.ToSortableString(0));
     Assert.AreEqual("b3E7", PackedSizeConverter.ToSortableString(999));
     Assert.AreEqual("b3FF", PackedSizeConverter.ToSortableString(kb - 1));
     Assert.AreEqual("k001", PackedSizeConverter.ToSortableString(kb));
 }
示例#3
0
        void IndexDocument(IndexJobData data)
        {
            if (_args.Verbosity == 0 && data.Path[0] == '$')
            {
                Console.WriteLine("Revision " + data.RevisionFirst);
            }
            else
            {
                Console.WriteLine("Index {0}   {1}:{2}", data.Path, data.RevisionFirst, data.RevisionLast);
            }

            string idText = data.Path[0] == '$' ? data.Path : data.Path + "@" + data.RevisionFirst;
            Term   id     = _idTerm.CreateTerm(idText);

            _indexWriter.DeleteDocuments(id);

            if (_args.SingleRevision && data.RevisionLast != Revision.Head)
            {
                return;
            }

            Document doc = MakeDocument();

            _idField.SetValue(idText);
            _pathTokenStream.SetText(data.Path);
            _revFirstField.SetValue(data.RevisionFirst.ToString(RevisionFilter.RevFormat));
            _revLastField.SetValue(data.RevisionLast.ToString(RevisionFilter.RevFormat));
            _authorField.SetValue(data.Info.Author.ToLowerInvariant());
            SetTimestampField(data.Info.Timestamp);
            _messageTokenStream.SetText(_svn.GetLogMessage(data.RevisionFirst));

            if (!data.Info.IsDirectory)
            {
                _sizeField.SetValue(PackedSizeConverter.ToSortableString(data.Info.Size));
                doc.Add(_sizeField);
            }

            _contentTokenStream.SetText(data.Content);
            if (!_contentTokenStream.IsEmpty)
            {
                doc.Add(_contentField);
            }

            IndexProperties(doc, data.Properties);

            _indexWriter.AddDocument(doc);
        }
示例#4
0
        public string[] GetFragments(Query query, Hits hits)
        {
            var highlighter = CreateHighlighter(query);
            var result      = new string[hits.Length()];

            for (var i = 0; i < result.Length; i++)
            {
                var size = PackedSizeConverter.FromSortableString(hits.Doc(i).Get(FieldName.Size));
                var loc  = hits.Doc(i).Get(FieldName.Id).Split('@');
                var info = Svn.GetPathInfo(loc[0], Convert.ToInt32(loc[1]));
                if (info.IsDirectory)
                {
                    continue;
                }

                var text   = Svn.GetPathContent(loc[0], Convert.ToInt32(loc[1]), size);
                var tokens = new SimpleTokenStream(text);
                result[i] = GetFragments(highlighter, tokens, text);
            }
            return(result);
        }
 public void ToSortableString_MBytes()
 {
     Assert.AreEqual("m001", PackedSizeConverter.ToSortableString(mb));
     Assert.AreEqual("m3FF", PackedSizeConverter.ToSortableString(gb - 1));
     Assert.AreEqual("z001", PackedSizeConverter.ToSortableString(gb));
 }
 public void ToSortableString_KBytes()
 {
     Assert.AreEqual("k001", PackedSizeConverter.ToSortableString(kb));
     Assert.AreEqual("k3FF", PackedSizeConverter.ToSortableString(mb - 1));
     Assert.AreEqual("m001", PackedSizeConverter.ToSortableString(mb));
 }