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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:54:26+00:00 2026-06-04T02:54:26+00:00

I am using a few persisted Tire models in my Rails app. Searching has

  • 0

I am using a few persisted Tire models in my Rails app. Searching has been working fine, using Tire.search ['index1','index2'], :load => true do ... But I now made a new index and model, and I get the following error when trying to include it in the search and access its results:

undefined method `detect' for #<AuthoredHistory:0x000001013d6a88>

I see it’s coming from Tire::Results::Collection#results, down at the last line:

@response['hits']['hits'].map { |item| records[item['_type']].detect { |record| record.id.to_s == item['_id'].to_s } }

For some reason records[item['_type']] returns a Tire::Results::Collection object for my other models, but with the new class it returns an AuthoredHistory object, which is my actual model class. I saw something about this on the gem’s github page, but I am not doing anything with Tire.configuration.wrapper. I am including Persistence, Search, and Callbacks modules in all indexed models.

Am I missing something? Can someone please point me in the right direction? (karmi, I’m hoping you can save me here!)

[UPDATE]

Now I’m getting somewhere… an error was occurring when only 1 result from a particular index is returned with the results. If there are 2 or more results from an index, it wraps it in Tire::Results::Collection. Now to find a hack…

[UPDATE again]

Hacky solution found! Look below for the answer…

  • 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-04T02:54:28+00:00Added an answer on June 4, 2026 at 2:54 am

    I found a hack that I believe works… not a pretty one, but that’s the nature of the hack. If there is only ONE result for a particular model, the records do not return a Tire::Results::Collection object but rather just an object of the actual model, which fails on detect. So, I must check if we have a Collection or not, and if not, simply wrap it in an array. It seems to work for now, hopefully there are no ill effects down the road…

    Here is the hack… this replaces the problematic line that I posted in the question:

    @response['hits']['hits'].map do |item|
      collection = records[item['_type']].is_a?(Tire::Results::Collection) ?
        records[item['_type']] :
        [records[item['_type']]]
      collection.detect { |record| record.id.to_s == item['_id'].to_s }
    end
    

    ALSO! I had done a hack before to account for when the search results as a whole only returned one item. I had to insert this line right before the same problematic line above:

    return [records[@response['hits']['hits'].first['_type']]] if @response['hits']['hits'].size == 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using ZF for few months and I'm really happy with it however
I have an app that I'm attempting to integrate hibernate search into. I'm using
I've been using Fiddler for a few days now, extending CustomRules.js with my own
So I've got an app which compiles fine on windows, linux and a few
I'm using a few repository which I do not host myself and I thinking
I’m using a few custom MSBuild tasks that are checked into source control. I
I'm using a few jQuery UI modal dialogs and the positioning of each dialog
I have run a few using batch jobs, but, I am wondering what would
Right now I'm using a few scripts to generate files that I'm including as
How to pause a program for a few milliseconds using C++ managed code? I

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.