Пример #1
0
        public static Query MakeQuery(string q, NuGetSearcherManager searcherManager)
        {
            Query query        = LuceneQueryCreator.Parse(q, false);
            Query boostedQuery = new RankingScoreQuery(query, searcherManager.GetRankings());

            return(boostedQuery);
        }
        private static string AddExplanation(IndexSearcher searcher, string data, Query query, ScoreDoc scoreDoc, IDictionary <string, int> rankings)
        {
            Explanation explanation = searcher.Explain(query, scoreDoc.Doc);

            JObject diagnostics = new JObject();

            int    rankVal;
            string id = searcher.Doc(scoreDoc.Doc).Get("Id");

            if (rankings.TryGetValue(id, out rankVal))
            {
                float rankingScore = RankingScoreQuery.GetRankingScore(rankings, id);
                diagnostics.Add("Rank", rankVal);
                diagnostics.Add("RankScore", rankingScore);
                diagnostics.Add("LuceneScore", scoreDoc.Score / rankingScore);
            }
            diagnostics.Add("Score", scoreDoc.Score.ToString());
            diagnostics.Add("Explanation", explanation.ToString());

            diagnostics.Add("IdTerms", GetTerms(searcher, scoreDoc.Doc, "Id"));
            diagnostics.Add("TokenizedIdTerms", GetTerms(searcher, scoreDoc.Doc, "TokenizedId"));
            diagnostics.Add("ShingledIdTerms", GetTerms(searcher, scoreDoc.Doc, "ShingledId"));
            diagnostics.Add("VersionTerms", GetTerms(searcher, scoreDoc.Doc, "Version"));
            diagnostics.Add("TitleTerms", GetTerms(searcher, scoreDoc.Doc, "Title"));
            diagnostics.Add("TagsTerms", GetTerms(searcher, scoreDoc.Doc, "Tags"));
            diagnostics.Add("DescriptionTerms", GetTerms(searcher, scoreDoc.Doc, "Description"));
            diagnostics.Add("AuthorsTerms", GetTerms(searcher, scoreDoc.Doc, "Authors"));
            diagnostics.Add("OwnersTerms", GetTerms(searcher, scoreDoc.Doc, "Owners"));

            diagnostics.Add("PublishedDate", GetInt(searcher, scoreDoc.Doc, "PublishedDate"));
            diagnostics.Add("EditedDate", GetInt(searcher, scoreDoc.Doc, "EditedDate"));

            diagnostics.Add("CuratedFeed", GetMultiValue(searcher, scoreDoc.Doc, "CuratedFeed"));
            diagnostics.Add("Key", GetInt(searcher, scoreDoc.Doc, "Key"));
            diagnostics.Add("Checksum", GetInt(searcher, scoreDoc.Doc, "Checksum"));
            diagnostics.Add("ProjectGuidRankings", GetProjectGuidRankings(searcher, scoreDoc.Doc));



            JObject obj = JObject.Parse(data);

            obj.Add("diagnostics", diagnostics);
            data = obj.ToString();

            return(data);
        }
        private static string ListDocumentsImpl(IndexSearcher searcher, Query query, IDictionary <string, int> rankings, Filter filter, string sortBy, int skip, int take, bool includeExplanation, PackageSearcherManager manager)
        {
            Query boostedQuery = new RankingScoreQuery(query, rankings);

            int  nDocs = GetDocsCount(skip, take);
            Sort sort  = GetSort(sortBy);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            TopDocs topDocs = (sort == null) ?
                              searcher.Search(boostedQuery, filter, nDocs) :
                              searcher.Search(boostedQuery, filter, nDocs, sort);

            sw.Stop();

            sw.Stop();
            return(MakeResults(searcher, topDocs, skip, take, includeExplanation, boostedQuery, sw.ElapsedMilliseconds, rankings, manager));
        }
Пример #4
0
        static Query AutoCompleteMakeQuery(string q, NuGetSearcherManager searcherManager)
        {
            if (string.IsNullOrEmpty(q))
            {
                return(new MatchAllDocsQuery());
            }

            QueryParser queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "IdAutocomplete", new PackageAnalyzer());

            //TODO: we should be doing phrase queries to get the ordering right
            //const int MAX_NGRAM_LENGTH = 8;
            //q = (q.Length < MAX_NGRAM_LENGTH) ? q : q.Substring(0, MAX_NGRAM_LENGTH);
            //string phraseQuery = string.Format("IdAutocompletePhrase:\"/ {0}\"~20", q);
            //Query query = queryParser.Parse(phraseQuery);

            Query query = queryParser.Parse(q);

            Query boostedQuery = new RankingScoreQuery(query, searcherManager.GetRankings());

            return(boostedQuery);
        }
        private static string ListDocumentsImpl(IndexSearcher searcher, Query query, IDictionary<string, int> rankings, Filter filter, string sortBy, int skip, int take, bool includeExplanation, PackageSearcherManager manager)
        {
            Query boostedQuery = new RankingScoreQuery(query, rankings);
            
            int nDocs = GetDocsCount(skip, take);
            Sort sort = GetSort(sortBy);

            Stopwatch sw = new Stopwatch();
            sw.Start();
            TopDocs topDocs = (sort == null) ?
               searcher.Search(boostedQuery, filter, nDocs) :
               searcher.Search(boostedQuery, filter, nDocs, sort);
            sw.Stop();
            
            sw.Stop();
            return MakeResults(searcher, topDocs, skip, take, includeExplanation, boostedQuery, sw.ElapsedMilliseconds, rankings, manager);
        }
 public static Query MakeQuery(string q, NuGetSearcherManager searcherManager)
 {
     Query query = LuceneQueryCreator.Parse(q, false);
     Query boostedQuery = new RankingScoreQuery(query, searcherManager.GetRankings());
     return boostedQuery;
 }
        static Query AutoCompleteMakeQuery(string q, NuGetSearcherManager searcherManager)
        {
            if (string.IsNullOrEmpty(q))
            {
                return new MatchAllDocsQuery();
            }

            QueryParser queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "IdAutocomplete", new PackageAnalyzer());

            //TODO: we should be doing phrase queries to get the ordering right
            //const int MAX_NGRAM_LENGTH = 8;
            //q = (q.Length < MAX_NGRAM_LENGTH) ? q : q.Substring(0, MAX_NGRAM_LENGTH);
            //string phraseQuery = string.Format("IdAutocompletePhrase:\"/ {0}\"~20", q);
            //Query query = queryParser.Parse(phraseQuery);

            Query query = queryParser.Parse(q);

            Query boostedQuery = new RankingScoreQuery(query, searcherManager.GetRankings());
            return boostedQuery;
        }
        private static JToken ListDocumentsImpl(NuGetIndexSearcher searcher, Query query, IDictionary<string, int> rankings, Filter filter, string sortBy, int skip, int take, NuGetSearcherManager manager)
        {
            Query boostedQuery = new RankingScoreQuery(query, rankings);

            int nDocs = skip + take;
            Sort sort = GetSort(sortBy);

            TopDocs topDocs = (sort == null) ?
                searcher.Search(boostedQuery, filter, nDocs) :
                searcher.Search(boostedQuery, filter, nDocs, sort);

            return MakeResults(searcher, topDocs, skip, take, boostedQuery, rankings, manager);
        }