How to convert below array to specific output?
Input:
[
{
"id": "9664581",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [
{
"id": "9664581:att_name",
"value": "Test1 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
},
{
"id": "9664581:att_email",
"value": "test1#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
},
{
"id": "9664581:comp_name",
"value": "Test1 comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
},
{
"id": "9664581:attendee_ctry",
"value": "Test cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
},
{
"id": "9664581:sources",
"value": "Test DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}
]
},
{
"id": "9528552",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [
{
"id": "9528552:att_name",
"value": "Test2 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
},
{
"id": "9528552:att_email",
"value": "Test2#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
},
{
"id": "9528552:comp_name",
"value": "Dsd comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
},
{
"id": "9528552:attendee_ctry",
"value": "Test2 cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
},
{
"id": "9528552:sources",
"value": "Test2 DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}
]
}
]
output should be like
output:
[
{
"id": "9664581",
"name": "Test1 att_name",
"email": test1#gmail.com
},
{
"id": "9528552",
"name": "Test2 att_name",
"email": test2#gmail.com
}
]
You need to understand your data.
It appears that the id comes right off of each object. As for the name and email, those are the values of the first and second cell. This turns into a trivial mapping.
You could also try to look-up the cells by their header:
function transformData(data) {
return data.map(item => {
return {
id : item.id,
name : item.cells.find(cell => cell.info.header.endsWith('name')).value,
email : item.cells.find(cell => cell.info.header.endsWith('email')).value
};
});
}
console.log(transformData(getData()));
function transformData(data) {
return data.map(item => {
return {
id : item.id,
name : item.cells[0].value,
email : item.cells[1].value
};
});
}
function getData() {
return [{
"id": "9664581",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [{
"id": "9664581:att_name",
"value": "Test1 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
}, {
"id": "9664581:att_email",
"value": "test1#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
}, {
"id": "9664581:comp_name",
"value": "Test1 comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
}, {
"id": "9664581:attendee_ctry",
"value": "Test cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
}, {
"id": "9664581:sources",
"value": "Test DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}]
}, {
"id": "9528552",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [{
"id": "9528552:att_name",
"value": "Test2 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
}, {
"id": "9528552:att_email",
"value": "Test2#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
}, {
"id": "9528552:comp_name",
"value": "Dsd comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
}, {
"id": "9528552:attendee_ctry",
"value": "Test2 cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
}, {
"id": "9528552:sources",
"value": "Test2 DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}]
}];
}
.as-console-wrapper { top: 0; max-height: 100% !important; }
You could do this:
let output = input.map(v => {
let name = '';
let email = '';
v.cells.map(obj => {
if(obj.info.header === 'att_name') {
name = obj.value
}
if(obj.info.header === 'att_email') {
email = obj.value
}
return
})
return {
"id": v.id,
"name": name,
"email": email
}
})
Related
I have this JSON object and I want to change an attribute inside it. In this case I'm trying to change VALUE inside configs[0].configs[0].value
{
"id": "PAY_TOOL_1",
"name": "PAY_TOOL_1",
"description": "PayTool1",
"state": "ENABLED",
"configs": [
{
"isDefaultConfig": null,
"id": "configId-1",
"name": "configId-1",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/", <-- WANT TO CHANGE THIS
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl",
"value": "http://localhost:7070/pay/payment/cancel/",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
{
"isDefaultConfig": null,
"id": "configId-2",
"name": "configId-2",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl2",
"value": "http://localhost:7070/pay/payment/confirm/22",
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl2",
"value": "http://localhost:7070/pay/payment/cancel/22",
"defaultValue": null,
"description": null,
"editable": true
}
]
}
]
}
This is the code in REACT HOOKS following this solution
SOLUTION
const [editPaymentTool, setEditPaymentTool] = useState(null);
function handleConfigurationInputs( configIndex, propertyIndex, configId, attributeName, attributeValue) {
console.log("CONFIG_INDEX: "+configIndex+" PROPERTY_INDEX: "+propertyIndex+" CONFIG ID: "+configId+ " NAME: "+attributeName+ " VALUE: "+attributeValue);
console.log(editPaymentTool);
setEditPaymentTool(prev => ({
...prev,
configs:[{
...prev.configs,
configs:[{
...prev.configs[configIndex].configs[propertyIndex],
value:attributeValue
}]
}]
}));
}
and the output produced which is pretty different from the expected above
{
"id": "PAY_TOOL_1",
"name": "PAY_TOOL_1",
"description": "PayTool1",
"state": "ENABLED",
"configs": [
{
"0": {
"isDefaultConfig": null,
"id": "configId-1",
"name": "configId-1",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/", <-- EXPECTED TO BE CHANGED BUT NOT
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl",
"value": "http://localhost:7070/pay/payment/cancel/",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
"1": {
"isDefaultConfig": null,
"id": "configId-2",
"name": "configId-2",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl2",
"value": "http://localhost:7070/pay/payment/confirm/22",
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl2",
"value": "http://localhost:7070/pay/payment/cancel/22",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/l", <-- THE CHANGED VALUE IS PUT HERE (WRONG)
"defaultValue": null,
"description": null,
"editable": true
}
]
}
]
}
Any help is appreciated
Try this:
newState = _.cloneDeep(editPaymentTool);
newState.configs[0].configs[0].value = newValue;
//more complicated nested updates
...
setEditPaymentTool(newState);
Input:
{
"data": {
"assets": [{
"organizationId": "1056bda9-2598-4fdf-bd99-db3924464a75",
"createdAt": "2018-03-14T14:41:41.154Z",
"tags": [{
"value": "raml",
"key": null,
"mutable": false
},
{
"value": "rest",
"key": null,
"mutable": false
},
{
"value": "api",
"key": null,
"mutable": false
},
{
"value": "v1",
"key": "product-api-version",
"mutable": false
},
{
"value": "has-mule4-connector",
"key": null,
"mutable": false
},
{
"value": "has-mule3-connector",
"key": null,
"mutable": false
},
{
"value": "system",
"key": null,
"mutable": true
},
{
"value": "sourcing",
"key": null,
"mutable": true
}
],
"type": "rest-api"
},
{
"organizationId": "SASAAs",
"createdAt": "2018-03-14T14:41:41.154Z",
"tags": [{
"value": "raml",
"key": null,
"mutable": false
},
{
"value": "rest",
"key": null,
"mutable": false
},
{
"value": "api",
"key": null,
"mutable": false
},
{
"value": "v1",
"key": "product-api-version",
"mutable": false
},
{
"value": "has-mule4-connector",
"key": null,
"mutable": false
},
{
"value": "has-mule3-connector",
"key": null,
"mutable": false
},
{
"value": "system",
"key": null,
"mutable": true
},
{
"value": "supply-chain",
"key": null,
"mutable": true
}
],
"type": "rest-api"
}
]
}
}
Expected output:
{
"data": {
"assets": [{
"organizationId": "1056bda9-2598-4fdf-bd99-db3924464a75",
"createdAt": "2018-03-14T14:41:41.154Z",
"tags": [{
"value": "raml",
"key": null,
"mutable": false
},
{
"value": "rest",
"key": null,
"mutable": false
},
{
"value": "api",
"key": null,
"mutable": false
},
{
"value": "v1",
"key": "product-api-version",
"mutable": false
},
{
"value": "has-mule4-connector",
"key": null,
"mutable": false
},
{
"value": "has-mule3-connector",
"key": null,
"mutable": false
},
{
"value": "system",
"key": null,
"mutable": true
},
{
"value": "sourcing",
"key": null,
"mutable": true
}
],
"type": "rest-api",
"domain": "sourcing"
},
{
"organizationId": "SASAAs",
"createdAt": "2018-03-14T14:41:41.154Z",
"tags": [{
"value": "raml",
"key": null,
"mutable": false
},
{
"value": "rest",
"key": null,
"mutable": false
},
{
"value": "api",
"key": null,
"mutable": false
},
{
"value": "v1",
"key": "product-api-version",
"mutable": false
},
{
"value": "has-mule4-connector",
"key": null,
"mutable": false
},
{
"value": "has-mule3-connector",
"key": null,
"mutable": false
},
{
"value": "system",
"key": null,
"mutable": true
},
{
"value": "supply-chain",
"key": null,
"mutable": true
}
],
"type": "rest-api",
"domain": "supply-chain"
}
]
}
}
SO far, I tried this which worked partially for me.
.data.assets[] | select (.tags[].value=="sourcing") | . += {"domain":"sourcing"}
The problem is that I want this condition to apply for every object inside the array but I'm not able to do that. It is getting applied to the first object only.
Where am i doing wrong? Any suggestions please?
The following seems to meet the descriptive requirements:
.data.assets |=
map( if any(.tags[].value; . == "sourcing")
then . + {"domain":"sourcing"}
else .
end )
This produces the desired output except for the key-value pair "domain": "supply-chain" that is inconsistent with the descriptive requirements.
The following, by contrast, takes its cue from (that is, produces) the given output:
.data.assets |=
map( if any(.tags[].value; . == "sourcing") then . + {"domain":"sourcing"}
elif any(.tags[].value; . == "supply-chain") then . + {"domain":"supply-chain"}
else . end )
Setting "domain" to all the tag values
.data.assets |= map( .domain += [.tags[].value] )
I have a this json that has a arrays in it.
How can i get :
- full_text,
- picture link : media_url_https from media and from extended_entities
- url from entities in urls
- lang
[{
"created_at": "Thu Oct 12 14:42:03 +0000 2017",
"id": 9184869314823331890,
"id_str": "9184869314823331890",
"full_text": "trying some stuff! \nhttps://somewebsite.com/emjc1MLAbD\n\uf6430\nWhat bird is this? What is its name? It has beautiful feathers. Love the mix of green, white. https://somewebsite.com/q3IqrfVcUz",
"truncated": false,
"display_text_range": [0, 139],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": [{
"url": "https://somewebsite.com/emjc1MLAbD",
"expanded_url": "https://www.pexels.com/royalty-free-images/",
"display_url": "pexels.com/royalty-free-i\u2026",
"indices": [20, 43]
}],
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"extended_entities": {
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"metadata": {
"iso_language_code": "en",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
}, {
"created_at": "Wed Oct 04 17:33:29 +0000 2017",
"id": 915630969218064385,
"id_str": "915630969218064385",
"full_text": "hola!",
"truncated": false,
"display_text_range": [0, 5],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": []
},
"metadata": {
"iso_language_code": "es",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://website.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"lang": "es"
}]
Maybe not tidy but still you can try do the following:
require 'json'
test = JSON.parse(json)
test.each {|k|
p "============================"
full_text = k['full_text'] unless k['full_text'].nil?
urls = k['entities']['urls'] unless k['entities']['urls'].nil?
urls.each {|u|
entities_url = u['url'] unless u['url'].nil?
p "Url: #{entities_url}" }
lang = k['lang'] unless k['lang']
media = k['entities']['media']
extended_media = k['extended_entities']['media'] unless k['extended_entities'].nil?
p "Full text: #{full_text}" unless full_text.nil?
media.each {|u|
p "Media url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless media.nil?
extended_media.each {|u|
p "Extended url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless extended_media.nil?
p "Lang: #{lang}" unless lang.nil?
p "============================="
}
I have an index in azure search that consists of person data like firstname and lastname.
When I search for 3 letter lastnames with a query like
rau&searchFields=LastName
/indexes/customers-index/docs?api-version=2016-09-01&search=rau&searchFields=LastName
The name rau is found but it is quite far at the end.
{
"#odata.context": "myurl/indexes('customers-index')/$metadata#docs(ID,FirstName,LastName)",
"value": [
{
"#search.score": 8.729204,
"ID": "someid",
"FirstName": "xxx",
"LastName": "Liebetrau"
},
{
"#search.score": 8.729204,
"ID": "someid",
"FirstName": "xxx",
"LastName": "Damerau"
},
{
"#search.score": 8.729204,
"ID": "someid",
"FirstName": "xxx",
"LastName": "Rau"
More to the top are names like "Liebetrau","Damerau".
Is there a way to have exact matches at the top?
EDIT
Querying the index definition using the RestApi
GET https://myproduct.search.windows.net/indexes('customers-index')?api-version=2015-02-28-Preview
returned for LastName
"name": "LastName",
"type": "Edm.String",
"searchable": true,
"filterable": true,
"retrievable": true,
"sortable": true,
"facetable": true,
"key": false,
"indexAnalyzer": "prefix",
"searchAnalyzer": "standard",
"analyzer": null,
"synonymMaps": []
Edit 1
The analyzer definition
"scoringProfiles": [],
"defaultScoringProfile": null,
"corsOptions": null,
"suggesters": [],
"analyzers": [
{
"name": "prefix",
"tokenizer": "standard",
"tokenFilters": [
"lowercase",
"my_edgeNGram"
],
"charFilters": []
}
],
"tokenizers": [],
"tokenFilters": [
{
"name": "my_edgeNGram",
"minGram": 2,
"maxGram": 20,
"side": "back"
}
],
"charFilters": []
Edit 2
At the end specifying a ScoringProfile that i use whene querying did the trick
{
"name": "person-index",
"fields": [
{
"name": "ID",
"type": "Edm.String",
"searchable": false,
"filterable": true,
"retrievable": true,
"sortable": true,
"facetable": true,
"key": true,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": null
}
,
{
"name": "LastName",
"type": "Edm.String",
"searchable": true,
"filterable": true,
"retrievable": true,
"sortable": true,
"facetable": true,
"key": false,
"analyzer": "my_standard"
},
{
"name": "PartialLastName",
"type": "Edm.String",
"searchable": true,
"filterable": true,
"retrievable": true,
"sortable": true,
"facetable": true,
"key": false,
"indexAnalyzer": "prefix",
"searchAnalyzer": "standard",
"analyzer": null
}
],
"analyzers":[
{
"name":"my_standard",
"#odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
"tokenizer":"standard_v2",
"tokenFilters":[ "lowercase", "asciifolding" ]
},
{
"name":"prefix",
"#odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
"tokenizer":"standard_v2",
"tokenFilters":[ "lowercase", "my_edgeNGram" ]
}
],
"tokenFilters":[
{
"name":"my_edgeNGram",
"#odata.type":"#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
"minGram":2,
"maxGram":20,
"side": "back"
}
],
"scoringProfiles":[
{
"name":"exactFirst",
"text":{
"weights":{ "LastName":2, "PartialLastName":1 }
}
}
]
}
The analyzer "prefix" set on the LastName field produces the following terms for the name Liebetrau : au, rau, trau, etrau, betrau, ebetrau, iebetrau, libetrau. These are edge ngrams of length ranging from 2 to 20 starting from the back of the word, as defined in the my_edgeNGram token filter in your index definition. The analyzer will process other names in the same way.
When you search for the name rau, it matches all names as they all end with those characters. That's why all documents in your result set have the same relevance score.
You can test your analyzer configurations using the Analyze API.
To learn more about custom analyzers please go here and here.
Hope that helps
I am using lopbackJS AngularJS sdk.I have a model for sites (id(pk) int, name varchar(50), url varchar(100)).
When i try to update name and calling site.save(), record became duplicated. If i try to update other fields except name, update succeeded.
Any suggestion?
site.json :
{
"name": "Site",
"base": "PersistedModel",
"idInjection": false,
"mysql": {
"schema": "myDB",
"table": "Site"
},
"properties": {
"id": {
"type": "Number",
"id": true,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "Id",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": true
},
"xmlFieldId": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "XmlFieldId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"name": {
"type": "String",
"required": true,
"length": 150,
"precision": null,
"scale": null,
"mysql": {
"columnName": "Name",
"dataType": "varchar",
"dataLength": 150,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": true
},
"url": {
"type": "String",
"required": true,
"length": 600,
"precision": null,
"scale": null,
"mysql": {
"columnName": "Url",
"dataType": "varchar",
"dataLength": 600,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"active": {
"type": "Boolean",
"required": true,
"mysql": {
"columnName": "Active",
"dataType": "BOOL",
"nullable": "N"
},
"_selectable": true
},
"xmlUrl": {
"type": "String",
"required": false,
"length": 600,
"precision": null,
"scale": null,
"mysql": {
"columnName": "XmlUrl",
"dataType": "varchar",
"dataLength": 600,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"private": {
"type": "Boolean",
"required": true,
"mysql": {
"columnName": "Private",
"dataType": "BOOL",
"nullable": "N"
},
"_selectable": true
},
"xmlUrlValidated": {
"type": "Boolean",
"required": true,
"length": null,
"precision": 5,
"scale": 0,
"mysql": {
"columnName": "XmlUrlValidated",
"dataType": "BOOL",
"nullable": "N"
},
"_selectable": true
},
"xmlUrlValUpdate": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "XmlUrlValUpdate",
"dataType": "datetime",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"imgBaseUrl": {
"type": "String",
"required": false,
"length": 200,
"precision": null,
"scale": null,
"mysql": {
"columnName": "ImgBaseUrl",
"dataType": "varchar",
"dataLength": 200,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"credit": {
"type": "Number",
"required": false,
"length": null,
"precision": 8,
"scale": 2,
"mysql": {
"columnName": "Credit",
"dataType": "decimal",
"dataLength": null,
"dataPrecision": 8,
"dataScale": 2,
"nullable": "N"
},
"_selectable": true
}
},
"validations": [],
"relations": {
"siteCategorySteps": {
"type": "hasMany",
"model": "SiteCategoryStep",
"foreignKey": ""
},
"siteProdSchemas": {
"type": "hasOne",
"model": "SiteProdSchema",
"foreignKey": ""
},
"products": {
"type": "hasMany",
"model": "Product",
"foreignKey": ""
},
"users": {
"type": "hasMany",
"model": "UyguncaUser",
"foreignKey": "siteId"
}
},
"acls": [],
"methods": []
}
Controller :
'use strict';
MyApp.controller('SiteInfoController', ['$rootScope', '$scope', '$timeout', '$animate', 'Site', '$http', 'CheckXmlFile',
function ($rootScope, $scope, $timeout, $animate, Site, $http, CheckXmlFile) {
var site = null;
Site.findOne({
filter: {where: {id: $rootScope.globals.accessToken.user.siteId}}
}, function (fSite) {
site = $scope.site = fSite;
});
$scope.checkXmlUrl = function (showMesg, cb) {
CheckXmlFile.check({
xmlUrl: site.xmlUrl
}, function (res) {
site.xmlUrlValidated = true;
site.$save();
if (showMesg) showMsg({
title: "Bilgi!",
text: res.msg,
type: "success",
confirmButtonText: "Tamam",
}, null);
cb(true);
}, function (err) {
site.xmlUrlValidated = false;
site.$save();
if (showMesg) showMsg({
title: "Hata!",
text: err.data.errMsg,
type: "error",
confirmButtonText: "Tamam",
}, null);
cb(false);
})
};
$scope.save = function () {
!$scope.checkXmlUrl(false, function (err) {
if (!err) {
showMsg({
title: "Uyarı!",
text: "Kayıt yapıldı fakat XML dosya doğrulanamadı. XML dosya doğrulaması yapılmadan ürün bilgileri alınamayacaktır!",
type: "warning",
confirmButtonText: "Tamam",
}, null);
}
else {
showMsg({
title: "Bilgi!",
text: "XML dosya doğrulanarak site bilgileri kaydedilmiştir.",
type: "success",
confirmButtonText: "Tamam",
}, null);
}
});
}
}]);
I found that, 'Site' table has trigger and it prevents to update.
I removed trigger and update works...