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 7833249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:37:33+00:00 2026-06-02T12:37:33+00:00

As an example of what I’m trying to accomplish, here is some code which

  • 0

As an example of what I’m trying to accomplish, here is some code which builds out a list of books with a string property called Sentence.

public class Book {
    public string Sentence { get; set; }
}

Book book1 = new Book() { Sentence = "The quick brown fox jumps over the lazy dog" };
Book book2 = new Book() { Sentence = "The quick brown frog jumps over the lazy sloth" };

List<Book> books = new List<Book>();

books.Add(book1);
books.Add(book2);

I want to search through the list of books based on some user input (the search requirements shouldn’t get more complicated than this example).

If a user provides a search phrase of quick fox "lazy dog", then I went to return a List which has book1 as a member of the collection. If a user provides a search phrase of quick fox sloth nothing should be returned because those three words do not all appear in any of the properties.

Summary

  1. quick fox "lazy dog" – 1 Result (the words in quotes appear together, and the remaining words appear individually)

  2. quick fox sloth – No results

  3. "lazy sloth" – 1 Result (both words appear together in the string)

  4. lazy sloth – 1 Result (both words appear individuals in the string)

The code that I currently have:

//Turn the search word into an array of words (includes support for quotes phrases).  E.g: quick fox "lazy dog" becomes a list of these values: `quick`, `fox`, `lazy dog`.
var searchWords = Regex.Matches(searchWord, @"(?<match>\w+)|\""(?<match>[\w\s]*)""")
                       .Cast<Match>()
                       .Select(m => m.Groups["match"].Value)
                       .ToList();

var query = from b in books
            where (!string.IsNullOrEmpty(b.Sentence) && searchWords.Any(b.Sentence.Contains))
            select b;

This doesn’t work for case 2. The code I have now is just looking for 1 match, and if it gets 1 match then it considers the item found.

  • 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-02T12:37:35+00:00Added an answer on June 2, 2026 at 12:37 pm

    I think you might want the All() LINQ method, try this:

    var query = from b in books
                where (!string.IsNullOrEmpty(b.Sentence) && searchWords.All(word => b.Sentence.Contains(word)))
                select b;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Example code: Dim a As String a = 1234,5678,9123 I want to add literal
Example here: http://jsfiddle.net/KyW6c/2/ I have an ordered list. Each list item is a project
Example code: List<Student> Students = new List<Student>() { new Student(101, Hugo, Garcia, new List<int>()
Example code: <html> <head> <script src=jquery-1.3.2.min.js type=text/javascript></script> <script src=jquery-ui-1.7.1.custom.min.js type=text/javascript></script> </head> <body> <table border=1
example: NSString *day = [[NSString stringWithFormat:@السبت];and i think the representation of this string in
Example input string: (F1 (F2 X (Y) Z) (F3 A B) What i want
Example class code: <?php class example { public function forExample() { return true; }
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Example code: int hour = 0; bool saveData = true; if(hour > 0) doSomeMethod();

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.