How to access fields with special characters from _source? - reactjs

I am creating a search application in React using searchkit. Some of the fields in my _source have special characters in the beginning, like _index or #timestamp. I am not able to access those fields using source._index, the way I can access fields without special characters, like source.Body.
My sourceFilter looks like this:
sourceFilter={["#timestamp", "From", "MessageStatus", "SmsStatus", "To", "Message", "Timestamp", "Body", "_index"]}
I am trying to access the fields to set the html using dangerouslySetInnerHtml.
How can I either change what the field is called or access a field with a special character?

In the end, I created a new field in the elasticsearch index with a name that doesn't have special characters.

Related

Find documents through embedded documents in MongoDB using an array of strings?

I am currently practicing MongoDB by building a site powered by it. The db has 5 collections and uses cross-references, either through objectid references or through a hybrid objectid-embedded document system. Mostly things have went very smoothly.
Now, I am trying to build an advanced search function. One field lets you insert multiple strings, separated by commas. In the backend, these will be separated into an array. The objects that are being searched all have an array field which normally contains one or more embedded documents. All of these embedded documents have an objectid reference and a "title" property. This query array I mentioned lets users search for multiple of this title entries, and I want to return all objects that contains the embedded documents with "title" properties all matching the array, so if you search for "X,Y" and there are a document with two embedded documents with the title properties "X" respective "Y" they will be returned, whereas if only of those embedded documents is present, that document will be ignored. The document structure looks like this:
{
"_id":"5dfcd95fe9d81c32437ba3fb",
"usedBy":[
{
"_id":"5ddaf35f51528c0881e84507",
"title":"X"
},
{
"_id":"5e00b2c04facc56b40930eac",
"title":"Y"
}
],
//more properties follow...
}
So far however, without success. I have tried a few methods, like $in and $elemMatch, but they don't seem to do what I want to have them do. Which method would you suggest? Right now, I tried to converted the array of strings to an array of objects, which in turn are passed to a filter object for the "find"-method:
if(usedBy){
usedBy = usedBy.split("%5C%2C%2");
for(var i=0; i<usedBy.length; i++){
usedBy[i] = {title: usedBy[i]};
}
filter.usedBy = usedBy;
}
Thanks.
You need to filter by subfield usedBy.title
var titles = usedBy.split(",");
db.collection.find({"usedBy.title":{$in: titles}});

Azure Search Define Custom Analyzer

I'm defining the Index schema. One of the field is "InvoiceNumber" which it can be something like "459" or "00459" or "P00459".
I want the text "00459" while indexing tokenize to 2 tokens "459" and the original "00459".
And the text "P00459", tokenize to 3 tokens "459", "00459" and the original "P00459".
Is there a way to define the custom analyzer for this?
configuring pattern_capture token filter with appropriate regex is able to produce multiple tokens based on the same text while preserving the original text.
https://learn.microsoft.com/en-us/azure/search/index-add-custom-analyzers
https://lucene.apache.org/core/4_10_3/analyzers-common/org/apache/lucene/analysis/pattern/PatternCaptureGroupTokenFilter.html
This is the example from the latter link
"(https?://([a-zA-Z-_0-9.]+))" when matched against the string "http://www.foo.com/index" would return the tokens "https://www.foo.com" and "www.foo.com".

URL Type Hierarchy in Adobe DTM

I'm trying to create a page type hierarchy where I can use it both a page hierarchy as well as props and evars, using the page URL. In a nutshell my URL would look something like this:
http://www.domain.com/BrandHomePage/SuperCategory/ProductCategory/Product
The mindset is to take the URL and use a data element to split the URL, and then capture the values into separate data elements that could also be used in a page hierarchy.
var url = "http://www.domain.com/part1/part2/part3/part4"
var parts = url.split('/').splice(2);
console.log(parts);
var baseUrl = parts[0];
var part1 = parts[1];
var part2 = parts[2];
var part3 = parts[3];
var part4 = parts[4]
My question is, would it even be possible to capture each individual portion of the URL into separate data elements? Or is my approach overkill.
Create a Data Element
The following will create a Data Element that returns an array containing up to 4 elements, depending on how many dir levels there are in the URL.
Go to Rules > Data Elements > Create New Data Element
Name it "hier1" (no quotes).
Choose Type Custom Script and click Open Editor.
Add the following code to the code box:
return location.pathname.split('/').filter(Boolean).slice(0,4);
When you are done, Save Changes.
Populate the Hierarchy Variable
Here is an example of populating hier1 on page view.
Go to Overview > Adobe Analytics Tool Config > Pageviews & Content
Under Hierarchy, select Hierarchy1 from the dropdown (this is shown by default).
To the right of the dropdown, in the first field, add %hier1%
Leave the other 3 fields blank.
Leave Delimiter as default comma , (it doesn't matter what you put here).
Note: DTM stringifies the returned array (String(Array) or Array.toString()) from the Data Element, which is effectively the same as doing Array.join(','). This is why the above shows to only put the Data Element reference in the first field, and the Delimiter is ignored.
If your implementation uses a delimiter other than a comma, see additional notes below.
Additional Notes
Populating other Variables
You can also reference %hier1% to populate other variable fields in the Global Variables section. Note that the data element will be stringified with default comma delimiter.
Alternatively, you may consider using Dynamic Variable syntax (e.g. D=h1) as the value, to shorten the request URL. If you are using the latest AppMeasurement and Marketing Cloud Service libraries, this isn't a big deal (the libs will automatically use a POST request instead of GET request if the request URL is too long).
Using the Data Element in Custom Code Boxes
You can use _satellite.getVar('hier1') to return the data element. Note that this returns an array, e.g. ['foo','bar'], so you need to use .join() to concatenate to a single delimited string value.
Using a different Delimiter
If your implementation uses a delimiter other than a comma (,) and you use the same alternate delimiter for all your variables, you can update the Data Element as such:
return location.pathname.split('/').filter(Boolean).slice(0,4).join('[d]');
Where [d] is replaced by your delimiter. Note that this will now cause the Data Element to return a single concatenated String value instead of an Array. Using %hier1% syntax in DTM fields remains the same, but you will no longer need to use .join() in Custom Code boxes.
If your implementation uses different delimiters for different variables, implement the Data Element per the original instructions in the first section. You may use %hier1% syntax in DTM fields only if the delimiter is a comma. For all other delimiters, you will need to populate the variable in a custom code box and use a .join('[d]').
Capturing more than Four Directory Levels
Since you are no longer trying to put a value in four hierarchy fields, you may consider pushing more levels to hier1 or other variables.
In the Data Element, change the 4 in .slice(0,4); to whatever max level of dirs you want to capture. Or, if you want to capture all dir levels, remove .slice(0,4) completely.

How to filter the the odata query with case insensitivity when already using a function?

I have a complex odata query that I am passing through Angular using OdataAngularResrouce library. As we all know that odata queries are case sensitive and obviously I dont know how the data is being stored in the database. Here is the predicates that I used to build the query.
var predicFirstName = new $odata.Predicate(new $odata.Func("startswith", "FirstName", new $odata.Func("tolower", $scope.searchObject.searchString)), true);
var predicLastName = new $odata.Predicate(new $odata.Func("startswith", "LastName", new $odata.Func("tolower", $scope.searchObject.searchString)));
**OData URI:**
https://localhost/app/TylerIdentityUserAdministrationService/Users/$count/?$filter=((startswith(FirstName,tolower(Fahad)))%20or%20startswith(LastName,tolower(Fahad)))
As you can see, I want to put a function to check only the given string with startswith. I have seen several posts where the solution is to put the tolower(). However, when I put it the way mentioned above its not returning any data. Can anybody help here?
Thanks
-Fahad
Both the properties and the literal strings in the $filter need to be converted to lowercase. And since the literal strings originate on the client, you can optimize by converting them to lowercase before you send the OData request.
$filter=startswith(tolower(FirstName),'fahad') or startswith(tolower(LastName),'fahad')
Note that the literal strings must be surrounded with single quotes in the filter expression.

How to pass an array within a http header?

I would like to pass an array through a http header.
Would it be acceptable to name multiple params the same name, and that way I would know that they belong to an array just like in a get request query string? Example:
CurrentHeaderArray: myarray[]=value1&myarray[]=value2&myarray[]=value3
There is already a stackoverflow answer to pass it through the query string of a get request, see this hyper link.
How to pass an array within a query string?
You can pass an array as string with some delimiter char as the way csv file does. Then, in the server side code, just use some string split function to get back the array.
If the string contains the delimiter charater, escapes them.
You can pass an array as a header like this:
CurrentHeaderArray : [ "value1", "value2", "value3" ]
You can easily try this in a tool like Fiddler, using the Composer.

Resources