Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I search by ip address? #28

Open
eddiefisher opened this issue Feb 5, 2016 · 8 comments
Open

how can I search by ip address? #28

eddiefisher opened this issue Feb 5, 2016 · 8 comments

Comments

@eddiefisher
Copy link

No description provided.

@mrkamel
Copy link
Owner

mrkamel commented Feb 5, 2016

please provide more details ...

Server.search("ip:'8.8.8.8'")

@eddiefisher
Copy link
Author

irb(main):021:0> HostSearch.search(ip: '192')
NameError: uninitialized constant SearchCopGrammar::Attributes::Inet
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:89:in `const_get'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:89:in `attribute_for'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:55:in `block in attributes'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:55:in `collect'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:55:in `attributes'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop_grammar/attributes.rb:38:in `matches'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/hash_parser.rb:38:in `parse_attribute'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/hash_parser.rb:21:in `block in parse'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/hash_parser.rb:10:in `each'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/hash_parser.rb:10:in `collect'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/hash_parser.rb:10:in `parse'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop.rb:23:in `parse'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop/query_builder.rb:10:in `initialize'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop.rb:61:in `new'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop.rb:61:in `unsafe_search_cop'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop.rb:53:in `search_cop'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/search_cop-1.0.6/lib/search_cop.rb:44:in `block in search_scope'
  from (irb):21
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
  from bin/rails:4:in `require'

@eddiefisher
Copy link
Author

db: posgresql

@mrkamel
Copy link
Owner

mrkamel commented Feb 5, 2016

huh, could you please provide your search_cop specification from your model ...

@eddiefisher
Copy link
Author

class HostSearch < ::Host
  include SearchCop

  search_scope :search do
    attributes :ip, :name
  end
end

@eddiefisher
Copy link
Author

schema

  create_table "hosts", force: :cascade do |t|
    t.inet     "ip",                                         null: false
    t.string   "name",                  limit: 255
  end

@mrkamel
Copy link
Owner

mrkamel commented Feb 5, 2016

ah, ok, postgres specific datatype. search_cop currently supports text, numeric, date and boolean datatypes. I'll check if this should be extended, thx.

@eddiefisher
Copy link
Author

thx

@mrkamel mrkamel mentioned this issue Feb 8, 2017
jakecraige added a commit to jakecraige/search_cop that referenced this issue Mar 24, 2017
This commit provides a low level extension point in the
hash structure to provide a lambda that returns the section of the query that
is being asked for.

This allows people to query for any DB types or operated that aren't directly
supported in SearchCop, and SearchCop doesn't have to support them.

It's a pretty low level API in that it expects you to know about what nodes and
visitors are, but this seems like a starting point that gets users past being
stuck, and could be built on in the future.

One of those things that I think could be useful is providing this same
structure, but as one of the `options` instead and that would be used every time
you query for that said attribute. The downside of the method proposed in this
PR is that you have to use the hash parser, and inline your SQL there and every
other place you want to use it. Providing it as a default option would allow
that.

Related to mrkamel#31 and mrkamel#28.
jakecraige added a commit to jakecraige/search_cop that referenced this issue Mar 24, 2017
This commit provides a low level extension point in the
hash structure to provide a lambda that returns the section of the query that
is being asked for.

This allows people to query for any DB types or operated that aren't directly
supported in SearchCop, and SearchCop doesn't have to support them.

It's a pretty low level API in that it expects you to know about what nodes and
visitors are, but this seems like a starting point that gets users past being
stuck, and could be built on in the future.

One of those things that I think could be useful is providing this same
structure, but as one of the `options` instead and that would be used every time
you query for that said attribute. The downside of the method proposed in this
PR is that you have to use the hash parser, and inline your SQL there and every
other place you want to use it. Providing it as a default option would allow
that.

Related to mrkamel#14, mrkamel#28 and mrkamel#31.
jakecraige added a commit to jakecraige/search_cop that referenced this issue Apr 21, 2017
This commit provides an extension point in the `search_scope` definition that
allows you to define a named `generator` that can be used with the hash
structure to perform arbitrary SQL queries.

This allows people to query for any DB types or operators that aren't directly
supported in SearchCop, and SearchCop doesn't have to support them.

Related to mrkamel#14, mrkamel#28 and mrkamel#31.
jakecraige added a commit to jakecraige/search_cop that referenced this issue Apr 21, 2017
This commit provides an extension point in the `search_scope` definition that
allows you to define a named `generator` that can be used with the hash
structure to perform arbitrary SQL queries.

This allows people to query for any DB types or operators that aren't directly
supported in SearchCop, and SearchCop doesn't have to support them.

Related to mrkamel#14, mrkamel#28 and mrkamel#31.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants