Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 743849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:54:39+00:00 2026-05-14T08:54:39+00:00

I want to do a search for Music instruments which has its informations Name,

  • 0

I want to do a search for Music instruments which has its informations Name, Category and Origin as I asked in my post.

But now I want to sort/group the result by similarity/equality to the keyword such as.
If I have the list

{ Drum, Grand Piano, Guitar, Guitarrón, Harp, Piano} << sorted by name

and if I queried "p" the result should be { Piano, Grand Piano, Harp }
but it shows Harp first because of the source list’s sequence

and if I add {Grand Piano} to the list and query "piano"
the result shoud be like { Piano, Grand Piano }
or query "guitar"
it should be { Guitar, Guitarrón }

here’s my code

static IEnumerable<MInstrument> InstrumentsSearch(IEnumerable<MInstrument> InstrumentsList, string query, MInstrument.Category[] SelectedCategories, MInstrument.Origin[] SelectedOrigins)
{
    var result = InstrumentsList
        .Where(item => SelectedCategories.Contains(item.category))
        .Where(item => SelectedOrigins.Contains(item.origin))
        .Where(item =>
            {
                if (
                        (" " + item.Name.ToLower()).Contains(" " + query.ToLower())
                        || item.Name.IndexOf(query) != -1
                    )
                {
                    return true;
                }
                return false;
            }
        )
        .Take(30);

    return result.ToList<MInstrument>();
}

Or the result may be like my old self-invented algorithm that I called "by order of occurence",
that is just OK to me.

And the further things to do is I need to search the Name, Category or Origin such as.
If i type "Italy" it should found Piano or something from Italy.
Or if I type "string" it should found Guitar.

Is there any way to do those things, please tell me.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:54:39+00:00Added an answer on May 14, 2026 at 8:54 am

    You want OrderBy / OrderByDescending —

    result = InstrumentsList.
         .Where(...)
         .OrderByDescending(instrument => 
             StringSimilarityScore(instrument.Name, searchString))
         .Take(30);
    

    As to the definition of StringSimilarityScore — a full-on fuzzy match would be best, but you could start by quantifying the match based on the proportion of the name matched by the search string:

    double StringSimilarityScore(string name, string searchString)
    {
        if (name.Contains(searchString))
        {
            return (double)searchString.Length / (double)name.Length;
        }
    
        return 0;
    }
    

    You might then want to consider the position of the search string within the name (earlier is better), for the cases where a single letter is specified — but I’ll leave that up to you. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to search two item (name=string and location=json). this search is (one input
I want to search a series of files based on the files name. Here
I want to search a text in a table without knowing its attributes. Example
I want to get all the articles names under a category and its sub-categories.
Hello i am making an small application in which i want search functionality i
I want to search through existing Excel files with a macro, but I don't
So I have this website that has a search feature which searches a table
all I want to display youtube subscriber using its api. But not able to
I have a members control panel page which I don't want search engine to
I want to search for a word and its variants in a sentence. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.