I think this is best explained using an example. Say I want to display a list of movies with actors below each move.
eg:
Movie A
- Actor 1
- Actor 2
Movie B
- Actor 4
- Actor 5
- etc.
JSON file looks like:
{ movies: [
{ movie_name: "Movie A",
actors: [
{ actor_name: "Actor 1" },
{ actor_name: "Actor 2" }
]
},
{ movie_name: "Movie B",
actors: [
{ actor_name: "Actor 4" },
{ actor_name: "Actor 5" },
]
}
]
}
The view:
<TableView dataCollection="movies">
<TableViewRow>
<Label class="movie_heading" text="{movie_name}"></Label>
**<Label dataCollection="actors.actor_name ???? ">**
</TableViewRow>
</TableView>
I'm not sure how to go about binding the actors to the second level of the view. I'm looking for something like ng-repeat in angular but I can't seem to rebind actors.actor_name. Any help appreciated :)
Pretty sure you can't do this at the moment in Accelerator.
Related
I have a blog built in NextJS, backed by Sanity. I want to start tagging posts with tags/categories.
Each post may have many categories.
Category is a reference on post:
defineField({
name: 'category',
title: 'Category',
type: 'array',
of: [
{
type: 'reference',
to: [
{
type: 'category',
},
],
},
],
}),
This is my GROQ query:
*[_type == "post" && count((category[]->slug.current)[# in ['dogs']]) > 0] {
_id,
title,
date,
excerpt,
coverImage,
"slug": slug.current,
"author": author->{name, picture},
"categories": category[]-> {name, slug}
}
The above works, when it is hardcoded, but swapping out 'dogs' with $slug for example will cause the query to fail. (Where $slug is a param provided)
*[_type == "post" && count((category[]->slug.current)[# in [$slug]]) > 0]
{
$slug: 'travel'
}
How do I make the above dynamic?
Returns all documents that are storefronts // within 10 miles of the user-provided currentLocation parameter ; // For a given $currentLocation geopoint
I can't believe it. Rookie mistake. I needed to pay more attention in the Sanity IDE. (To be fair there was a UI bug that hid the actual issue)
The param should not contain the $. E.g the following works in the GROQ IDE.
{
slug: 'travel'
}
I have a working query that flattens a nested JSON object into rows of data. What I would like to do, however, is preserve the original order of one array of objects which is nested several layers in.
I have tried to use ROW_NUMBER with an ORDER BY NULL and an ORDER BY (SELECT NULL) and neither seem to preserve the order.
Any ideas on how to accomplish that? Examples below. I chose to mask the real data, but the important parts of the structure are the same. The data in JSON format comes through with no rank-identifying information, but I used numbers as examples here to show the strange results.
Original structure (masked):
{
"topNode: {
"childNode": {
"list": [
{
"title": "example title 1",
},
{
"title": "example title 2",
},
{
"title": "example title 3",
},
{
"title": "example title 4",
},
{
"title": "example title 5",
}
]
}
}
}
Example query (masked):
SELECT
A.VALUE:"title"::VARCHAR AS "TITLE",
ROW_NUMBER() OVER(ORDER BY NULL) AS RANK
FROM
DB.SCHEMA.TABLE as A,
lateral flatten(input=>A.JSON:topNode.childNode.list) "list_flatten"
Example output:
TITLE RANK
"example title 3" 1
"example title 5" 2
"example title 2" 3
"example title 1" 4
"example title 4" 5
It is possible with INDEX, which returns index of element in array:
SELECT A.VALUE:"title"::VARCHAR AS "TITLE",
"list_flatten".index AS "RANK"
FROM DB.SCHEMA.TABLE as A,
lateral flatten(input=>A.JSON:topNode.childNode.list) "list_flatten"
Im trying to find a way of returning the parent(s) in an array. I have tried pickBy and other solutions on stack but it either return the whole parent array, or nothing.
This is how my array looks like, and i want to find the parents based on tags.
{
'fraga': "Question 1",
'svar' : "This is this explanation",
'tags' : ['knowledge'],
},
{
'fraga': "Question 2",
'svar' : "This is this explanation for question 2",
'tags' : ['knowledge', 'code'],
},
So if i want the parents with tag knowledge i would get both "question 1" and "question 2", but if i want the parent with tags code i would only get "question 2".
I wrote a simple wrapper function in case you are calling it multiple times to search for multiple tags separateliy, but you could easily just use the Lodash code from within the function.
const arr = [
{
'fraga': "Question 1",
'svar' : "This is this explanation",
'tags' : ['knowledge'],
},
{
'fraga': "Question 2",
'svar' : "This is this explanation for question 2",
'tags' : ['knowledge', 'code'],
}
];
console.log(getByTag(arr, 'knowledge'));
console.log(getByTag(arr, 'code'));
function getByTag(objectArray, tagName) {
return _.filter(objectArray, (obj) => _.includes(obj.tags, tagName));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
I have followed the doc for the ReferenceArrayInput (https://marmelab.com/react-admin/Inputs.html#common-input-props) but it does not seem to be working with relationship fields.
For example, I have this many-to-many relation for my Users (serialized version) :
Coming from (raw response from my API):
I have setup the ReferenceArrayInput as followed :
<ReferenceArrayInput source="profiles" reference="profiles" >
<SelectArrayInput optionText="label" />
</ReferenceArrayInput>
I think it's making the appropriate calls :
But here is my result :
Any idea what I'm doing wrong ?
Thanks in advance for your help !
On docs, ReferenceArrayInput is said to expect a source prop pointing to an array os ids, array of primitive types, and not array of objects with id. Looks like you are already transforming your raw response from api, so if you could transform a bit more, mapping [{id}] to [id], it could work.
If other parts of your app expects profiles to be an array of objects, just create a new object entry like profilesIds or _profiles.
As gstvg said, ReferenceArrayInput expects an array of primitive type, not array of objects.
If your current record is like below:
{
"id": 1,
"tags": [
{ id: 'programming', name: 'Programming' },
{ id: 'lifestyle', name: 'Lifestyle' }
]
}
And you have a resource /tags, which returns all tags like:
[
{ id: 'programming', name: 'Programming' },
{ id: 'lifestyle', name: 'Lifestyle' },
{ id: 'photography', name: 'Photography' }
]
Then you can do something like this (it will select the tags of current record)
<ReferenceArrayInput
reference="tags"
source="tags"
parse={(value) => value && value.map((v) => ({ id: v }))}
format={(value) => value && value.map((v) => v.id)}
>
<AutocompleteArrayInput />
</ReferenceArrayInput>
it sure seems that there's no easy way to do this ... how can i ensure that certain fields in my multi match query going to actually be boosted correctly so that exact matches show up at the top?
i honestly seem to have tried this a multitude of ways, but maybe someone knows the answer ...
in my movie and music database, i'm trying to search multiple fields at once, but ensure that exact matches make it to the top and that certain fields such as title and artist name have more boost.
here's the main portion of my query...
"query": {
"bool": {
"should": [
{
"multi_match": {
"type": "phrase_prefix",
"query": "brave",
"max_expansions": 10,
"fields": [
"title^3",
"artists.name^2",
"starring.name^2",
"credits.name",
"tracks^0.1"
]
}
}
],
"minimum_number_should_match": 1
}
}
as you see, the query is 'brave'. it just so happens there's a movie called brave. perfect, i want it at the top - since not only is it an exact match, but the match is in the title. however, there's a popular song called 'brave' from sara bareilles which ends up on top. why?
i've tried every analyzer known to man, custom and otherwise, and i've tried changing the 'type' parameter to every other permutation (phrase, best_fields, cross_fields, most_fields), and it just doesn't seem to honor the fact that i'm effectively trying to either promote 'title' and 'artists.name' and 'starring.name' and DEMOTE 'tracks'.
is there any way i can ensure all exact matches show up at the top (especially in title, etc) followed by expansions, etc?
any suggestions would be helpful.
EDIT
the analyzer i'm currently using which seems to work better than others is a custom one i call 'nameAnalyzer' which is made up of a 'lowercase' filter and 'keyword' tokenizer only.
here's some example documents in the order in which they're appearing in the results:
fields": {
"title": [
"Brave"
],
"credits.name": [
"Kelly MacDonald",
"Emma Thompson",
"Billy Connolly",
"Julie Walters",
"Kevin McKidd",
"Craig Ferguson",
"Robbie Coltrane"
],
"starring.name": [
"Emma Thompson",
"Julie Walters",
"Billy Connolly",
"Kevin Mckidd",
"Kelly Macdonald"
]
,
fields": {
"credits.name": [
"Hilary Weeks",
"Scott Wiley",
"Sarah Sample",
"Debra Fotheringham",
"Dustin Christensen",
"Russ Dixon"
],
"title": [
"Say Love"
],
"artists.name": [
"Hilary Weeks"
],
"tracks": [
"Say Love",
"Another Second Chance",
"It's A Good Day",
"Brave",
"I Found Me",
"Hero",
"Tell Me",
"Where I Am",
"Better Promises",
"Even When"
]
,
fields": {
"title": [
"Brave Little Toaster"
],
"credits.name": [
"Randy Bennett",
"Jim Jackman",
"Randy Cook",
"Judy Toll",
"Jon Lovitz",
"Tim Stack",
"Timothy E. Day",
"Thurl Ravenscroft",
"Deanna Oliver",
"Phil Hartman",
"Jonathon Benair",
"Joe Ranft"
],
"starring.name": [
"Jon Lovitz",
"Thurl Ravenscroft",
"Tim Stack",
"Timothy E. Day",
"Deanna Oliver"
]
},
"fields": {
"title": [
"Braveheart"
],
"credits.name": [
"Bernard Horsfall",
"Martin Dempsey",
"James Robinson",
"Robert Paterson",
"Alan Tall",
"Rupert Vansittart",
"Donal Gibson",
"Malcolm Tierney",
"Sandy Nelson",
"Sean Lawlor"
],
"starring.name": [
"Brendan Gleeson",
"Sophie Marceau",
"Mel Gibson",
"Patrick Mcgoohan",
"Catherine Mccormack"
]
}
maybe someone knows why the second title ... (in this case not sara bareilles as i said before, but) Hillary Weeks - who has a track called 'brave' ... why is it before title 'braveheart' and 'brave little toaster'?
EDIT AGAIN
to further complicate the situation, what if i had a 'rank' field that was a part of my document? i'm finding it very difficult to add that to my _score field using a script score function...
"functions": [
{
"script_score": {
"script": "_score * 1/ doc['rank'].value"
}
}
]