Esempio n. 1
0
        Program()
        {
            Docs      = new List <Document>();
            _searcher = new BM25Searcher();
            ReadArticles();
            int userInput = 0;

            do
            {
                userInput = DisplayMenu();
                switch (userInput)
                {
                case 1:
                    AddDocument();
                    break;

                case 2:
                    Query();
                    break;

                case 3:
                    SeeDocuments();
                    break;
                }
            } while (userInput != 4);
        }
Esempio n. 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);
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void initSearcher()
        {
            if (_searcher == null)
            {
                _searcher = new BM25Searcher();
            }

            LoadSearcher();
        }
Esempio n. 5
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)));
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
 private void initSearcher()
 {
     _searcher = new BM25Searcher();
     LoadSearcher();
 }