fusejs.io : Weight the items by type - fuse.js

First, thank for this great fusejs.io component, works like a charm.
There is one tweak though that I would like to see. Or, maybe, this is already possible, but I just dont know how to do it. Any help would be appreciated.
Say we have a JSON that combines both a list of Products and Categories of Product. I would like my users to be able to search for both. However, the need is to get the Products always above. In my example below, is there a way to weight the 'ObjectType' Product higher than the other one?
Thanks in advance
{"title":"Product A1","ObjectType":"Product","text":"","tags":"","} ,{"title":"Product A2","ObjectType":"Product","text":"","tags":""} ,{"title":"Product B1","ObjectType":"Product","text":"","tags":"",} ,{"title":"Category A2","ObjectType":"Category","text":"","tags":""}
Thanks in advance

Related

Return All Suburbs, Post Codes and Location IDs for a State

I am using Overpass Turbo and I am looking to create a very simple extract that has the following fields:
State
Suburb
Post Code
Location ID (ref:psma:loc_pid)
This is the query I have so far, but it's not giving very clean results. There are also many blank rows on the bottom of the result.
http://overpass-turbo.eu/?q=LyoKVGhpcyBoYcSGYmVlbiBnxI1lcmF0ZWQgYnkgdGhlIG92xJJwxIlzLXR1cmJvIHdpemFyZC7EgsSdxJ9yaWdpbmFsIHNlxLBjaMSsxIk6CsOiwoDCnGNpdHnFiMKdCiovCltvdXQ6Y3N2KCfEu21lJywgJ3Bvc3TEvF9jb2TFoSwncmVmOnBzbWE6bG9jX3BpZCcpXVt0acWgxZbFmDI1XTsKe3vEkMW8xa1lQcWyxblUxInFuG5pYX19LT4uxL_FgWjGlsWAxo4vL8SPxJTEnXIgxbJzdWx0cwooCiAgxqogcXXEksSaxKNydCBmb3I6IMWIxYrFjMWOwoDFkMa5IG7GlFtwbGFjZX4ixrJixKhiIl0oxLDFgMajxYByxYLGp2Epxo7GusWyx5fGhm9uWyJhZG3Eul9sZcShbCIgPSAiOcehx6PGl8emxqXHqsesCgrIi8a8cMS3bseExrHGs8a1CsaJxJjFrXnGjj7GjsiYc2tlxL1xdDs
Can someone please give me some pointers around what I need to to do to fix this query, the documentation on Overpass is not great and is quite hard to follow.
Thanks in advance.

How to set permissions efficiently

I have a list of Exchanges (extract shown below) and I want to give a user WRITE permissions to all but those containing Invoice in the name. Here an extract of the list of Exchanges as an example:
E.BankAccount.Commands
E.BankAccount.Commands.Confirmations
E.BankAccount.Commands.Errors
E.BankAccount.Events
E.Customer.Commands
E.Customer.Commands.Confirmations
E.Customer.Commands.Errors
E.Customer.Events
E.Invoice.Commands
E.Invoice.Commands.Confirmations
E.Invoice.Commands.Errors
E.Payment.Commands
E.Payment.Commands.Confirmations
E.Payment.Commands.Errors
E.Payment.EventsEvents.test
So I can write a regex like this:
E\.(BankAccount|Customer|Payment)\.[a-zA-Z.]+
This works but since I have more than 100 different types it is a lot to type and almost impossible to maintain. Better would be to have a regex which excludes invoice. I tried a couple of things but without any look, e.g.
E\.([a-zA-Z.]+|?!Invoice)\.[a-zA-Z.]+ or
E\.([a-zA-Z.]+|?!(Invoice))\.[a-zA-Z.]+
But that is all syntactically wrong. Another strategy could be to reverse the result of the expression e.g. use
E\.(Invoice)\.[a-zA-Z.]+
and then somehow reverse the entire result but I could not figure out how!
I am not using regex very often so I can't find any better solution then the first one which is impracticable in my production environment.
Does anybody have more experience and a solution to that problem?? Any help would be greatly appreciated!

Order not working correctly in MDX

I'm new to MDX and I cannot get the ordering correct. I looked at references online and I think i sorted the query correctly, but the result of the query doesn't agree with me. Can anyone shed some light into what I'm not doing.
I have included a hypothetical example that is close to my problem.
The result of the query comes out without being sorted.
Any help is deeply appreciated.
Thanks
The 2nd argument to the Order()-function on your Rows-axis, must be the value or string to sort by. If you want to sort by the names of the SalespersonID-members, do something like this:
Order([Sales].[SalespersonID], [Sales].CURRENTMEMBER.MEMBER_NAME) on Rows

Pluck last value of an association in rails

The model Price has an attribute data, so
Price.pluck(:data)
results in something like [3.99,4.55,5.44]
And Price belongs to Vendor
So I want to select the best price for each vendor, something like
Vendor.all.pluck(prices.order("data ASC").first.data)
How can I go about extracting the lowest price data element for each vendor in this scenario? Thank you in advance for the help.
For each vendor, use minimum(:data) on its associated prices:
Vendor.includes(:prices).map { |v| v.prices.minimum(:data) }
Here's another approach which puts more work on the database and less on Ruby. (I'm pretty sure the code in #meagar 's answer will issue a select for each vendor during the map). Which way is better (faster) may depend on how big your tables areā€¦
You could do something like this, which will issue one SQL statement:
Vendor.select('min(prices.data) as min_price').from('vendors').joins('INNER join prices on vendors.id = prices.vendor_id').group('vendors.id')map {|v| v.min_price}
You don't gain anything from getting the Vendor model involved--everything you need to know about vendor is already in the Price model as vendor_id, right?
So all you need is:
Price.order(:data).group(:vendor_id).pluck(:data)

Rails sum on an associated record

I have a survey model that works like so:
ResponseSets have many Responses
Responses belong_to Answer
Answer model has a "value" column.
Given a ResponseSet, I'd like the sum of the Answers that are associated with each Response.
Ie, what I'd like to be able to do, (in imaginary code) is:
response_set.responses.answers.sum('value')
However, this obviously doesn't work, I need to build a query through response_set.responses, but I don't know how.
What's the SQL-fu way to tackle this in ActiveRecord?
After much trial and error I came up with this relatively simple solution, I hope this helps others in the future:
response_set.responses.joins(:answer).sum('answers.value')
To make this more convenient I just made this a method in the ResponseSet Model:
def total_value
self.responses.joins(:answer).sum('answers.value')
end
Well if you're using Rails 3.2 you can do something like:
response_set.responses.answers.pluck(:value).inject{|sum,x| sum + x }
Are the answers Integers, in the sense that you're looking to find ALL numeric answers associated with a response and literally add them all up? I think you could use map and inject for something like this, depending exactly on how your models/associations are set up..
response_set.responses.answers.map(:&value).inject(:+)
Can you post your models?