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

  • Home
  • SEARCH
  • 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 8211527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:27:19+00:00 2026-06-07T10:27:19+00:00

this way i am trying to order data List<SearchResult> list = new List<SearchResult>() {

  • 0

this way i am trying to order data

        List<SearchResult> list = new List<SearchResult>() {
        new SearchResult(){ID=1,Title="Geo Prism 1995 GEO GEO- ABS #16213899"},
        new SearchResult(){ID=2,Title="Geo Prism 1995 GEO - ABS #16213899"},
        new SearchResult(){ID=3,Title="Geo Prism 1995 - ABS #16213899"},
        new SearchResult(){ID=3,Title="Geo Prism 1995 - ABS #16213899"},
        new SearchResult(){ID=4,Title="Wie man BBA reman erreicht"},
        new SearchResult(){ID=5,Title="Ersatz Airbags, Gurtstrammer und Auto Körper Teile "},
        new SearchResult(){ID=6,Title="JCB Excavator - ECU P/N: 728/35700"},
        };

        var to_search = new[] { "Geo", "JCB" };
        var result = from searchResult in list
                     let title = searchResult.Title.ToLower()
                     let key_string = to_search.FirstOrDefault(ts => title.Contains(ts))
                     orderby key_string == null ? -1 : title.Split(new[] { key_string }, StringSplitOptions.None).Length descending
                     group searchResult by key_string into Group
                     orderby Group.Count() descending
                     select Group;

        var matched = result.SelectMany(m => m);
        var completeList = matched.Concat(list.Except(matched));
        dataGridView2.DataSource = completeList.ToList();//.SelectMany(x => x).ToList();

data is showing in grid but the way i am expecting data that is not coming.

output is coming now

ID  Title

1   Geo Prism 1995 - ABS #16213899
2   Geo Prism 1995 - ABS #16213899
3   Geo Prism 1995 - ABS #16213899
3   Geo Prism 1995 - ABS #16213899
4   Wie man BBA reman erreicht
5   Ersatz Airbags, Gurtstrammer und Auto Körper Teile 
6   JCB Excavator - ECU P/N: 728/35700

but i want to show data this below way

output should be like

ID  Title

1   Geo Prism 1995 GEO GEO - ABS #16213899
2   Geo Prism 1995 GEO - ABS #16213899
3   Geo Prism 1995 - ABS #16213899
3   Geo Prism 1995 - ABS #16213899
6   JCB Excavator - ECU P/N: 728/35700
4   Wie man BBA reman erreicht
5   Ersatz Airbags, Gurtstrammer und Auto Körper Teile 

JCB should come after all the GEO because i am sorting data with the search word like
“geo jcb” . geo found in title of most of the rows. so those rows come first which has occurance of my search word. so geo is one of my search word and it present maximum time in all rows title. next jcb should come because jcb is in my search term but in output jcb related rows coming at last. so tell me how to change my linq query. thanks

  • 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-06-07T10:27:21+00:00Added an answer on June 7, 2026 at 10:27 am
    class SearchResult{
        public int ID { get; set; } 
        public string Title{ get; set; }
    }
    
    void Main()
    {
    
        List<SearchResult> list = new List<SearchResult>() {
            new SearchResult(){ID=4,Title="Wie man BBA reman erreicht"},
            new SearchResult(){ID=5,Title="Ersatz Airbags, Gurtstrammer und Auto Körper Teile "},
            new SearchResult(){ID=6,Title="JCB Excavator - ECU P/N: 728/35700"},
            new SearchResult(){ID=2,Title="Geo Prism 1995 GEO - ABS #16213899"},
            new SearchResult(){ID=3,Title="Geo Prism 1995 - ABS #16213899"},
            new SearchResult(){ID=1,Title="Geo Prism 1995 GEO GEO- ABS #16213899"},
        };
    
        var to_search = new[] { "Geo", "JCB" };
    
        var result = from sr in list
                     let w = to_search.FirstOrDefault(ts => sr.Title.ToLower().Contains(ts.ToLower()))
                     where w != null
                     let a = new {sr=sr, word=w.ToLower()}
                     group a by a.word into g
                     orderby g.Count() descending
                     let sorted = g.OrderByDescending(a=> a.sr.Title.Select((c, i) => a.sr.Title.Substring(i)).Count(sub => sub.ToLower().StartsWith(a.word)))
                     from a in sorted 
                     select a.sr;
    
        var completeList = result.Concat(list.Except(result));
    
        foreach (var element in completeList)
            Debug.WriteLine(String.Format("ID={0},Title={1}", element.ID, element.Title));
    }
    

    Output:

    ID=1,Title=Geo Prism 1995 GEO GEO- ABS #16213899
    ID=2,Title=Geo Prism 1995 GEO - ABS #16213899
    ID=3,Title=Geo Prism 1995 - ABS #16213899
    ID=6,Title=JCB Excavator - ECU P/N: 728/35700
    ID=4,Title=Wie man BBA reman erreicht
    ID=5,Title=Ersatz Airbags, Gurtstrammer und Auto Körper Teile 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to send mail in this way: Properties props = new Properties(); props.setProperty(mail.transport.protocol,
I am trying to get the results of this code this way: title: Ben
I'm trying to use that method this way: public void Method() { ThreadPool.QueueUserWorkItem(() =>
I'm trying to use PDO in this way and reuse the output template: selected_products_show
I am trying to trigger the onScroll event this way using prototype: Event.observe(document, 'scroll',
I'm trying to get edit text to behave in this way: User can input
So, i'm trying to parse some xml that looks this way: <image size=extralarge> http://...
I'm trying to do this in a way that will prevent end-user browser security
I have been trying to figure this out for way to long tonight. I
I'm trying to figure out the best way to do this, but I'm getting

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.