I'm looking for a way to display my facets in a grouped list. For example i have some users and a facet to filter by country, this gives me:
Country
Holland (5)
England (2)
Egypt (5)
Rwanda (2)
And what i would like to have is:
Europe
Holland (5)
England (2)
Africa
Egypt (5)
Rwanda (2)
I'm using the Tire gem in a Rails application, my models and relations are like this: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-option_groups_from_collection_for_select
I've googled for an example on this for hours, just can't find anything for nested /grouped facets what makes sense to me in Elasticsearch. Hope someone can help me in the right direction! Many thanks in advance!
Daniel
You can probably handle this by indexing the data in two ways and then just parse the outout. Use the "object" version to apply filters, and get your parsing version as a facet to display filters.
For example:
"mydocument":{
"attributes":[
"location":{
{"continent":"europe",
"country":"england"
},
"fur_style":"long"
],
"facets":[
{"location":"Europe##england"},
{"fur_style":"long"
]
}
when you get your data back, you'll have:
"facets":[
{"location":"Europe##england",
"total":5},
{"location":"africa##egypt",
"total":7}
{"fur_style":"long",
"total":3}
etc etc
]
In your application, you just have to loop through and break apart the terms using the ## delimiter (or whatever you want it to be).
Related
I have a graph database with information about different companies and their subsidiaries. Now my task is to display the structure of the company. This I have achieved with d3 and vertical tree.
But additionally I have to write summary statistics about the company that is currently displayed. Companies can be chosen from a dropdown list which is fetching this data dynamically via AJAX call.
I have to write in the same HTML a short summary like :
Total amount of subsidiaries for CompanyA: 300
Companies in Corporate Havens : 45%
Companies in Tax havens 5%
My database consists of two nodes: Company and Country, and the country has label like CH and TH.
CREATE (:TH:Country{name:'Nauru', capital:'Yaren', lng:166.920867,lat:-0.5477})
WITH 1 as dummy MATCH (a:Company), (b:Country) WHERE a.name=‘CompanyA ' AND b.name='Netherlands' CREATE (a)-[:IS_REGISTERED]->(b)
So how can I find amount of subsidiaries of CompanyA that are registered in corporate and tax havens? And how to pass this info further to html
I found different cypher queries to query all the labels as well as apocalyptic.stats but this does not allow me to filter on mother company. I appreciate help.
The cypher is good because you write a query almost in natural language (the query below may be incorrect - did not check, but the idea is clear):
MATCH (motherCompany:Company {name: 'CompanyA'})-[:HAS_SUBSIDIARY]->(childCompany:Company)
WITH motherCompany,
childCompany
MATCH (childCompany)-[:IS_REGISTERED]->(country:Country)
WITH motherCompany,
collect(labels(country)) AS countriesLabels
WITH motherCompany,
countriesLabels,
size([countryLabels IN countriesLabels WHERE 'TH' IN countryLabels ]) AS inTaxHeaven
RETURN motherCompany,
size(countriesLabels) AS total,
inTaxHeaven,
size(countriesLabels) - inTaxHeaven AS inCorporateHeaven
I am trying to group records based on a value from a column, so I can use it to display the information elsewhere. At the moment I have this working if I specify the values in the column -
#city_count = People.select('city,count(*)').where("city in ('london', 'paris')").group(:city).count
This works fine if I want a list of people in London and Paris but if the city list also has Sydney, New York, Rio etc I don't want to keep adding the extra cities to the 'city in', I would like this to just find the people selected by each city.
Does anyone know the best way of doing this? Also if it can include NULL values as well.
Just use:
#city_count = People.group(:city).count
to get counts for all cities. This will include an entry for nil.
A more efficient way would be to use the distinct and count methods together.
#city_counts = Person.distinct.count(:city)
That way the work is done in the db instead of in Ruby.
I have a search form where I want someone to choose to enter in a query or not, then optionally enter in some sort of filter to get a result. So, dealing with 2 fields name and city, let's say someone searches "billy", and "Las Vegas". The user searching knows there is a name that has "billy" in it, but don't know if it's a first, middle, or last, or maybe it was a street name... The one thing the user knows for sure is that the record is in the city "Las Vegas".
Here is my query hash that gives me 0 results.
{
query: {
query_string: {
query: 'billy'
}
},
filter: {
and: [
{term: {city: 'Las Vegas'}}
]
}
}
What am I missing here?
Just came across this. Instead of using the elasticsearch-model gem, use the searchkick gem. Tons easier to integrate and query.
Person.search("billy", where: {city: 'Las Vegas'})
This still uses elasticsearch, and returns the exact results I was looking for!
I'm trying to figure out how to list products in categories to achieve a result similar to this:
Phones (3)
--Smart Phones (2)
----Apple(1)
----Android (1)
--House Phones (1)
Computers (4)
--Laptops (1)
--Desktops (3)
----AMD (2)
----Intel (1)
And when I click on a category it lists the products in that category`
I watched:
http://railscasts.com/episodes/162-tree-based-navigation-revised
http://railscasts.com/episodes/262-trees-with-ancestry
and read:
http://en.wikipedia.org/wiki/Tree_(data_structure)
http://en.wikipedia.org/wiki/Tree_traversal
http://en.wikipedia.org/wiki/Nested_set_model
But I still don't understand how to achieve this in rails. If anyone could point me to the right direction, I'll be very thankful.
Background:
1 - I'm using WebSolr for this search.
2 - I have two fields stored in websolr - name and id.
I want to search for these entries based on name AND boost the search score based on this criteria:
if id in [x1,x2..xN] then +2
if id in [y1,y2..yN] then +1
else +0
From my research, the answer lies in the following
- Function query, or
- DisMaxQParser
I have looked at the documentation but IMO its not very comprehensive.
Any help is appreciated.
You can use boosts. Try a query like
name:searchString AND ( id:[x1 TO xN] ^2 OR id:[y1 TO yN]^1)
In addition to hkn's approach, you could also use DisMax query parser boost queries:
q=queryString
&defType=dismax
&qf=…
&bq=id:[x1+TO+xN]^3
&bq=id:[y1+TO+yN]^2
(Untested, but should convey the idea.)