Solr how to write a facet.query text field value - solr

I am thoroughly confused and lost due to being unable to know what to enter in this facet.query field when using Solr
I want to do a sum of all the documents that are returned, summing up this TotalPaxCount and AdultPaxCount values?
How can I do this using the GUI in the Solr web interface. The very limited examples seem to use curl requests and I have tried what they put in the facet.query and its constantly errors.

I managed to see what the original code was creating and then gave up trying to use the web UI interface! using curl I could make a call like this, in windows I had to put it all on one line like this:
curl http://localhost:8983/solr/mycore/query -d "{\"filter\": \"\",\"query\":\"ResortId:(229) AND ArrivalDate:[2022-10-24T00:00:00Z TO 2022-10-30T23:59:59Z] AND IsActive:True AND *:*\", \"limit\": 0,\"offset\": 0,\"fields\": \"\",\"facet\": {\"ResortId\": { \"type\": \"terms\",\"field\": \"ResortId\", \"limit\": -1, \"minCount\": 0, \"facet\": { \"Total\": \"sum(TotalCount)\", \"AdultCount\": \"sum(AdultCount)\", \"ChildCount\": \"sum(ChildCount)\", \"InfantCount\": \"sum(InfantCount)\" }}}}'
On a linux machine I believe you could do this curl command, which is more readable. I think this helps show the structure that is expect from solr, as was very confusing trying to understand the documentation.
curl http://localhost:8983/solr/mycore/query -d '
{
"filter": "",
"query": "ResortId:(229) AND ArrivalDate:[2022-10-24T00:00:00Z TO 2022-10-30T23:59:59Z] AND IsActive:True AND *:*",
"limit": 0,
"offset": 0,
"fields": "",
"facet": {
"ResortId": {
"type": "terms",
"field": "ResortId",
"limit": -1,
"minCount": 0,
"facet": {
"Total": "sum(TotalCount)",
"AdultCount": "sum(AdultCount)",
"ChildCount": "sum(ChildCount)",
"InfantCount": "sum(InfantCount)"
}
}
}
}'

Related

API URL Query to filter the response

So I'm trying to filter the response of my API GET query and can't seem to find a way to access deep enough in Json.
My response is like:
{
"orders": [
{
"id": "7e35583d-2309-4775-a993-d2277539da2f",
"updated_at": "2022-05-13T22:12:35.426Z",
"created_at": "2022-05-13T22:11:40.194Z",
"properties_attributes": {
"sublocacao": "Sim_Subloc"
},
"price_in_cents": 13500,
"grand_total_in_cents": 0,
"grand_total_with_tax_in_cents": 0,
"tax_in_cents": 0,
.
.
.
And I want to show only responses that have the properties_attributes": {"sublocacao": "Sim_Subloc"}. The others orders id's that doesn't have this property I don't want to show on the result.
I've tried:
https://apixxxxx.com/api/1/orders?sort=number_desc&statuses[]=reserved&properties_attributes=%7B%22sublocacao%22%3A%22Sim_Subloc%22%7D
Without avail.
There isn’t (at least on the documentation) an endpoint for this filter, so I'm trying to filter by myself.
Any hopes of getting it right?
thanks

How can you retrieve a full nested document in Solr?

In my instance of Solr 4.10.3 I would like to index JSONs with a nested structure.
Example:
{
"id": "myDoc",
"title": "myTitle"
"nestedDoc": {
"name": "test name"
"nestedAttribute": {
"attr1": "attr1Val"
}
}
}
I am able to store it correctly through the admin interface:
/solr/#/mySchema/documents
and I'm also able to search and retrieve the document.
The problem I'm facing is that when I get the response document from my Solr search, I cannot see the nested attributes. I only see:
{
"id": "myDoc",
"title": "myTitle"
}
Is there a way to include ALL the nested fields in the returned documents?
I tried with : "fl=[child parentFilter=title:myTitle]" but it's not working (ChildDocTransformerFactory from:https://cwiki.apache.org/confluence/display/solr/Transforming+Result+Documents). Is that the right way to do it or is there any other way?
I'm using: Solr 4.10.3!!!!!!
To get returned all the nested structure, you indeed need to use ChildDocTransformerFactor. However, you first need to properly index your documents.
If you just passed your structure as it is, Solr will index them as separate documents and won't know that they're actually connected. If you want to be able to correctly query nested documents, you'll have to pre-process your data structure as described in this post or try using (modifying as needed) a pre-processing script. Unfortunately, including the latest Solr 6.0, there's no nice and smooth solution on indexing and returning nested document structures, so everything is done through "workarounds".
Particularly in your case, you'll need to transform your document structure into this:
{
"type": "parentDoc",
"id": "myDoc",
"title": "myTitle"
"_childDocuments_": [
{
"type": "nestedDoc",
"name": "test name",
"_childDocuments_" :[
{
"type": "nestedAttribute"
"attr1": "attr1Val"
}]
}]
}
Then, the following ChildDocTransformerFactor query will return you all subdocuments (btw, although it says it's available since Solr 4.9, I've actually only seen it in Solr 5.3... so you need to test):
q=title:myTitle&fl=*,[child parentFilter=type:parentDoc limit=50]
Note, although it returns all nested documents, the returned document structure will be flattend (alas!), i.e., you'll get:
{
"type": "parentDoc",
"id": "myDoc",
"title": "myTitle"
"_childDocuments_": [
{
"type": "nestedDoc",
"name": "test name"
},
{
"type": "nestedAttribute"
"attr1": "attr1Val"
}]
}
Probably, not really what you've expected but... this is the unfortunate Solr's behavior that will be fixed in a nearest future release.
You can put
q={!parent which=}
and in fl field :"fl=*,[child parentFilter=title:myTitle].
It will give you all parent field and children field of title:mytitle

Highlight matches in MongoDB full text search

Is it possible to define which part of the text in which of the indexed text fields matches the query?
No, as far as I know and can tell from the Jira, no such feature exists currently. You can, of course, attempt to highlight the parts of the text yourself, but that requires to implement the highlighting and also implement the stemming according to the rules applied by MongoDB.
The whole feature is somewhat complicated - even consuming it - as can be seen from the respective elasticsearch documentation.
Refer to Mongodb Doc Highlighting
db.fruit.aggregate([
{
$searchBeta: {
"search": {
"path": "description",
"query": ["variety", "bunch"]
},
"highlight": {
"path": "description"
}
}
},
{
$project: {
"description": 1,
"_id": 0,
"highlights": { "$meta": "searchHighlights" }
}
}
])
I'm afraid that solution applies only to MongoDB Atlas at the moment #LF00.

Google Translate get synonyms and examples

Can I access word's synonyms and examples along with the translation itself, when using Google Translate API?
I checked out docs but I don't see anything like that.
No, you cannot get the synonyms and examples along with the translated text.As currently they have only 3 methods in the Translate API.The 3 methods are detections.list, languages.list and translations.list. So i think it would be great if you make a feature request for this API at PIT of AppEngine.
Pearson released their free API which includes examples, part of speech, and synonyms. Check it out: http://developer.pearson.com/apis/dictionaries
http://api.pearson.com/v2/dictionaries/lase%20/entries?headword=hola
{
"status": 200,
"offset": 0,
"limit": 10,
"count": 1,
"total": 1,
"url": "/v2/dictionaries/lase /entries?headword=hola",
"results": [
{
"datasets": [
"lase",
"dictionary"
],
"headword": "hola",
"id": "ct59rx0q97",
"part_of_speech": "interjection",
"senses": [

Solr, adding a record via JSON with a multi-value field and boosted values

I'm pretty new to Solr, I'm trying to add a multi-value field with boost values defined for each value, all defined via JSON. In other words, I'd like this to work:
[{ "id": "ID1000",
"tag": [
{ "boost": 1, "value": "A test value" },
{ "boost": 2, "value": "A boosted value" } ]
}]
I know how to do that in XML (multiple <field name = 'tag' boost = '...'>), but the JSON code above doesn't work, the server says "Error parsing JSON field value. Unexpected OBJECT_START". Has Solr a limit/bug?
PS: I fixed the originally-missing ']' and that's not the problem.
EDIT: It seems the way to go should be payloads (http://wiki.apache.org/solr/Payloads), but I couldn't make them to work on Solr (followed this: http://sujitpal.blogspot.co.uk/2011/01/payloads-with-solr.html). Leaving the question open to see if someone can further help.
Found the following sentence in the from the Solr Relevancy FAQ - Query Elevation Component section
An Index-time boost on a value of a multiValued field applies to all values for that field.
I do not think adding an individual boost to each value in the multivalued field is going to work. I know that the Xml will allow it, but I would guess that it may only apply the boost value from the last value applied to the field.
So based on that I would change the Json to the following and see if that works.
[
{
"id": "ID1000",
"tag": {
"boost": 2,
"value": [ "A test value", "A boosted value"]
}
}
]
The JSON seems to be invalid missing a closing ]
[
{
"id": "ID1000",
"tag": [
{
"boost": 1,
"value": "A test value"
},
{
"boost": 2,
"value": "A boosted value"
}
]
}
]
You hit an edge case. You can have the boosts on single values and you can have an array of values. But not one inside another (from my reading of Solr 4.1 source code)
That might be something to create as an enhancement request.
If you are generating that JSON by hand, you can try:
"tag": { "boost": 1, "value": "A test value" },
"tag": { "boost": 2, "value": "A boosted value" }
I believe Sols will merge the values then. But if you are generating it via a framework, it will most likely disallow or override multiple object property names (tag here).
The error has nothing to do with boosting.
I get the same error with a very simple json doc.
No luck solving it.
see Solr errors when trying to parse a collection: Error parsing JSON field value. Unexp ected OBJECT_START
I hit the same error message. Actually the error message was misplaced. The underlying real error was the two of the required fields as per schema.xml in solr configuration were missing in the json payload.
An error message of the kind "required parameters are missing in the document" would have been more helpful here. You might want to check if some required fields are missing in the json payload.

Resources