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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:35:52+00:00 2026-06-12T18:35:52+00:00

Lets say a user has a search form where he searches for properties. Lets

  • 0

Lets say a user has a search form where he searches for properties. Lets say he selects:

Location : ABC
Price Range : 1 million - 5 millions
No. of Bedrooms Range : 5 - 12
State : XYZ
County : PQR
Category: MNO

There is a very slim chance of matching all the fields he selected to yield result from the database. so using AND in WHERE condition doesn’t seem effective here. what I want is –

  1. If all selection matched then no problem show the result
  2. If location, price range, state matched then show the result as well
  3. if location, no of bedrooms, category, state matched then show the result as well
  4. and so on….if any of the combination match then show the result
  • 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-12T18:35:53+00:00Added an answer on June 12, 2026 at 6:35 pm

    How about filtering the table for records that match on any search term and sorting the results in descending order of the number of matching terms:

    SELECT   *,
             (Location = 'ABC')
           + (Price BETWEEN 1000000 AND 5000000)
           + (Bedrooms BETWEEN 5 AND 12)
           + (State = 'XYZ')
           + (County = 'PQR')
           + (Category = 'MNO')
               AS relevance
    FROM     my_table
    WHERE    (Location = 'ABC')
          OR (Price BETWEEN 1000000 AND 5000000)
          OR (Bedrooms BETWEEN 5 AND 12)
          OR (State = 'XYZ')
          OR (County = 'PQR')
          OR (Category = 'MNO')
    HAVING   relevance >= ?   -- specify the minimum number of matching terms here
    ORDER BY relevance DESC
    LIMIT    ?                -- specify the maximum number of matching records here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have 2 Entities, User and Address. Each User has to have
Say User has_many Things. In a User form, I'd like a hidden_field that lets
Let's say I have a schema where User has many Alerts (many to many).
Let's say I have a table that has user_id, date, score, and every user
I have an app that contains several activities...so lets say user is navigating activity
Lets say class User include Mongoid::Document field :sign_in_count, :type => Integer, :default => 0
So lets say that user x sends a message to user y on a
How would i go about having my site know lets say IE User Visit's
Lets say that input from the user is a decimal number, ex. 5. 2155
Lets say you have a web app related Android app that requires the user

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.