How to make a similar search in "github.com"?

149 Views Asked by At

Used - "octokit.net".
I'm interested in searching for "repositories", "users" and filtering results by language.

Scenario:
1. User. Enter a search phrase;
2. Site. Performs a search;
3. Site. Displays the result:
a. repositories;
b. users;
Filter:
- languages;

After clicking the "repositories" or "users" buttons, the result is displayed in the table.
After clicking the languages ​​(for example, "C #"), the results are filtered.

General search result:
Repositories
- Repositories - 108,951 results
- C # (repository) - 4,315 results
Users
- Users - ~ 4K
- C # (users) - ~ 72

How to repeat this script search engine?
I wrote the preliminary code, but I don’t understand how to make it work more correctly.

Method not completed "searchUser (string searchQuery_str)".
I plan to do this by analogy with “SearchReposit (string searchQuery_str, string lang_str)”

Current code logic:
- search all repositories:
- send a request;
- we receive the answer;
- search in repositories that use C #:
- send a request;
- we filter request by language "C #";
- we receive the answer;
Those. Now a separate request is being executed for each case (var request), but it seems to me that you need to execute one request and then perform the following actions on it:
  - filter;
  - sort;
  - clear filtering;
  - clear sorting.

The question is: how to make it possible to execute one request, and then perform the following actions on it:
  - filter;
  - sort;
  - clear filtering;
  - clear sorting
  - calculate the number of search results?

Do I understand the logic correctly and is it possible to do this?

If I understand correctly, the work with the search for "users" will be similar to the search for "repositories".

Link to search documentation - Link

enter image description here
enter image description here

private async void button1_Click(object sender, EventArgs e)
{
    // Получаем поисковую фразу
    string searchQuery_str = Search_txB.Text;
    string lang_str;
      
    // Поиск по репозитариям. "Результат"
    lang_str = "";
    var countRepo = await SearchReposit(searchQuery_str, lang_str);
 
    label5.Text = countRepo;
 
    // Поиск по репозитариям. "Результат"
    lang_str = "C#";
    var countRepoLang = await SearchReposit(searchQuery_str, lang_str);
 
    label7.Text = countRepoLang;
}
 
public async Task<string> SearchReposit(string searchQuery_str, string lang_str)
{
    // Поиск по "Реозитариям"
    var request = new SearchRepositoriesRequest(searchQuery_str); // mvc client side framework - Структура клиентской стороны mvc           
 
    switch (lang_str)
    {
       case "C#":
           request.Language = Language.CSharp;
           break;                
    }
 
    var resultRepo = await client.Search.SearchRepo(request);
 
    // Количество репозитариев
    decimal countRepo_dec = Convert.ToDecimal(resultRepo.TotalCount);
 
    // Количество репозитариев. Форматирование
    string countRepo_str = formatValue(countRepo_dec);
 
    return countRepo_str;            
}
 
// Поиск по "Пользователям" ()
public async void searchUser(string searchQuery_str)     
{        
    var request = new SearchUsersRequest(searchQuery_str); // _____
 
    var resultUser = await client.Search.SearchUsers(request);
 
    label6.Text = resultUser.TotalCount.ToString();
    // var resultUsers = await client.Search.SearchUsers(request);
}
1

There are 1 best solutions below

0
On BEST ANSWER

Changed the variable request:
- was var - became SearchRepositoriesRequest;
- was local - becameglobal`;

Changed the method "SearchReposit (string searchQuery_str, string lang_str)"
- added the argument "bool null_flg" - became "SearchReposit (string searchQuery_str, string lang_str, bool null_flg)";
- added check "bool null_flg";

if (null_flg == false)
{
request = new SearchRepositoriesRequest (searchQuery_str);
}

The code looks like this

SearchRepositoriesRequest request;
    public async Task<string> SearchReposit(string searchQuery_str, string lang_str, bool null_flg)
            {
                //SearchRepositoriesRequest request = new SearchRepositoriesRequest();
                // Поиск по "Реозитариям"
                // if (request == null) // ошб
                if (null_flg == false)
                {
                     request = new SearchRepositoriesRequest(searchQuery_str); // mvc client side framework - Структура клиентской стороны mvc           
                    // return request; 
                }

                switch (lang_str)
                {
                   case "C#":
                       request.Language = Language.CSharp;
                       break;                
                }

                var resultRepo = await client.Search.SearchRepo(request);

                // Количество репозитариев
                decimal countRepo_dec = Convert.ToDecimal(resultRepo.TotalCount);

                // Количество репозитариев. Форматирование
                string countRepo_str = formatValue(countRepo_dec);

                return countRepo_str;            
            }


    private async void button1_Click(object sender, EventArgs e)
            {
                // Получаем поисковую фразу
                string searchQuery_str = Search_txB.Text;
                string lang_str;
                bool null_flg;


                // Поиск по репозитариям. "Результат"
                lang_str = "";
                null_flg = false;
                var countRepo = await SearchReposit(searchQuery_str, lang_str, null_flg);
                null_flg = true;

                label5.Text = countRepo;

                // Поиск по репозитариям. "Результат"            
                lang_str = "C#";
                var countRepoLang = await SearchReposit(searchQuery_str, lang_str, null_flg);

                label7.Text = countRepoLang;

            }

Will this be a normal decision or can it be made more competently?