Example #1
0
        private IList <Hit> ClosestMatchOnDisk(
            Vector vector, IStringModel model)
        {
            var time  = Stopwatch.StartNew();
            var pages = _sessionFactory.ReadPageInfo(_ixpFileName);
            var hits  = new List <Hit>();

            using (var indexStream = _sessionFactory.CreateReadStream(_ixFileName))
                using (var vectorStream = _sessionFactory.CreateReadStream(_vecFileName))
                {
                    foreach (var page in pages)
                    {
                        indexStream.Seek(page.offset, SeekOrigin.Begin);

                        var hit = ClosestMatchInPage(
                            vector,
                            indexStream,
                            vectorStream,
                            model);

                        hits.Add(hit);
                    }
                }

            this.Log($"scan took {time.Elapsed}");

            return(hits);
        }
Example #2
0
        public ReadSession(string collectionName,
                           ulong collectionId,
                           SessionFactory sessionFactory,
                           IConfigurationProvider config,
                           IStringModel tokenizer)
            : base(collectionName, collectionId, sessionFactory)
        {
            ValueStream      = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.val", CollectionId)));
            KeyStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.key", CollectionId)));
            DocStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.docs", CollectionId)));
            ValueIndexStream = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.vix", CollectionId)));
            KeyIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.kix", CollectionId)));
            DocIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.dix", CollectionId)));

            _docIx     = new DocIndexReader(DocIndexStream);
            _docs      = new DocMapReader(DocStream);
            _keyIx     = new ValueIndexReader(KeyIndexStream);
            _valIx     = new ValueIndexReader(ValueIndexStream);
            _keyReader = new ValueReader(KeyStream);
            _valReader = new ValueReader(ValueStream);
            _config    = config;
            _tokenizer = tokenizer;

            var posFileName = Path.Combine(SessionFactory.Dir, $"{CollectionId}.pos");

            _postingsStream = SessionFactory.CreateReadStream(posFileName);
        }
Example #3
0
        public DocumentStreamSession(string collectionName, ulong collectionId, SessionFactory sessionFactory)
            : base(collectionName, collectionId, sessionFactory)
        {
            ValueStream      = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.val", CollectionId)));
            KeyStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.key", CollectionId)));
            DocStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.docs", CollectionId)));
            ValueIndexStream = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.vix", CollectionId)));
            KeyIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.kix", CollectionId)));
            DocIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.dix", CollectionId)));

            _docIx     = new DocIndexReader(DocIndexStream);
            _docs      = new DocMapReader(DocStream);
            _keyIx     = new ValueIndexReader(KeyIndexStream);
            _valIx     = new ValueIndexReader(ValueIndexStream);
            _keyReader = new ValueReader(KeyStream);
            _valReader = new ValueReader(ValueStream);
        }
Example #4
0
        public ReadSession(string collectionName,
                           ulong collectionId,
                           SessionFactory sessionFactory,
                           IConfigurationProvider config,
                           ConcurrentDictionary <long, NodeReader> indexReaders)
            : base(collectionName, collectionId, sessionFactory)
        {
            ValueStream      = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.val", CollectionId)));
            KeyStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.key", CollectionId)));
            DocStream        = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.docs", CollectionId)));
            ValueIndexStream = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.vix", CollectionId)));
            KeyIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.kix", CollectionId)));
            DocIndexStream   = sessionFactory.CreateReadStream(Path.Combine(sessionFactory.Dir, string.Format("{0}.dix", CollectionId)));

            _docIx          = new DocIndexReader(DocIndexStream);
            _docs           = new DocMapReader(DocStream);
            _keyIx          = new ValueIndexReader(KeyIndexStream);
            _valIx          = new ValueIndexReader(ValueIndexStream);
            _keyReader      = new ValueReader(KeyStream);
            _valReader      = new ValueReader(ValueStream);
            _postingsReader = new RemotePostingsReader(config, collectionName);
            _indexReaders   = indexReaders;
            _config         = config;
        }