Skip to content

Unreachable code in activerecord_extensions #6

Description

@dave-gantenbein

Hi-

If you call search_raw and it passes models as false to the indextank_search function, models gets set to a true value (empty array), and the raw never executes:

    models = []
    res = it.search("__any:(#{query.to_s}) __type:#{self.name}", options)
    if models # <---- I am always true!
        res['results'].each do |doc|
            type, docid = doc['docid'].split(" ", 2)
            models << self.find(id=docid)
        end
        return models
    else
        res['results'].each do |doc|
            type, docid = doc['docid'].split(" ", 2)
            doc['model'] = self.find(id=docid)
        end
        return res
    end

I've patched my local copy thusly, and now can access the raw results.

    res = it.search("__any:(#{query.to_s}) __type:#{self.name}", options)
    if models
        models = [] # <--- assign me after checking!
        res['results'].each do |doc|
            type, docid = doc['docid'].split(" ", 2)
            models << self.find(id=docid)
        end
        return models
    else
        res['results'].each do |doc|
            type, docid = doc['docid'].split(" ", 2)
            doc['model'] = self.find(id=docid)
        end
        return res
    end

With this change it seems to work both ways now.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions