public ActionResult <SearchIndexResponse> SearchExistingIndex(SearchIndexRequest model) { m_Logger.Info($"[GET] {APIRoutes.SearchInIndexRoute}"); if (string.IsNullOrWhiteSpace(model.SearchWord)) { m_Logger.Debug("Required parameter SearchWord is null, empty or whitespace"); return(BadRequest()); } if (m_Manager.GetIndexById(model.IndexID) == null) { m_Logger.Debug("Required parameter IndexID point to non existing index"); return(BadRequest()); } m_Logger.Info($"looking in index {model.IndexID} for {model.SearchWord}"); var searchResults = m_Manager.SearchInIndex(model.IndexID, model.SearchWord); return(new SearchIndexResponse { Results = searchResults.ToArray() }); }
internal static void ShowCreateNewIndexMenu(ICodeSearcherManager manager, ITextBasedUserInterface tui, IMenuNavigator nav) { string answer; // Source path string sourcePath = null; do { tui.WriteLine("Please enter Path with Sources to Index:"); answer = tui.ReadLine(); if (Directory.Exists(answer)) { sourcePath = answer; tui.WriteLine($"Path with files to Index: {sourcePath}"); break; } tui.WriteLine("Path do not exist!"); } while (tui.ShouldLoop()); // file extensions var extensions = new List <String>(); tui.WriteLine("Please select file extension to index (form .ext1,.ext2)"); tui.WriteLine("Leave empty to use (.cs,.xml,.csproj) "); answer = tui.ReadLine(); if (string.IsNullOrWhiteSpace(answer)) { extensions.Add(".cs"); extensions.Add(".xml"); extensions.Add(".csproj"); } else { foreach (var extension in answer.Split(new[] { ',' })) { extensions.Add(extension); } } tui.WriteLine("Looking for files with extensions: "); extensions.ForEach((ext) => tui.WriteLine($"File Extension: {ext}")); if (!string.IsNullOrWhiteSpace(sourcePath) && extensions.Count > 0) { var id = manager.CreateIndex(sourcePath, extensions); tui.WriteLine($"New Index created with ID: {id}"); do { tui.WriteLine("[1] Search in new created index"); tui.WriteLine("[2] Back to main menu"); tui.WriteLine("Please choose: "); answer = tui.ReadLine(); if (int.TryParse(answer, out int selection)) { if (1.Equals(selection)) { var selectedIndex = manager.GetIndexById(id); nav.GoToSelectedIndexMenu(manager, selectedIndex, tui); } else if (2.Equals(selection)) { nav.GoToMainMenu(tui); } } } while (tui.ShouldLoop()); } }