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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:30:30+00:00 2026-06-07T09:30:30+00:00

My app has Machines that have and belong to many Specifications class Machine <

  • 0

My app has Machines that have and belong to many Specifications

class Machine < ActiveRecord::Base
  has_and_belongs_to_many :specs

Specifications have both field (width, weight, capacity, horsepower) and value attributes.

The search is done entirely through Solr through Sunspot.

I’d like to be able to find a Machine based on its Specifications, such as find all machines with Width greater than 50.

I know I can index spec_field and spec_valueseparately, but it will filter for specs with value more than 50, which could include fields I don’t want, such as height or capacity (so searching for width > 50 will yield capacity > 50 in results).

Ideally, I’d like to assign each Specification of a Machine to its own indexed field along with its value, so that my index has field such as “height” or “weight”, but the specifications are flexible, and some machines have one set of specs while another machine has a different set, so it doesn’t look like it can work out.

Can it even be done with Solr?

  • 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-07T09:30:32+00:00Added an answer on June 7, 2026 at 9:30 am

    Solution Found

    The Solution I found was to use “Dynamic Fields” as described here

    INDEXING

    dynamic_integer :specs do
      specs.inject({}) do |hash,spec|
        hash.merge(spec.spec_field.label.to_sym => spec.value)
      end
    end
    

    QUERY

      dynamic :specs do
        if params[:specs].present?
          for spec in params[:specs]
            case spec[:condition]
              when "gt"
                with(spec[:field]).greater_than(spec[:value])
              when "lt"
                with(spec[:field]).less_than(spec[:value])
              else
                with(spec[:field],spec[:value])
            end
          end
        end
      end
    

    SOLR keeps looking better and better to me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a C# app that has been working on three machines, 2 running
I have a web-app that has a master mysql db and four slave dbs.
I have a winforms c# app that has an embedded webbrowser control inside it
I have a crossplatform app that has a gtk.StatusIcon sitting in the tray, and
So I have a few machines in production that are running a Sinatra app
I have app that uses ClickOnce deployment. It works on about a dozen machines
My app has an options menu that is available in almost all Activities, which
My app has started throwing errors when I try to save a particular class
I have a quick little app that steps through the possible symmetric encryption methods.
I have a C# app that creates a settings file for itself to store

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.