예제 #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 Query Parse(
            ulong collectionId,
            HttpRequest request,
            ReadSession mappingSession)
        {
            var query = _httpQueryParser.Parse(collectionId, request);

            mappingSession.Map(query);
            return(query);
        }
예제 #3
0
        public Query Parse(
            ulong collectionId,
            HttpRequest request,
            ReadSession readSession,
            IStringModel tokenizer)
        {
            var query = _httpQueryParser.Parse(collectionId, tokenizer, request);

            readSession.Map(query);
            return(query);
        }
예제 #4
0
 public OptimizeSession(
     string collectionName,
     ulong collectionId,
     SessionFactory sessionFactory,
     IConfigurationProvider config,
     ConcurrentDictionary <long, NodeReader> indexReaders) : base(collectionName, collectionId, sessionFactory)
 {
     _config         = config;
     _readSession    = new ReadSession(collectionName, collectionId, sessionFactory, config, indexReaders);
     _postingsWriter = new RemotePostingsWriter(config, collectionName);
 }
예제 #5
0
        public ReadSession CreateReadSession(ulong collectionId)
        {
            var sess = new ReadSession(_dir, collectionId, this)
            {
                ValueStream      = _valueStream,
                KeyStream        = CreateReadStream(string.Format("{0}.key", collectionId)),
                DocStream        = CreateReadStream(string.Format("{0}.docs", collectionId)),
                ValueIndexStream = _valueIndexStream,
                KeyIndexStream   = CreateReadStream(string.Format("{0}.kix", collectionId)),
                DocIndexStream   = CreateReadStream(string.Format("{0}.dix", collectionId)),
                PostingsStream   = CreateReadStream(string.Format("{0}.pos", collectionId)),
                VectorStream     = CreateReadStream(string.Format("{0}.vec", collectionId)),
                Index            = GetIndex(collectionId)
            };

            return(sess);
        }
예제 #6
0
        private ReadResult Reduce(IDictionary <long, SortedList <long, byte> > query, ReadSession readSession, int skip, int take)
        {
            IDictionary <long, BOCHit> scored = new Dictionary <long, BOCHit>();

            foreach (var term in query)
            {
                var hit = Scan(term.Key, term.Value);

                BOCHit score;

                if (scored.TryGetValue(hit.PostingsOffsets.PostingsOffset, out score))
                {
                    scored[hit.Key].Score = score.Score + hit.Value.Score;
                }
                else
                {
                    scored.Add(hit.Key, hit.Value);
                }
            }

            var sortedHits = scored.Values.OrderByDescending(h => h.Score);
            var offsets    = sortedHits.Select(h => h.PostingsOffset).ToArray();
            var docIds     = _postingsReader.Read(skip, take, offsets);
            var window     = docIds.GroupBy(x => x).Select(x => (x.Key, x.Count()))
                             .OrderByDescending(x => x.Item2)
                             .Skip(skip)
                             .Take(take)
                             .Select(x => x.Key).ToList();
            var docs = readSession.ReadDocs(window);

            return(new ReadResult {
                Docs = docs, Total = docIds.Count
            });
        }
예제 #7
0
 public ReadResult Read(IDictionary <long, SortedList <long, byte> > query, ReadSession readSession, int skip, int take)
 {
     return(Reduce(query, readSession, skip, take));
 }