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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:38:54+00:00 2026-06-14T07:38:54+00:00

I have a Company model that has many industries and a level. I’ve got

  • 0

I have a Company model that has many industries and a level.

I’ve got a helper function that gets the number of industries based on the level.

Say a Company model instance with “Basic” level should only be searchable for the first 2 industries, although it might contain more, I only want it to show up in results for the first 2 industries.

In the model I have

searchable do
  integer :industry_ids, multiple: true

How do I limit the search for the model instance, so that only a specific number of industries can be searched for based on the level as determined by the num_of_industries helper function.

something like

searchable do
  integer :industry_ids[num_of_industries], multiple: true

EDIT:
I figured it out

LIMITED_INDUSTRIES_BASED_ON_LEVEL = {
  'Free' => 1,
  'Silver' => 3,
  'Gold' => 5,
  'Platinum' => 5
}
def industries_limited
  self.industries.limit(LIMITED_INDUSTRIES_BASED_ON_LEVEL[self.level])
end
searchable do
  integer :industry_ids, multiple: true do
    self.industries_limited.map(&:id)
  end
end
  • 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-14T07:38:56+00:00Added an answer on June 14, 2026 at 7:38 am

    Figured it out
    Company’s level is say “Free”, and is thus limited to 1 industry, but it can add more, so in the future if it decides to upgrade, all of the information is there. So I was limiting the search itself to basically only count the industries based on the level (in this case only count the first 1, since for level = “Free”, the limit is 1)

    LIMITED_INDUSTRIES_BASED_ON_LEVEL = {
      'Free' => 1,
      'Silver' => 3,
      'Gold' => 5,
      'Platinum' => 5
    }
    def industries_limited
      self.industries.limit(LIMITED_INDUSTRIES_BASED_ON_LEVEL[self.level])
    end
    searchable do
      integer :industry_ids, multiple: true do
        self.industries_limited.map(&:id)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have a Company model, that has many Employees And has many
I have a User model, Person model and Company model. a User has many
I have a model called company that has_many users then users belongs_to company. class
Let's say that I have a Company model and a Product model, both of
if I have a model that has two model choice fields, is there a
I've got a form that has a single text field (for company): class Cas_Form_Company
so i have a little tricky combination here Company has many Users User belongs
I have a Backbone.Model named Company . My Company model has an Employees Backbone.Collection
I have created a Company model and a profile model. Every User belongs to
i have the following code in the rails company model: class Company include Mongoid::Document

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.