And operator doesnt appear to work - azure-cognitive-search

I must be missing something,
my search includes the string long+beach so I expect results to only contain entries where (in this case) the location field contains both long and beach.
/indexes/person2/docs?$count=true&$top=100&search=long+beach&searchFields=location
plus
api-version=2014-07-31-Preview
the image I dont have rep to post shows miami beach, florida among others.
I tried setting &searchMode=any with no change.
the column looks like this
new { Name = "location",
Type = "Edm.String",
Key = false,
Searchable = true,
Filterable = true,
Sortable = true,
Facetable = true,
Retrievable = true,
Suggestions = true },
my bad?

Most likely this is an escaping issue. "+" is treated as a space character in most cases by code that handles URL encoding. "+" shouldn't show up literally in the URL but encoded as %2B. More in general, you should escape the search string before adding it to the search= parameter. Most languages have a built-in URL encoding primitive that will do this for you (e.g. Uri.EncodeDataString() in .NET)

I was having the same issue. %2B worked for me as well. I think I was thrown off by this page of the Azure Search documentation where it describes the simple query syntax that can be used to refine the search.
https://msdn.microsoft.com/en-us/library/azure/dn798920.aspx
It seems that the simple query syntax is what you would put in the search input box, not what you would send to the API.
Here's an example from my project:
search=Aberdeen%2Bdistrict (2 results)
search=Aberdeen+district (156 results)

Related

Using Spring-Data/MongoDB findBy/IsFalse with reserved keyword

I have a structure that looks kind of like this:
{
'foo': 'bar',
'isBaz': false
}
and the following Repository code
repository.findByIsBazIsFalse();
I figured that would only return records where isBaz is false, but it's also returning records where isBaz is set to true. My initial guess is that the field starts with the word 'is' which is a reserved keyword in the spring/mongo query.
FWIW I also tried via annotation but no luck
#Query("{isBaz:false}")
Does anyone know how to make it work without renaming the variable to 'baz'?
Make sure this field is defined as boolean and it should work!
private boolean isBaz;
repository.findByIsBazIsFalse();
[main] o.m.d.p.c :Sending command '{"find": "collection", "filter": {"isBaz": false}, ...}'

Azure search highlight not working if the sentence has special character

Team,
I am using below sample azure search query
`{azuresearchurl}/docs?api-version=2019-05-06?search=examples&highlight=title&$select=title
I am getting below response.
"#search.highlights": {
"title": [
": From <em>Examples</em> of our Projects"
]
},
"title": "Can we execute? : From Examples of our Projects"
}
In the above result, we can see text before '?' not added in highlight field value.
How to fix this issue. in highlight field I need to get same text which is available in search result field.
The highlight feature only returns the fragment of text where the searched term is found. Those fragments are generated by finding sentence boundaries. In this case, the interrogation mark indicates the end of a different sentence, so it's not included in the fragment.

Using search.in with all

Follwing statement find all profiles that has Facebook or twitter and this works:
$filter=SocialAccounts/any(x: search.in(x, 'Facebook,Twitter'))
But I cant find any samples for finding all that has both Facebook and twitter. I tried:
$filter=SocialAccounts/all(x: search.in(x, 'Facebook,Twitter'))
But this is not valid query.
Azure Search does not support the type of ‘all’ filter that you’re looking for. Using search.in with ‘all’ would be equivalent to using OR, but Azure Search can only handle AND in the body of an ‘all’ lambda (which is equivalent to OR in the body of an ‘any’ lambda).
You might try a workaround like this:
$filter=tags/any(t: t eq 'Facebook') and tags/any(t: t eq 'Twitter')
However, this isn't actually equivalent to using all with search.in. The query as expressed using all is matching documents where every social account is strictly either Facebook or Twitter. If any other social account is present, the document won’t match. The workaround doesn’t have this property. A document must have at least Facebook and Twitter in order to match, but not exclusively those. This is certainly a valid scenario; it just isn't the same as using all with search.in, which was the original question.
No matter how you try to rewrite the query, you won’t be able to express an equivalent to the all query. This is a limitation due to the way Azure Search stores collections of strings and other primitive types in the inverted index.
Please vote on user voice to help prioritize:
https://feedback.azure.com/forums/263029-azure-search/suggestions/37166749-efficient-way-to-express-a-true-all
A possible workaround is to use the new Complex Types feature, which does allow more expressive filters inside lambda expressions. For example, if you model tags as objects with a single value property instead of as a collection of strings, you should be able to execute a filter like this:
$filter=tags/all(t: search.in(t/value, 'Facebook,Twitter'))
In the REST API, you'd define tags like this:
{
"name": "myindex",
"fields": [
...
{
"name": "tags",
"type": "Collection(Edm.ComplexType)",
"fields": [
{ "name": "value", "type": "Edm.String", "filterable": true }
]
}
]
}
Note that this feature is in preview at the time of this writing, but will be generally available (and publicly documented) soon.

Salesforce Custom Object Relationship Creation

I want to create two objects and link them via a parent child relationship in C# using the Metadata API.
I can create objects and 'custom' fields for the objects via the metadata, but the service just ignores the field def for the relationship.
By snipet for the fields are as follows:
CustomField[] fields = new CustomField[] { new CustomField()
{
type = FieldType.Text,
label = "FirstName",
length = 50,
lengthSpecified = true,
fullName = "LJUTestObject__c.FirstName__c"
},
new CustomField()
{
type = FieldType.Text,
label = "LastName",
length = 50,
lengthSpecified = true,
fullName = "LJUTestObject__c.Lastname__c"
},
new CustomField()
{
type = FieldType.Text,
label = "Postcode",
length = 50,
lengthSpecified = true,
fullName = "LJUTestChildObject__c.Postcode__c"
},
new CustomField()
{
type = FieldType.MasterDetail,
relationshipLabel = "PostcodeLookup",
relationshipName = "LJUTestObject__c.LJUTestObject_Id__c",
relationshipOrder = 0,
relationshipOrderSpecified = true,
fullName = "LJUTestChildObject__c.Lookup__r"
}
};
The parent object looks like:
LJUTestObject
ID,
FirstName, Text(50)
LastName, Text(50)
The child objext looks like:
LJUTestChildObject
ID,
Postcode, Text(50)
I want to link the parent to the child so one "LJUTestObject", can have many "LJUTestChildObjects".
What values do I need for FieldType, RelationshipName, and RelationshipOrder to make this happen?
TL;DR:
Use this as a template for accomplishing what you want:
var cf = new CustomField();
cf.fullName = "ChildCustomObject__c.ParentCustomField__c";
cf.type = FieldType.MasterDetail;
cf.typeSpecified = true;
cf.label = "Parent Or Whatever You Want This To Be Called In The UI";
cf.referenceTo = "ParentCustomObject__c";
cf.relationshipName = "ParentOrWhateverYouWantThisToBeCalledInternally";
cf.relationshipLabel = "This is an optional label";
var aUpsertResponse = smc.upsertMetadata(metadataSession, null, null, new Metadata[] { cf });
The key difference:
The natural temptation is to put the CustomField instances into the fields array of a CustomObject, and pass that CustomObject to the Salesforce Metadata API. And this does work for most data fields, but it seems that it does not work for relationship fields.
Instead, pass the CustomField directly to the Salesforce Metadata API, not wrapped in a CustomObject.
Those muted errors:
Turns out that errors are occurring, and the Salesforce Metadata API knows about them, but doesn't bother telling you about them when they occur for CustomFields nested inside a CustomObject.
By passing the CustomField directly to the Metadata API (not wrapped in a CustomObject), the call to upsertMetadata will still return without an exception being thrown (as it was already doing for you), but this time, if something goes wrong, upsertResponse[0].success will be false instead of true, and upsertResponse[0].errors will give you more information.
Other gotchas
Must specify referenceTo, and if it doesn't match the name of an existing built-in or custom object, the error message will be the same as if you had not specified referenceTo at all.
fullName should end in __c not __r. __r is for relationship names, but remember that fullName is specifying the field name, not the relationship name.
relationshipName - I got it working by not including __r on the end, and not including the custom object name at the start. I haven't tested to be sure other ways don't work, but be aware that at the very least, you don't need to have those extra components in the relationshipName.
Remember generally that anything with label in its name is probably for display to users in the UI, and thus can have spaces in it to be nicely formatted the way users expect.
Salesforce... really???
(mini rant warning)
The Salesforce Metadata API is unintuitive and poorly documented. That's why you got stuck on such a simple thing. That's why no-one knew the answer to your question. That's why, four years later, I got stuck on the same thing. Creating relationships is one of the main things you would want to do with the Salesforce Metadata API, and yet it has been this difficult to figure out, for this long. C'mon Salesforce, we know you're a sales company more than a tech company, but you earn trazillions of dollars and are happy to show it off - invest a little more in a better API experience for the developers who invest in learning your platform.
I've not created these through the meta data API like this myself, but I'd suggest that:
relationshipName = "LJUTestObject__c.LJUTestObject_Id__c
Should be:
relationshipName = "LJUTestObject__c.Id
as Id is a standard field, the __c suffix is only used for custom fields (not standard fields on custom objects). Also, it may be that the relationship full name should end in __c not __r, but try the change above first and see how you go.
SELECT
Id,
OwnerId,
WhatId,
Reminder_Date_Time__c,
WhoId,
Record_Type_Name__c,
Task_Type__c,
Assigned_Date__c,
Task_Status__c,
ActivityDate,
Subject,
Attended_By__c,
Is_Assigned__c
FROM Task
WHERE
(NOT Task_Status__c LIKE 'Open') AND
ActivityDate >= 2017-12-13 AND
(NOT Service__r.Service_State__c LIKE 'Karnataka')

Django admin: Format fields in list, but keep sortable?

I keep numeric fields like "size", "width", "height" in my database. Now I would attach units like "KiB" or "pixels" to them when showing them in the change list. This could easily be achieved by adding callables such as "size_formatted" etc to list_display. However, these are no longer sortable.
Is there a way around this limitation?
Read here - ModelAdmin.list_display (read a lot to get to the point ;) )
you need to add admin_order_field attribute to your function
class YourAdminCLass(admin.ModelAdmin)
[...]
def size_formatted(self, obj):
return "whatever you need"
size_formatted.admin_order_field = 'size'

Resources