Comments (10)
This may not be a bug but a feature request to enable anding of filters, I will take a look at your code in depth
Thanks
from retire.
Hi, could you post a full example, with couple of docs, index creation, query, please? So I can recreate on my side?
Karel
On 17.May, 2011, at 21:59 , willoughby wrote:
When using filtering by facets only the counts do not seem to reflect what the search results are
@s = Tire.search "14" do
query do
string 'title:*'
end
filter :terms, :prices => ["#{price}"] if price
filter :terms, :tags => ["#{tag}"] if tag
facet 'current-tags' do
terms :tags
end
facet 'current-prices' do
terms :prices
end
endEmpty search returns
Tags
1 - 48 (coresponds to "Kitchen")
Prices
1 - 2282
2 - 1455
4 - 258
3 - 138Filter based on tag 1 apears to select the correct documents but facet counts remain as above. however by editing the query to title :kitchen
the facets look correct
Tags
1 - 48
Prices
1 - 48
2 - 47
4 - 14
3 - 4Hope this make sense.
Regards
Reply to this email directly or view it on GitHub:
#21
from retire.
Hi Karel
I have push this as an example https://[email protected]/willoughby/facet_example.git
What I am trying to do is,
From a initial query of title:*
Show all available facets
On selection of a facet (tag:ruby) show the relevant results and facets
Select a different facet (category:one) show results based on tag:ruby AND category:one
The call below does this but can do Tire do this?
Regards
Nath
{"query":
{"query_string":{"query":"title:*"}},
"facets" : {
"tags" : {
"terms" : {"field" : "tags"},
"facet_filter" : {
"and" : [
{"term" : {"tags" : "ruby"}},
{"term" : {"category" : "one"}}
]
}
},
"category":{"terms":{"field":"category"},
"facet_filter" : {
"and" : [
{"term" : {"tags" : "ruby"}},
{"term" : {"category" : "one"}}
]
}
},
"price":{"terms":{"field":"price"},
"facet_filter" : {
"and" : [
{"term" : {"tags" : "ruby"}},
{"term" : {"category" : "one"}}
]
}
}
},"filter":{"terms":{"tags":["ruby"]}},
"filter":{"terms":{"category":["one"]}}
}
from retire.
Hi, sooo, sorry it took so long. Now I understand what you mean, looking at http://www.elasticsearch.org/guide/reference/api/search/filter.html.
I think it should be doable right now, because facet options like global
are encoded:
Tire.search 'someindex' do
query { string "title:*" }
facet 'tags' do
terms :tags, :facet_filter => { :and => [ {:term => { :tags => 'ruby }}, :term => { :category => 'one' } ] }
end
# ...
end
I'm writing this from heart, so it may not work as expected. Could you try it?
from retire.
Ping, any updates, @willoughby? :)
from retire.
I was trying to do the same thing that willoughby was and was unable to accomplish this because using the above example, the :facet_filter would be scoped within the :terms instead of under the facet itself. I am new to Tire/Elasticsearch so I may be doing something wrong, but here is what I was able to come up with:
Monkeypatch for Tire::Search::Facet:
def filter(type, *options)
@filters ||= []
@filters << Filter.new(type, *options).to_hash
self
end
def to_hash
@value.update @options
@value.update( { :facet_filter => @filters.first.to_hash } ) if @filters && @filters.size == 1
@value.update( { :facet_filter => { :and => @filters.map { |filter| filter.to_hash } } } ) if @filters && @filters.size > 1
{ @name => @value }
end
then I could use it just like the search filter:
filters = []
filters << { :upccode => params[:upccode] } if params[:upccode]
@search = Tire.search( 'product' ) do |s|
s.query do |q|
q.string params[:keyword] if params[:keyword]
end
#Specify the filters on this search
filters.each { |filter| s.filter :term, filter }
[:product_line_id].each do |f|
s.facet(f.to_s) do |facet|
facet.terms f
facet.filter :term, { :upccode => ... }
end
end
end
from retire.
Hey ejlevin1
This might help solve your problem
s = Tire.search "products_#{current_site}" do
query do
boolean do
must { string query}
must {term :retailer_id, params[:retailer_id] } if params[:retailer_id].present?
must {term :price, params[:price] } if params[:price].present?
end
end
facet "retailer_id" do
terms :retailer_id, :size=> 1000
end
facet "price" do
terms :price
end
size(20)
from(params[:page] || 0)
end
from retire.
def self.power_facets(domain_id, anchor_words, tag)
tire.search do
query do
boolean do
must { string "domain_id:#{domain_id}" }
end
end
facet "market_ranks" do
terms :market_rank, :facet_filter => { :and => [ {:term => { :tags => tag }}, :term => { :anchor_words => anchor_words } ] }
end
end
end
code above is does not work
i want to use filter facets, http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html
how can I do that with tire?
from retire.
@agungyuliaji https://github.com/karmi/tire/blob/master/test/integration/facets_test.rb#L296-L305
from retire.
thanks! :)
but the results were not as I wanted
{"market_ranks"=>{"_type"=>"filter", "count"=>198}}
i want like this :
{"market_ranks"=>{"_type"=>"terms", "missing"=>0, "total"=>198, "other"=>0, "terms"=>[{"term"=>2, "count"=>134}, {"term"=>1, "count"=>38}, {"term"=>3, "count"=>10}, {"term"=>0, "count"=>10}, {"term"=>6, "count"=>2}, {"term"=>5, "count"=>2}, {"term"=>4, "count"=>2}]}}
now I have new a code :
def self.power_facets(domain_id, anchor_words, tag)
tire.search do
query do
boolean do
must { string "domain_id:#{domain_id}" }
end
end
facet "market_ranks" do
terms :market_rank
facet_filter :term, tags: tag
facet_filter :term, anchor_words: anchor_words
end
end
end
But it seems to apply only the last filter. But I need both of them.
from retire.
Related Issues (20)
- empty array HOT 2
- Elasticsearch 1.2.1, empty hash should be removed. HOT 5
- T
- Can I use regexp query via tire? HOT 1
- Persistence module does not provide updating a record. HOT 2
- "uninitialized constant" error on import rake task HOT 3
- Sort by field value other model (table)
- How can we use tire with multitenant app?
- Timeout option on activerecord? HOT 1
- Boost hits based on date HOT 2
- is there a way to use tire with zeus-parallel_tests?
- Custom Mapping on Hstore Columns
- Elasticsearch(0.90.9) failed to download 230K records(~80mb), with Tire gem(0.4.2).Below was the error message
- Elasticsearch(0.90.9) failed to download 230K records(~80mb), with Tire gem(0.4.2).Below was the error message
- import:all tasks: models load HOT 1
- Regarding nested query
- Support to `search_type: scan` HOT 1
- Ordering doesn't work without RoR shutdown HOT 1
- d
- Querying Association Trouble? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retire.