Beispiel #1
0
        private void BuildInMemoryIndex(ulong docId, long keyId, VectorNode index, IEnumerable <string> tokens)
        {
            var count = 0;

            using (var vectorStream = SessionFactory.CreateAppendStream(
                       Path.Combine(SessionFactory.Dir, string.Format("{0}.{1}.vec", CollectionId.ToHash(), keyId))))
            {
                foreach (var token in tokens)
                {
                    index.Add(new VectorNode(token, docId), vectorStream);
                    count++;
                }
            }
        }
Beispiel #2
0
        public void Publish(ulong collectionId, long keyId, VectorNode index)
        {
            lock (_sync)
            {
                var timer = new Stopwatch();
                timer.Start();

                VectorNode clone = null;

                var colIx = GetCollectionIndex(collectionId);

                if (colIx == null)
                {
                    _index.Add(collectionId, keyId, index);
                }
                else
                {
                    if (colIx.ContainsKey(keyId))
                    {
                        clone = colIx[keyId].Clone();
                    }
                    else
                    {
                        colIx[keyId] = index;
                    }
                }

                if (clone != null)
                {
                    using (var vectorStream = CreateAppendStream(
                               Path.Combine(Dir, string.Format("{0}.{1}.vec", collectionId, keyId))))
                    {
                        foreach (var node in index.Right.All())
                        {
                            clone.Add(node, vectorStream);
                        }
                    }

                    _index.Add(collectionId, keyId, clone);
                }

                _log.Log(string.Format("published {0}.{1} in {2}", collectionId, keyId, timer.Elapsed));
            }
        }