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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:53:14+00:00 2026-05-16T18:53:14+00:00

I have been searching the web for several hours to try to get an

  • 0

I have been searching the web for several hours to try to get an answer on this, but to no avail.

What I am trying to do is AND ‘N’ amount of Disjunctions to refine searches based on white space delimited query.

I have a ‘Unity’ which can be any combination of either a single person or organisation or multiple people/organisation, or any combination of the above.

So if I search for ‘Smith’ I want to match any companies OR people with the name ‘Smith’, easy.

However if someone were to type ‘Smith w’ and want matches on the different combos (OR on Person and Organisation).

So I would get a hit only for a Unity (combination of people and/or organisations) that has BOTH a company or person with smith AND either an organisation

 ICriteria query = Session.CreateCriteria(typeof(Unity), "u")
                .CreateCriteria("Organisations", "o", JoinType.LeftOuterJoin)
                .CreateCriteria("u.People", "p", JoinType.LeftOuterJoin)
                .SetResultTransformer(new DistinctRootEntityResultTransformer())
                .SetMaxResults(10);

        Disjunction keywordsCriteria = Restrictions.Disjunction();

        if (searchTerms.Contains(' ')) {
            foreach (var keyword in searchTerms.Split(' ')) {
                var term = string.Format("%{0}%", keyword);
                keywordsCriteria
                    .Add(Restrictions.Like("p.FirstName", term))
                    .Add(Restrictions.Like("p.LastName", term))
                    .Add(Restrictions.Like("o.Name", term));
            }

        }
        else
        {
            var term = string.Format("%{0}%", searchTerms);
            keywordsCriteria
                .Add(Restrictions.Like("p.FirstName", term))
                .Add(Restrictions.Like("p.LastName", term))
                .Add(Restrictions.Like("o.Name", term));
        }
        query.Add(keywordsCriteria);

        return query.List<Unity>();

This results in

where(p2_.Name1 like '%smith%' /* @p0 */
     or p2_.Name3 like '%smith%' /* @p1 */
     or o1_.EntityName like '%smith%' /* @p2 */
     or p2_.Name1 like '%w%' /* @p3 */
     or p2_.Name3 like '%w%' /* @p4 */
     or o1_.EntityName like '%w%' /* @p5 */)

However what I want to produce is the below

WHERE  ((p2_.Name1 like '%smith%' /* @p0 */
     or p2_.Name3 like '%smith%' /* @p1 */
     or o1_.EntityName like '%smith%' /* @p2 */)
     AND(
     p2_.Name1 like '%w%' /* @p3 */
     or p2_.Name3 like '%w%' /* @p4 */
     or o1_.EntityName like '%w%' /* @p5 */))
  • 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-16T18:53:14+00:00Added an answer on May 16, 2026 at 6:53 pm

    use this

    if (!searchTerms.Contains(' '))
    {
        Disjunction keywordsCriteria = Restrictions.Disjunction();
        var term = string.Format("%{0}%", searchTerms);
        keywordsCriteria
            .Add(Restrictions.Like("p.FirstName", term))
            .Add(Restrictions.Like("p.LastName", term))
            .Add(Restrictions.Like("o.Name", term));
        query.Add(keywordsCriteria);
    }
    else
    {
        Conjunction conjunction = Restrictions.Conjunction();
        foreach (var keyword in searchTerms.Split(' '))
        {
            Disjunction disjunction = Restrictions.Disjunction();
            var term = string.Format("%{0}%", keyword);
                disjunction
                .Add(Restrictions.Like("p.FirstName", term))
                .Add(Restrictions.Like("p.LastName", term))
                .Add(Restrictions.Like("o.Name", term));
            conjunction.Add(disjunction);
        }
        query.Add(conjunction);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching the web for this, but have been unable to find
I have been searching the web for this, but I havent found any decent
I have been searching the web for an answer to my problem, but so
I have been searching for an answer and trying out stuff for days now
I have been searching for a few hours and cant seem to find answer
I've been searching through the web but I have not been able to find
I have been searching through the web and reading many posts, but none has
I have been searching the web for a solution for 3 hours without success.
I have been searching the web, but I have not found huge linear systems
I have been searching the web for an answer now for quite a while,

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.