Пример #1
0
        public List <Question> RelatedQuestions(string Title, string Description)
        {
            var    relatedQuestions = new List <Question>();
            string query            = Title + " " + Description;

            if (BM25Searcher.IsValidString(query))
            {
                initSearcher();
                LoadSearcher();
                List <Question>    questions   = new List <Question>();
                List <ISearchable> searchables = _searcher.Search(query);
                foreach (ISearchable s in searchables)
                {
                    questions.Add((Question)s);
                }

                foreach (ISearchable s in searchables)
                {
                    Question q = (Question)s;
                    relatedQuestions.Add(q);
                    if (relatedQuestions.Count == MAX_RELATED_QUESTIONS)
                    {
                        break;
                    }
                }
            }
            return(relatedQuestions);
        }
Пример #2
0
 public string[] SuggestStudios(String query)
 {
     string[] suggestion = new string[3];
     if (BM25Searcher.IsValidString(query))
     {
         initSearcher();
         List <Question>    questions   = new List <Question>();
         List <ISearchable> searchables = _searcher.Search(query);
         foreach (ISearchable s in searchables)
         {
             questions.Add((Question)s);
         }
         var relatedQuestions = new List <Question>();
         foreach (ISearchable s in searchables)
         {
             Question q = (Question)s;
             relatedQuestions.Add(q);
             if (relatedQuestions.Count == MAX_RELATED_QUESTIONS)
             {
                 break;
             }
         }
         suggestion = SuggestedStudios(relatedQuestions);
     }
     return(suggestion);
 }
Пример #3
0
        public async Task <IActionResult> Search(string query)
        {
            if (BM25Searcher.IsValidString(query))
            {
                initSearcher();
                List <Question>    questions   = new List <Question>();
                List <ISearchable> searchables = _searcher.Search(query);
                foreach (ISearchable s in searchables)
                {
                    questions.Add((Question)s);
                }
                return(View("Index", questions));
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        public async Task <IActionResult> AdvancedSearch(string query, string studio, string studio2, string studio3, string glober,
                                                         string question_tags)
        {
            SetActiveUser();
            List <Question> questions = new List <Question>();

            if (BM25Searcher.IsValidString(query))
            {
                initSearcher();
                LoadSearcher();

                List <ISearchable> searchables = _searcher.Search(query);
                foreach (ISearchable s in searchables)
                {
                    questions.Add((Question)s);
                }
            }
            else
            {
                questions = await _context.Question.Where(q => q.isArchived == false)
                            .Include(q => q.Answers)
                            .Include(q => q.InterestingVotes)
                            .Include(q => q.Views)
                            .Include(q => q.QuestionLabels)
                            .ThenInclude(ql => ql.Label)
                            .Include(q => q.QuestionStudios)
                            .ThenInclude(qs => qs.Studio)
                            .Include(q => q.User)
                            .ToListAsync();
            }
            questions.RemoveAll(q => !q.IsUser(glober));
            if (!string.IsNullOrEmpty(question_tags))
            {
                string[] tagsStr = question_tags.Split(",");
                foreach (string t in tagsStr)
                {
                    questions.RemoveAll(q => !q.HasTag(t));
                }
            }
            questions.RemoveAll(q => !q.HasStudio(studio));
            questions.RemoveAll(q => !q.HasStudio(studio2));
            questions.RemoveAll(q => !q.HasStudio(studio3));
            return(View("Index", questions));
        }