Does the SC.Gridview support grouping? If so, can someone give me some pointers how to get started?
I'm trying to build gridview of tiles separated into logical groups. My underlying model is similar to the following:
TestApp.personModel.FIXTURES = [
{
"name" : "Bob",
"group" : "group1"
},
{
"name" : "Alice",
"group" : "group1"
},
{
"name" : "Tom",
"group" : "group2"
}
];
So, for example, I'd like Bob and Alice tiles to be in 1 group and Tom to be a separate group.
I don't want to use the SC.ListView because each item is going to be arbitrarily complex (i.e., not just a name).
Thanks in advance.
As long as you create a controller that has a list of each group (so an SC.ArrayController) that has a list of the personModel objects releated to each group (fire off a query that will group your results per group), the SC.GridView is able to display each group just as you would like. I would recommend to have an "ItemView" that defines how each item in the grid is rendered. This ItemView is linked up with the GridView via the exampleView property.
Have a look at the following code for the EurekaJ application on how the GridView is used to display a list of charts.
https://github.com/joachimhs/EurekaJ/blob/master/EurekaJ.View/apps/EurekaJView/views/chart/chart_grid.js
Related
I'm trying to compare vespa query capabilities with both ES and MongoDb but I'm having a hard time to figure out what kind of support the YQL has for advanced queries over JSON. (by the way, this would be an awesome post for vespa blog)
For example given an object Person (see example below) with nested documents and/or an array of objects, how could do:
Select all Persons whose hobbies contains 'sport'.
Select all Persons whose Phones area code equals 'NY'.
Select all Persons whose Mother's Birthdate is greater than 1960.
Person = {
Name: 'Joe',
Hobbies: ['sports','books','bonzais'],
Phones: [{Number: '12-3456-7890', areaCode: 'NY'},{Number: '22-3456-7890', areaCode: 'CA'}],
Mother: {
Name: 'Mom',
Birthdate: '1961-24-02'
}
}
Also, are there any best practices regarding how should I model an object for Vespa/YQL?
Thanks in advance.
A clarification first: YQL is just a query syntax. The JSON query language (https://docs.vespa.ai/documentation/reference/select-reference.html) is another. Yet another way (the most common) is to construct queries directly from the data received from clients in a Searcher (Java) component.
Below I show to construct your three examples in each of these variants. Vespa does not have a date type so here I've assumed you have a 'Birthyear' integer field instead.
Select all Persons whose hobbies contains 'sport'.
// YQL (as GET URL parameters)
?query=select * from Persons where hobbies contains 'sports';&type=yql
// JSON (POST body)
{ "contains" : [ "hobbies", "sports" ]}
// Java code
query.getModel().getQueryTree().setRoot(new WordItem("sports", "hobbies"));
Select all Persons whose Phones area code equals 'NY'.
// YQL (as GET URL parameters)
?query=select * from Persons where phones.areaCode contains 'NY';&type=yql
// JSON (POST body)
{"select" : { "where" : { "contains" : [ "phones.areaCode", "NY" ] } } }
// Java code
query.getModel().getQueryTree().setRoot(new WordItem("NY", "phones.areaCode"));
Select all Persons whose Mother's Birthdate is greater than 1960.
// YQL (as GET URL parameters)
?query=select * from Persons where mother.Birthyear > 1960;&type=yql
// JSON (POST body)
{"select" : { "where" : { "range" : [ "mother.Birthyear", { ">": 1960}] } } }
// Java code
query.getModel().getQueryTree().setRoot(new IntItem(">1960", "mother.Birthyear"));
Note:
Structured fields are referenced by dotting into the structures.
Containers becomes (has these tokens) or (equals) depending on the field matching setting.
I have a graph structure in Neo4j for a questionnaire that has the following relationships:
(a:Category)-[:INITIAL_QUESTION]->(b:Question)-[c:Answer*]->(d:Question)
where the specific question text is contained in (b|d).text and the possible answers for each question is contained in the relationship c.response
From the initial question, there are some paths that are longer than others. I would like the return to look something like this:
{"category": "example questionnaire category",
"initialQuestion" : {
"id": 1,
"text": "Example text here",
"possibleAns": {
"yes" : {
"id": 2,
"text": "Second question text here?",
"possibleAns": {
"ans1": {/*Question 4 containing all possible child question nodes nested
in possibleAns*/},
"ans2": {/*Question 5 containing all possible child question nodes nested
in possibleAns*/},
}
},
"no" :{
"id": 3,
"text": "Different question text here?",
"possibleAns": {
"ans1": {/*Question 6 containing all possible child question nodes nested
in possibleAns*/},
"ans2": {/*Question 7 containing all possible child question nodes nested
in possibleAns*/},
}
}
}
}
}
so that the entire category questionnaire is contained in a single, nested map. I've seen some other examples, but haven't been able to tweak those queries to fit my needs, especially given the variable depth of the questionnaire branches.
Is there a Cypher query that makes this possible? If not, what would be the best approach for retrieving the entire questionnaire from the db?
I think that this is not done with standard tools (cypher etc.)
So, or transform the result from cypher query in the json-tree programmatically.
Or, if your neo4j-server versions not less 3.0, you can try apoc.convert.toTree:
MATCH path = (a:Category)
-[:INITIAL_QUESTION]->(b:Question)-[c:Answer*]->
(d:Question)
WITH collect(path) as paths
CALL apoc.convert.toTree(paths) yield value as tree
RETURN tree
I have a document that looks like this:
{
"id": "some guid",
"name": "Bob",
"following": [
{
"id": "some_guid",
"priority": true
}
]
}
The idea is that a user can follow other users.
What I would like to do is, for a given user get the IDs and names of all users that they are following. The name is not stored with in the "following" collection.
If I were using SQL, I'd be doing something like this:
SELECT u.following_id, u.priority, j.name FROM users INNER JOIN j on u.following_id = j.id.
What is the equivalent in DocumentDb SQL?
The equivalent in DocumentDB is to do two round trips. First fetch the user document containing the array of who that user is following. Then build up a big OR clause and use that to fetch the documents of who they are following.
Alternatively, you may want to store the relationship in the other direction. So instead of storing who one user follows in that user's document, store the followedBy list in each of the followers. You can then do an ARRAY_CONTAINS query in one round trip.
You also might want to look at Azure's stream analytics product because it has graph querying capabilities.
I am wanting to write some ruby to iterate through documents in a collection in a MongoDB.
My data has the schema:
"_id" : ObjectId("560ff830eeb4db07875b59b9"),
"userId" : NumberInt(1),
"movieId" : NumberInt(50),
"rating" : 4.0,
"timestamp" : NumberInt(1329753504)
I firstly want to count each time userId = 1 is present in the whole collection, and if less than 5 discard them all.
I'm really unsure how to tackle this, so any advice would be great.
You would need to count the number of documents which have userId = 1 through the count() method. Thus from the shell (command-line), you can do the following:
var count = db.collection.find({ "userId": 1 }).count();
if (count < 5) db.collection.remove()
You'll then have to do something similar with Ruby, but it should be pretty straightforward. Refer to the documentation on the Ruby driver for this:
Get a count of matching documents in the collection.
Remove documents from the collection
So my Rails app using elasticsearch (with searchkick), is working just fine using the _geo_distance ordering function, however I need to do a more complex ordering that includes location AND an attempt to promote a business name exact string match.
For example, if I make a query and there are 10 ascending distance returned results, but the #5 result is also an exact string match on the business name in the record, I would like to promote/elevate that to the #1 position (basically overriding the distance sorting for that record).
There are two ways I can see to try to solve this issue, but I am running into issues with both.
First, would be to do this on the initial query, so that elasticsearch handles the work.
Second, would be to do some type of post-process re-sort on the result returned by elasticsearch to look for an exact match and re-order if needed.
The issue with the first method is that the built in scoring mechanisms seem to shift completely to distance when invoking _geo_distance, leaving me to wonder how to mix custom scoring functions with location.
And the issue with the second method is that the search results returned are a custom type of SearchKick object that does not seem to like normal array or hash sorting mechanisms for a post-process.
Is there a way to do something pre- or post- query to promote a document in the results in this manner?
Thanks.
In fact, there are many ways to "control" the scoring. Before indexing, if you already some document is meant to get high score/boost. You can give high score for the special document before indexing, please reference here.
If you cannot determine the boost before the indexing, you can boost it in the query command. About the boosting query, there are also many options and it's dependent on what kind query you used.
For query string query:
You can boost some fields, such as fields" : ["content", "name.*^5"], or boost some query command such as, quick^2 fox(this might work for you, just extra boost the name).
For others:
You can give boost for term query, such as boosting the "ivan" case:
"term" : {"name" : {"value" : "ivan","boost" : 10.0}}
you can wrap it into bool query and boost the desired case. ex. find all 'ivan', boost 'ji' on name field.
{ "query" : { "bool" : { "must": [{"match":{"name":"ivan"}}],
"should" : [ { "term" : { "name": { "value" : "ji", "boost" : 10 }}}]}}}
Except for term query, there are a lot of queries that support boost, such as prefix query, match query. You can use it under situations. Here are some official examples: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html
Boosting might not easy for controlling score, because it needs normalization. You can specify the score using the function_score query to specify the direct score: It's really a useful query if you need more directly control.
In short, you can wrap your query in bool and add some boost for the name matching, as follow:
{ "query" : {
"bool" : {
"must": [
{"filtered" : {
"filter" : {
"geo_distance" : {
"distance" : "2000km",
"loc" : {
"lat" : 10,
"lon" : 10
}
}
}
}}],
"should" : [ { "term" : { "name": { "value" : "ivan", "boost" : 10 }}}]}},
"sort" : [
"_score",
{
"_geo_distance" : {
"loc" : [10, 10],
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "sloppy_arc"
}
}
]
}
For more detailed, you can check my gist https://gist.github.com/hxuanji/e5acd9a5174ea10c08b8. I boost the "ivan" name. In the result, the "ivan" document becomes first rather than the (10,10) document.