Azure Search contain - azure-cognitive-search

Im using azure search on my project,
This is information in the search field:
Document:{
field_name1: "this is the first value, new value",
field_name2: "My Name"
}
Now, I put the search term "new value" in field_name1 on search method:
"(field_name1:/.*new value.*/)"
But nothing to return.
So anyone could help me?

Your code looks fine and it should work. Make Sure
your Search Parameter should have SearchMode.Any and QueryType.Full as mentioned below.
SearchParameters()
{
SearchMode = SearchMode.Any,
QueryType = QueryType.Full
};

Related

How to respect Solr conditions in order

I need to send a query to Solr with two conditions in OR, instead of sending the query twice:
{!complexphrase inOrder=true}title:"some tests*" || title:(some tests*)
.. where, in the first condition, I want the precise result. If not found, then it goes to OR and retrieves any result that has at least one word in the search phrase. But when I launch the query, I still get the right condition results first.
Here is my data:
{
"title": "some values"
},
{
"title": "data tests"
},
{
"title": "some tests"
}
The response I need is:
{
"title": "some tests"
},
{
"title": "data tests"
},
{
"title": "some values"
}
I already tried using boosting, like so: {!complexphrase inOrder=true}title:"some tests*"^2 || title:(some tests*)^1 but didn't work. I am NOT able to change the Solr configuration since it's a software that's already in production and not managed by me. I even cannot sort by rating, infact I don't receive best occurences first. Solr version is 7.3.1. Any help is appreciated, thanks in advance!
I solved it with a work-around. Instead of putting two OR conditions, I managed to apply a working boost on the title field, using edismax.
What I had to change in my Java application was:
From
SolrQuery q = new SolrQuery("*");
To
SolrQuery q = new SolrQuery("(" + query + "*)");
and added:
q.set("defType", "edismax");
q.set("qf", "title^100");
Now, I'm not making a precise query but I'm retrieving documents with a higher match first without changing any configuration! The Solr Frontend equivalent is similar, but the query should look like this:
http://localhost:8983/solr/mycollection/select?defType=edismax&q=(some%20test*)&qf=title^100
Hope it helps someone

How to find the API name of field from an label of field from a particular sobject?

How to find the API name of field from an label of field from a particular sobject.
This was pretty bad to find the field api name in salesforce, It is an indeed a trivial question which many of developer folks find out tough while working on projects.
Putting here as an code snippet for searching easily.
Here's the code snippet to find out the api name of the field based on the label of an object.
public static String getMyAPIName(String objectName, String fieldLabel ) {
SObjectType type = Schema.getGlobalDescribe().get(objectName);
Map<String,Schema.SObjectField> mfields = type.getDescribe().fields.getMap();
for(String strField : mfields.keySet())
{
SObjectField fl = mfields.get(strField);
if(fieldLabel == fl.getDescribe().getlabel())
{
return strField;
}
}
return '';
}
SELECT EntityDefinition.QualifiedApiName, QualifiedApiName, Label
FROM FieldDefinition
WHERE EntityDefinition.QualifiedApiName = 'Account' AND Label = 'Parent Account'
outputs "ParentId" just fine, no describes and loops

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.

?members command for my discord bot - discord.js

So I've been trying to create a ?members command which lists all the users with a role.
So far I've got this:
if (message.content.startsWith("?members")) {
let roleName = message.content.split(" ").slice(1).join(" ");
let membersWithRole = message.guild.members.filter(member => {
return member.roles.find("name", roleName);
}).map(member => {
return member.user.username;
})
const embed = new Discord.RichEmbed({
"title": `Members in ${roleName}`,
"description": membersWithRole.join("\n"),
"color": 0xFFFF
});
return message.channel.send(embed);
}
So, it works if you type the exact name of the role, but not when you ping it or type the first word. I've been trying for hours to figure out how to do it, and I figured I should ask for help.
Thanks in advance!
Pings get translated into a code as they come through, there is a lot of information on how to parse them in the official guide After it's parsed into a role id you can just use members.roles.get() because that is what they are indexed by.
As for finding a partial name, for that you are going to have to run a function on your find and use String.includes.
return member.roles.find(role => role.name.includes(roleName));
This will also work for find the whole name of course, so it can replace your existing line.
However, this may result in more than one role. This is also true for searching by the entire role name, however, as there are no restrictions on duplicate named roles. For this you may want to invert you design and search through message.guild.roles first for any matching roles, then search for members with the roles found.

Referencing arrays that are nested within multiple objects within MongoDB with Express js

So in my MongoDB Collection I have this structure:
"_id" : "Object("-----------")
"name" : "John Doe"
"tool" : {
"hammer" : {
"name" : "hammer 1",
"characteristics" : [
{
"length" : "9 inches"
},
{
"weight" : "4 pounds"
}
]
I know the data may seem a little strange but I can't put the actual data online so I had to input some dummy data. So essentially what I would like to do is be able to update the array that is nested within those objects. So I would like to be able to update the weight or add a new characteristic that I haven't previously entered into it. So for example, add in "metal" : "steel" as a new entry into the array. Currently I'm using a Rest API built in Node.js and Express.js to edit the db. When I was trying to figure out how to dig down this deep I was able to do it with an array at the highest level, however I haven't been able to figure out how to access an array when its embedded like this. So what I was wondering if anybody knew if it was even possible to edit an array this far down? I can post code from controller.js and server.js file if needed but I figured I'd see if it's even possible to do before I start posting it. Any help would be greatly appreciated!
You can use findAndModify to $push it into the array. You have to specify the path precisely though:
db.tools.findAndModify( {
query: { name: "John Doe"},
update: { $push: { tool.hammer.characteristics: {metal: "steel"} }
} );

Resources