public IEnumerable <LogEntry> Filter(string queryString, ViewFilter view, int count, Direction direction, ulong?referenceId, out int totalCount)
            {
                var context = new IncermentalSearchContext(count, direction, referenceId);

                var parser = new CustomQueryParser(LuceneNet.Util.Version.LUCENE_30, MessageFieldName, analyzer);
                var sortBy = new Sort(new SortField(IdFieldName, SortField.LONG, direction == Direction.Backward));

                while (true)
                {
                    var combinedQueryString = Searcher.CombineQuery(queryString, view, context.Range);
                    if (combinedQueryString.Length == 0)
                    {
                        totalCount = 0;
                        return(new LogEntry[0]);
                    }

                    var query = parser.Parse(combinedQueryString);

                    lock (searcherLock)
                    {
                        var searchResults = searcher.Search(query, null, count, sortBy);

                        totalCount = searchResults.TotalHits;
                        var result = searchResults.ScoreDocs.Take(count).Select(d => searcher.Doc(d.Doc)).Select(x => converter.ToLogEntry(x));

                        context.UpdateResult(result);
                        if (context.IsFinished)
                        {
                            return((direction == Direction.Backward) ? context.Result.Reverse() : context.Result);
                        }

                        context.UpdateRange();
                    }
                }
            }
            private ulong?FindFirstId(string queryString, ViewFilter view, Direction direction, ulong?referenceId, out int totalCount)
            {
                if (direction == Direction.Backward)
                {
                    if (referenceId.HasValue && referenceId.Value > 0)
                    {
                        referenceId--;
                    }
                }
                else
                {
                    if (referenceId.HasValue && referenceId.Value < ulong.MaxValue)
                    {
                        referenceId++;
                    }
                }

                var context = new IncermentalSearchContext(1, direction, referenceId);

                while (true)
                {
                    var combinedQueryString = Searcher.CombineQuery(queryString, view, context.Range);
                    if (combinedQueryString.Length == 0)
                    {
                        totalCount = 0;
                        return(null);
                    }

                    var parser = new CustomQueryParser(LuceneNet.Util.Version.LUCENE_30, MessageFieldName, analyzer);
                    var query  = parser.Parse(combinedQueryString);
                    var sortBy = new Sort(new SortField(IdFieldName, SortField.LONG, direction == Direction.Backward));

                    lock (searcherLock)
                    {
                        var searchResults = searcher.Search(query, null, 1, sortBy);
                        var firstResult   = searchResults.ScoreDocs.FirstOrDefault();

                        totalCount = searchResults.TotalHits;
                        if (firstResult != null)
                        {
                            return(converter.ToLogEntry(searcher.Doc(firstResult.Doc)).Id);
                        }
                        if (context.IsFinished)
                        {
                            return(null);
                        }

                        context.UpdateRange();
                    }
                }
            }