Sort child documents - solr

In Solr, how can I sort the child documents by score? As I tested, it seems to be only possible to sort the documents and not the child documents that are retrieved inside the parent document.
I have the following document:
{
"id": 0,
"type": "parent",
"name": "Arnold",
"_childDocuments_": [
{
"id": 1,
"type": "child",
"field": "foo bar"
},
{
"id": 2,
"type": "child",
"field": "foo baz"
},
{
"id": 3,
"type": "child",
"field": "bar baz"
},
{
"id": 4,
"type": "child",
"field": "foobar baz bar"
}
]
}
Now I want to filter by foo baz. I'm using:
q= {!parent which=type:parent}
fl= *, [child parentFilter=type:parent childFilter="field:foo OR field:baz"]
score= score desc
Since ID 2 is foo baz, I would expect to see this one as the first child document retrieved, but I'm seeing ID 1 foo bar as the first one because ID 1 was the first one to be inserted.

Instead of using the [child] transformer, you can use the [subquery] transformer.
q= {!parent which=type:parent}
fl= *, my_childs:[subquery]&my_childs.q=field:foo OR field:baz&my_childs.fl=*, score
Results in:
"response": {
"numFound": 1,
"start": 0,
"docs": [
{
"id":"0",
"type": ["parent"],
"name": ["Arnold"],
"_version_": 1603334242311340032,
"name_str": ["Arnold"],
"type_str": ["parent"],
"my_childs": {
"numFound": 4,
"start": 0,
"docs":[
{
"id": "2",
"type": ["child"],
"field": ["foo baz"],
"field_str": ["foo baz"],
"_version_": 1603334242311340032,
"type_str": ["child"],
"score": 1.0998137
},
{
"id": "1",
"type": ["child"],
"field": ["foo bar"],
"field_str": ["foo bar"],
"_version_": 1603334242311340032,
"type_str": ["child"],
"score": 0.7261542
},
{
"id": "3",
"type": ["child"],
"field": ["bar baz"],
"field_str": ["bar baz"],
"_version_": 1603334242311340032,
"type_str": ["child"],
"score": 0.3736595
},
{
"id": "4",
"type": ["child"],
"field": ["foobar baz bar"],
"field_str": ["foobar baz bar"],
"_version_": 1603334242311340032,
"type_str": ["child"],
"score": 0.31387395
}
]
}
}
]
}

Related

Rdflib and activitystreams

so I'm investigating rdflib to use with ActivityStreams. My current main goal is to input an Object and get the same one back!
My current try looks like this
import rdflib
G = rdflib.Graph()
G.parse('https://raw.githubusercontent.com/HelgeKrueger/bovine/main/tests/data/mastodon_announce_1_undo.json', format='json-ld')
print(G.serialize(format='json-ld',
auto_compact=False,
use_native_types=True,
context="https://www.w3.org/ns/activitystreams",
base="https://my_domain/activitypub/user/3c0281b7-bede-460a-a49b-3b6d7d4eb32f/activity"))
and gets the output
{
"#context": "https://www.w3.org/ns/activitystreams",
"#graph": [
{
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": "https://first_domain/users/first/statuses/1097854/activity",
"to": "as:Public",
"type": "Undo"
},
{
"actor": "https://first_domain/users/john",
"cc": [
"https://first_domain/users/john/followers",
"https://second_domain/users/second"
],
"id": "https://first_domain/users/first/statuses/1097854/activity",
"object": "https://second_domain/users/second/statuses/109724234853",
"published": "2023-01-31T19:11:46+00:00",
"to": "as:Public",
"type": "Announce"
}
]
}
The signature is missing, because it's not part of the namespace -> This is as desired.
Unfortunately, there is the #graph property and the "Announce" is not represented as a subobject of
{
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": "https://first_domain/users/first/statuses/1097854/activity",
"to": "as:Public",
"type": "Undo"
}
Is there a way to get rdflib to ouput it like:
{
"#context": "https://www.w3.org/ns/activitystreams",
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": {
"actor": "https://first_domain/users/john",
"cc": [
"https://first_domain/users/john/followers",
"https://second_domain/users/second"
],
"id": "https://first_domain/users/first/statuses/1097854/activity",
"object": "https://second_domain/users/second/statuses/109724234853",
"published": "2023-01-31T19:11:46+00:00",
"to": "as:Public",
"type": "Announce"
},
"to": "as:Public",
"type": "Undo"
}
Thanks!

React Read a Apollo query Result (complex Array)

I've a little problem, fetch query over react to Graphql work.
But when I ask a complex query, I receive this answer :
How I can read all variable but not the variable in the "operation":
Name
ID
How I can read this 2 Variables ?
[
{
"__typename": "Journal",
"id": "1",
"name": "Journal1",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "1",
"name": "Oper1OnlyName"
}
},
{
"__typename": "Journal",
"id": "2",
"name": "Default",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "15",
"name": "Oper15ID"
}
},
{
"__typename": "Journal",
"id": "3",
"name": "Nachrichten",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "15",
"name": "Oper15ID"
}
},
{
"__typename": "Journal",
"id": "4",
"name": "WEMA",
"state": "ACTIVE",
"operation": null
},

How to sort parent document by child documents lowest price in solr

I am new in solr i want to sort parent document by child documents lowest price . Please see below mentioned sample data.
{
"parentID": 1,
"children": {
"numFound": 2,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 1,
"ID": "1",
"price": 189.7
},
{
"type": "child",
"parentID": 1,
"ID": "2",
"price": 933.1
}
]
} }, {
"parentID": 2,
"children": {
"numFound": 2,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 2,
"ID": "1",
"price": 1180.0
},
{
"type": "child",
"parentID": 2,
"ID": "2",
"price": 238.0
}
]
} }, {
"parentID": 3,
"children": {
"numFound": 1,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 3,
"ID": "1",
"price": 1442.81,
},
{
"type": "child",
"parentID": 3,
"ID": "2",
"price": 42.81,
}
]
} }, {
"parentID": 4,
"children": {
"numFound": 1,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 4,
"ID": "1",
"price": 1140.8,
}
]
} }
And i want to result below mentioned format
{
"parentID": 3,
"children": {
"numFound": 1,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 3,
"ID": "1",
"price": 1442.81,
},
{
"type": "child",
"parentID": 3,
"ID": "2",
"price": 42.81,
}
]
}
},
{
"parentID": 1,
"children": {
"numFound": 2,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 1,
"ID": "1",
"price": 189.7
},
{
"type": "child",
"parentID": 1,
"ID": "2",
"price": 933.1
}
]
}
},
{
"parentID": 2,
"children": {
"numFound": 2,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 2,
"ID": "2",
"price": 238.0
},
{
"type": "child",
"parentID": 2,
"ID": "1",
"price": 1180.0
}
]
}
},
{
"parentID": 4,
"children": {
"numFound": 1,
"start": 0,
"docs": [
{
"type": "child",
"parentID": 4,
"ID": "1",
"price": 1140.8,
}
]
}
}
I tried below mentioned link it's not worked for my issue.
how to sort parent documents by child attributes in solr
sort={!parent which=type:parent score=max v=’+type:child +{!func}price’} desc

Boost solr results based on a field value

I am new to solr and trying to fetch results from it. I want results which exactly matches my phrase ex: "test test1 test2" and any document which has any of these keywords, so kind of union of exact match and partial matches.
I am pretty much achieving it using dismax. Now i want the results to be sorted/boosted on the basis of some field value eg: cat:A, then cat:B then cat:C also I want this sorting to be applied first on exactly matched result then partial matched results.
Indexed data is:
[
{
"id": "001",
"name": "test test1 test2 Z",
"price": 12.9,
"cat": "A"
},
{
"id": "002",
"name": "test test1 test2 X",
"price": 91.5,
"cat": "B"
},
{
"id": "003",
"name": "test test1 test2 R",
"price": 45.5,
"cat": "C"
},
{
"id": "004",
"name": "test test1 test2 C",
"price": 78.67,
"cat": "B"
},
{
"id": "005",
"name": "data",
"price": 91.5,
"cat": "A"
},
{
"id": "008",
"name": "test test1 test2 D",
"price": 45.09,
"cat": "A"
},
{
"id": "009",
"name": "test test1 test2 B",
"price": 34.09,
"cat": "B"
},
{
"id": "010",
"name": "test test1 test2 A",
"price": 39.19,
"cat": "C"
},
{
"id": "011",
"name": "test this data",
"price": 89.19,
"cat": "A"
},
{
"id": "012",
"name": "this is my data",
"price": 89.19,
"cat": "C"
},
{
"id": "013",
"name": "test1 is this data title",
"price": 89.19,
"cat": "A"
}
]
Please help.Thanks in advance.

Json schema for array of objects doesn't validate

I have this schema for a json response
{
"title": "Products",
"description": "schema for products",
"type": "array",
"properties": {
"id": {
"description": "id of a product",
"type": "integer"
},
"name": {
"description": "name of the product",
"type": "string"
},
"created_at": {
"description": "record created_at",
"type": "string",
"format": "date-time"
},
"updated_at": {
"description": "record updated_at",
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name"]
}
and I want to match this schema with this json
[{
"id": 1,
"name": "Cricket Ball"
}, {
"id": 2,
"name": "Soccer Ball"
}, {
"id": 3,
"name": "football ball"
}, {
"id": 4,
"name": "Basketball ball"
}, {
"id": 5,
"name": "Table Tennis ball"
}, {
"id": 6,
"name": "Tennis ball"
}]
This schema matches the response but it also matches the schema in which the required field is this
"required": ["ids", "names"]
I think the schema is validated against the array and the objects in the array are not validated.
The way you have it set up now, your properties key refers to the array itself, not to each item, and is being ignored (because arrays don't have properties, they just have items). You need to use the items key to validate each item in the array, like so:
{
"title": "Products",
"description": "schema for products",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"description": "id of a product",
"type": "integer"
},
"name": {
"description": "name of the product",
"type": "string"
},
"created_at": {
"description": "record created_at",
"type": "string",
"format": "date-time"
},
"updated_at": {
"description": "record updated_at",
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name"]
}
}
try map
new_array = response.map{ |k| { 'id': k['properties']['id']['description'], 'name': k['properties']['name']['description'] } }

Resources