예제 #1
0
        public string[] Query(string query, string[] sortFields, int start, int pageSize, out int totalResults)
        {
            IndexSearcher searcher;

            using (GetSearcher(out searcher))
            {
                Query fileQuery;
                if (string.IsNullOrEmpty(query))
                {
                    Log.Debug("Issuing query on index for all files");
                    fileQuery = new MatchAllDocsQuery();
                }
                else
                {
                    Log.Debug("Issuing query on index for: {0}", query);
                    var queryParser = new SimpleFilesQueryParser(analyzer);
                    fileQuery = queryParser.Parse(query);
                }

                var topDocs = ExecuteQuery(searcher, sortFields, fileQuery, pageSize + start);

                var results = new List <string>();

                for (var i = start; i < pageSize + start && i < topDocs.TotalHits; i++)
                {
                    var document = searcher.Doc(topDocs.ScoreDocs[i].Doc);
                    results.Add(document.Get("__key"));
                }
                totalResults = topDocs.TotalHits;
                return(results.ToArray());
            }
        }
예제 #2
0
        public string[] Query(string query, string[] sortFields, int start, int pageSize, out int totalResults, out long durationInMs)
        {
            var           sp = Stopwatch.StartNew();
            IndexSearcher searcher;

            using (GetSearcher(out searcher))
            {
                Query fileQuery;
                if (string.IsNullOrEmpty(query))
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Issuing query on index for all files");
                    }

                    fileQuery = new MatchAllDocsQuery();
                }
                else
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug($"Issuing query on index for: {query}");
                    }

                    var queryParser = new SimpleFilesQueryParser(analyzer);
                    fileQuery = queryParser.Parse(query);
                }

                var topDocs = ExecuteQuery(searcher, sortFields, fileQuery, pageSize + start);

                var results = new List <string>();

                for (var i = start; i < pageSize + start && i < topDocs.TotalHits; i++)
                {
                    var document = searcher.Doc(topDocs.ScoreDocs[i].Doc);
                    results.Add(document.Get("__key"));
                }

                totalResults = topDocs.TotalHits;
                durationInMs = sp.ElapsedMilliseconds;
                return(results.ToArray());
            }
        }
예제 #3
0
        public string[] Query(string query, string[] sortFields, int start, int pageSize, out int totalResults)
        {
            IndexSearcher searcher;
            using (GetSearcher(out searcher))
            {
                Query fileQuery;
                if (string.IsNullOrEmpty(query))
                {
                    Log.Debug("Issuing query on index for all files");
                    fileQuery = new MatchAllDocsQuery();
                }
                else
                {
                    Log.Debug("Issuing query on index for: {0}", query);
                    var queryParser = new SimpleFilesQueryParser(analyzer);
                    fileQuery = queryParser.Parse(query);
                }

                var topDocs = ExecuteQuery(searcher, sortFields, fileQuery, pageSize + start);

                var results = new List<string>();

                for (var i = start; i < pageSize + start && i < topDocs.TotalHits; i++)
                {
                    var document = searcher.Doc(topDocs.ScoreDocs[i].Doc);
                    results.Add(document.Get("__key"));
                }
                totalResults = topDocs.TotalHits;
                return results.ToArray();
            }
        }