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

Correct placement of nested query #4

Merged
merged 2 commits into from Oct 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/arelastic/facets/facet.rb
@@ -1,6 +1,16 @@
module Arelastic
module Facets
class Facet < Arelastic::Nodes::Node
attr_reader :name

def initialize name
@name = name
end

def as_elastic
{ name => as_elastic_facet }
end

def nested path
Facets::Nested.new path, self
end
Expand Down
11 changes: 5 additions & 6 deletions lib/arelastic/facets/histogram.rb
@@ -1,17 +1,16 @@
module Arelastic
module Facets
class Histogram < Arelastic::Facets::Facet
attr_accessor :name, :options
attr_accessor :options

def initialize name, options
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea kind of sucks for this part, because all the inheriting classes still define initialize. Muuuurging anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it better anyway. Not as clean as < Struct, but still better than
munging a hash of a certain format.

On Fri, Oct 18, 2013 at 1:10 PM, Matthew Higgins
notifications@github.comwrote:

In lib/arelastic/facets/histogram.rb:

@@ -1,17 +1,16 @@
module Arelastic
module Facets
class Histogram < Arelastic::Facets::Facet

  •  attr_accessor :name, :options
    
  •  attr_accessor :options
    
    • def initialize name, options

My idea kind of sucks for this part, because all the inheriting classes
still define initialize. Muuuurging anyway.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4/files#r7072610
.

@name = name
super name
@options = options
end

def as_elastic
def as_elastic_facet
{
name => {
"histogram" => options
}
"histogram" => options
}
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/arelastic/facets/nested.rb
@@ -1,8 +1,16 @@
module Arelastic
module Facets
class Nested < Struct.new :path, :facet
def as_elastic
facet.as_elastic.merge("nested" => path)
class Nested < Arelastic::Facets::Facet
attr_reader :path, :facet

def initialize path, facet
super facet.name
@path = path
@facet = facet
end

def as_elastic_facet
facet.as_elastic_facet.merge("nested" => path)
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions lib/arelastic/facets/terms.rb
@@ -1,20 +1,19 @@
module Arelastic
module Facets
class Terms < Arelastic::Facets::Facet
attr_accessor :name, :field, :options
attr_accessor :field, :options

def initialize name, field, options = {}
@name = name
super name
@field = field
@options = options
end

def as_elastic
def as_elastic_facet
params = {"field" => field}.update(options)

{
name => {
"terms" => params
}
"terms" => params
}
end
end
Expand Down
4 changes: 0 additions & 4 deletions lib/arelastic/nodes/node.rb
Expand Up @@ -13,10 +13,6 @@ def convert_to_elastic(expr)
end
end

def as_elastic
{}
end

def ==(other)
as_elastic == other.as_elastic
end
Expand Down
15 changes: 10 additions & 5 deletions test/arelastic/facets/facet_test.rb
Expand Up @@ -2,9 +2,14 @@

class Arelastic::Facets::FacetTest < MiniTest::Unit::TestCase
def test_nested
facet = Arelastic::Facets::Facet.new
facet = Class.new(Arelastic::Facets::Facet) do
def as_elastic_facet
{}
end
end.new 'name'

expected = {
"nested" => "links"
"name" => {"nested" => "links"}
}

nested = facet.nested "links"
Expand All @@ -19,9 +24,9 @@ def test_nested_terms
"terms" => {
"field" => "links.name",
"size" => 10,
}
},
"nested" => "links"
},
"nested" => "links"
}
}

nested = facet.nested "links"
Expand Down