I'm doing some work to edit a configuration file. When I try, things are not quite working right.
Here's my code
config.module.rules.unshift( {
test: "/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/",
use: [ 'raw-loader' ]
}
);
fs.writeFileSync("C:\\temp\\config.txt", JSON.stringify(config) );
This outputs a file that contains the following text...
{
"test": "/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+.svg$/",
"use": [
"raw-loader"
]
},
however the value of "test" is incorrect. I'd like to have it set to
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: [ 'raw-loader' ]
}
Notice how there are no quotes around the regular expression string.
If I try to use
config.module.rules.unshift( {
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: [ 'raw-loader' ]
}
);
fs.writeFileSync("C:\\temp\\config.txt", JSON.stringify(config) );
Here's what I get instead
{
"test": {},
"use": [ "raw-loader" ]
},
I need to get the value of test to be
/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/
I'm barking up the wrong tree. As people have pointed out, the JSON Serialiser is changing the output to {}, instead of the value I was expecting. When I look at the object itself. It's set properly.
Related
I get a string from my user that represents an elastic request. There can be the following types of requests:
Single term: TERM:MATCH_TERM ;
Several terms separated by AND: TERM:MATCH_TERM AND TERM:MATCH_TERM AND TERM:MATCH_TERM ;
Several terms separated by OR: TERM:MATCH_TERM OR TERM:MATCH_TERM OR TERM:MATCH_TERM ;
Several terms separated by AND and OR: TERM:MATCH_TERM AND TERM:MATCH_TERM OR TERM:MATCH_TERM AND TERM:MATCH_TERM OR TERM:MATCH_TERM AND TERM:MATCH_TERM ;
The OR operator has priority over the AND operator
I parse this string next and get a list of my different terms.
I want to use this list now to build my elastic query. I know I will have to use the syntax for complex queries: bool. (I use the javascript client of elastic to make my request)
From what I understand, the must filter will allow me to do an AND and the should filter will allow me to do an OR.
In the case where we have: TERM1:MATCH_TERM1 AND TERM2:MATCH_TERM2 OR TERM3:MATCH_TERM3 AND TERM4:MATCH_TERM4 OR TERM5:MATCH_TERM5 AND TERM6:MATCH_TERM6 ;
Would the correct syntax be something like this:
"query":{
"bool":{
"should":[
"must":[
{"terms":{"TERM1":"MATCH_TERM1"}}
] ,
"must":[
{"terms":{"TERM2":"MATCH_TERM2"}}
] ,
],
"should":[
"must":[
{"terms":{"TERM3":"MATCH_TERM3"}}
] ,
"must":[
{"terms":{"TERM4":"MATCH_TERM4"}}
] ,
],
"should":[
"must":[
{"terms":{"TERM5":"MATCH_TERM5"}}
] ,
"must":[
{"terms":{"TERM6":"MATCH_TERM6"}}
] ,
],
}
}
If there is any information missing to answer my question let me know and I will try to add it as soon as possible.
Thank you in advance if you take the time to help me.
{
"query": {
"bool": {
"should": [
{
"bool": {
"filter": [
{
"terms": {
"TERM1": [
"MATCH_TERM1"
]
}
},
{
"terms": {
"TERM2": [
"MATCH_TERM2"
]
}
}
]
}
},
{
"bool": {
"filter": [
{
"terms": {
"TERM3": [
"MATCH_TERM3"
]
}
},
{
"terms": {
"TERM4": [
"MATCH_TERM4"
]
}
}
]
}
},
{
"bool": {
"filter": [
{
"terms": {
"TERM5": [
"MATCH_TERM5"
]
}
},
{
"terms": {
"TERM6": [
"MATCH_TERM6"
]
}
}
]
}
}
],
"minimum_should_match": "1"
}
}
}
I'm trying to sort props names alphabetically using the plugin eslint-plugin-react but I'm getting this error:
[Error ] .eslintrc.json: Configuration for rule "react/jsx-sort-props" is invalid: Value {"callbacksLast":true,"shorthandFirst":false,"shorthandLast":true,"multiline":"last","ignoreCase":true,"noSortAlphabetically":false} should NOT have additional properties.
This is my .eslintrc.json file:
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"next/core-web-vitals"
],
"rules": {
"react/jsx-sort-props": [
"2",
{
"callbacksLast": true,
"shorthandFirst": false,
"shorthandLast": true,
"multiline": "last",
"ignoreCase": true,
"noSortAlphabetically": false
}
]
}
}
What I'm missing?
There are two issues:
The severity option, if you're using a number, should be a number, not a string that contains a number - 2, not "2". (Though, personally, I'd suggest using "error" instead - it makes it clearer from reading the config what the rule means for your project - "error" makes more intuitive sense than 2)
There is a bug in the linter rule's jsx-sort-props.js - although the docs reference a multiline property, said property does not exist anywhere in the lint rule implementation, and so an error is thrown when you pass in an object containing that property. Remove it.
"rules": {
"react/jsx-sort-props": [
2,
{
"callbacksLast": true,
"shorthandFirst": false,
"shorthandLast": true,
"ignoreCase": true,
"noSortAlphabetically": false
}
]
}
I am looking out methods of Extracting only portion of JSON document with REST API search call in MarkLogic using JavaScript or XQuery.
I have tried using query options of re extract-document-data but was not successful. Tried checking my extract path using CTS.validextract path but that function was not recognised in Marklogic 9.0-1
Do I have to using specific search options like constraints or structured query.
Could you please help out? TIA.
I have below such sample document
{
"GenreType": {
"Name": "GenreType",
"LongName": "Genre Complex",
"AttributeDataType": "String",
"GenreType Instance Record": [
{
"Name": "GenreType Instance Record",
"Action": "NoChange",
"TitleGenre": [
"Test1"
],
"GenreL": [
"Test1"
],
"GenreSource": [
"ABC"
],
"GenreT": [
"Test1"
]
},
{
"Name": "GenreType Instance Record",
"Action": "NoChange",
"TitleGenre": [
"Test2"
],
"GenreL": [
"Test2"
],
"GenreSource": [
"PQR"
],
"GenreT": [
"Test2"
]
}
]
}
}
in which i need to search a document with attribute "TitleGenre" WHERE GenreSource = “ABC” in the GenreType complex attribute. It's an array in json document.
I was using the search option as below, (writing search option in XML, but searching the in json documents)
<extract-path>/GenreType/"GenreType Instance Record"[#GenreSource="ABC"]</extract-path>
I am still facing the issues. If possible could you please let me know how json documents can be searched for such specific requirement? #Wagner Michael
You can extract document data by using the extract-document-data option.
xquery version "1.0-ml";
let $doc := object-node {
"GenreType": object-node {
"Name": "GenreType",
"LongName": "Genre Complex",
"AttributeDataType": "String",
"GenreType-Instance-Record": array-node {
object-node {
"TitleGenre": array-node {
"Test1"
},
"GenreSource": array-node {
"ABC"
}
},
object-node {
"TitleGenre": array-node {
"Test2"
},
"GenreSource": array-node {
"PQR"
}
}}
}
}
return xdmp:document-insert("test.xml", $doc);
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search(
"Genre Complex",
<options xmlns="http://marklogic.com/appservices/search">
<extract-document-data>
<extract-path>/GenreType/GenreType-Instance-Record[GenreSource = "ABC"]</extract-path>
</extract-document-data>
</options>
)
In this case /GenreType/GenreType-Instance-Record is the xpath to the extracted element.
Relating to your comment, i also added a predicate [GenreSource = "ABC"]. This way only GenreType-Instance-Record which have a GenreSource of "ABC" are being extracted!
Result:
....
<search:extracted kind="array">[{"GenreType-Instance-Record":{"TitleGenre":["Test1"], "GenreSource":["ABC"]}}]
</search:extracted>
....
Note:
You can add multiple <search:extract-path> elements!
I had to change the name of GenreType Instance Record to GenreType-Instance-Record. I am not sure if you can have property names with whitespaces and access them with xpath. I couldn't get it working this way.
Please post your search options, if this does not work for you.
Edit: Added a predicate to the extract-path.
Thank you so much Wagner, for your prompt trials. Helped me look out for accurate solution to my problem as of now. I have used below extract path, as i could not modify the names in documents. /GenreType/array-node("GenreType Instance Record")/object-node()/TitleGenre[following-sibling::GenreSource="ABC"]
im working with nodejs an need to get a string value from a json.
The json looks like this:
`result["DIDL-Lite"]["item"] = [ { '$': { id: '0/Spotify/Track', parentID: '0/Spotify', restricted: '0' },
'upnp:class': [ 'object.item.audioItem.musicTrack' ],
'raumfeld:section': [ 'Spotify' ],
'dc:title': [ 'Californication' ],
'upnp:artist': [ 'Red Hot Chili Peppers' ],
'upnp:album': [ 'Californication (Deluxe Version)' ],
'upnp:albumArtURI': [ [Object] ] } ]`
how can i access the dc:title (or any other) value?
I'm trying different ways, e.g. console.log(result["DIDL-Lite"]["item"]["dc:title"]);, but I simply can't get it work...
Any tips? Thank you in adavance!!
I have the following objects in some dedicated json file:
{
"obj1": {
"firstField": "a",
"secondField": "b"
}
},
{
"obj2": {
"firstField": "c",
"secondField": "d"
}
}
I would like to read this json from my grunt file, inside initConfig.
I use:
grunt.initConfig({
configuration: grunt.file.readJSON('configuration.json')
)
}
Now I want to get Obj1 or Obj2 - and give them a name, so I could extract firstField generically.
Something like:
obj: '<%= configuration.obj1 %>
and then use:
'<%= obj.firstField %>
But this one is not working. How can I do it?