Пример #1
0
        public IDictionary <long, SortedList <long, byte> > Parse(
            string collectionName, HttpRequest request, ReadSession readSession, SessionFactory sessionFactory)
        {
            string[] fields;
            var      docs = new Dictionary <long, SortedList <long, byte> >();

            if (request.Query.ContainsKey("fields"))
            {
                fields = request.Query["fields"].ToArray();
            }
            else
            {
                fields = new[] { "title", "body" };
            }

            var phrase = request.Query["q"];

            foreach (var field in fields)
            {
                var keyId  = sessionFactory.GetKeyId(collectionName.ToHash(), field.ToLower().ToHash());
                var vector = BOWWriteSession.CreateDocumentVector(phrase, readSession.CreateIndexReader(keyId), _tokenizer);

                docs.Add(keyId, vector);
            }

            return(docs);
        }
Пример #2
0
        public async Task Optimize()
        {
            var time             = Stopwatch.StartNew();
            var optimizedColumns = new List <(long keyId, VectorNode column)>();

            Parallel.ForEach(Directory.GetFiles(SessionFactory.Dir, string.Format("{0}.*.ix", CollectionId)), ixFileName =>
            {
                var columnTime  = Stopwatch.StartNew();
                var keyId       = long.Parse(Path.GetFileNameWithoutExtension(ixFileName).Split('.')[1]);
                var indexReader = _readSession.CreateIndexReader(keyId);
                var optimized   = indexReader.ReadAllPages();
            });

            this.Log("rebuilding {0} took {1}", CollectionId, time.Elapsed);

            foreach (var col in optimizedColumns)
            {
                await SerializeColumn(col.keyId, col.column);
            }
        }