I'm currently working on a school project that uses bing image search api. My goal is to get a profile picture for every starwars character (as accurately as possible). I dont understand why, but the api doesnt seem to find results with accents on charaters.
For instance, in the code below, when searchTerm = "Han Solo"
everything works find but when searchTerm = "Dormé"
the API doesn't return any picture.
The wierd thing is if I do the same search in bing directly, it finds many pictures, but I get none from the API.
//server.js
app.get('/getPortrait/*', (req, res) => {
const serviceKey = "MY_KEY";
let searchTerm = req.url.split('/').pop();
// when searchTerme= "han solo", it works fine
// when searchTerme= "Dormé", it works but returns no image in the response
let credentials = new CognitiveServicesCredentials(serviceKey);
let imageSearchClient = new Search.ImageSearchClient(credentials);
let resultURL;
const sendQuery = async () => {
return await imageSearchClient.imagesOperations.search(searchTerm);
};
sendQuery().then(imageResults =>{
console.debug(imageResults)
if (imageResults == null || imageResults.value.length == 0) {
console.error("No image results were found.");
res.send(defaultPic);
}
else {
resultURL = imageResults.value[0].contentUrl;
console.log(resultURL);
res.send(resultURL);
}
}).catch(err => {
console.error(err)
res.send(defaultPic);
});
});
Is there a way configurate the search to accept all types of characters ?
Here are the results I get for theses queries :
\\searchTerm = "Dormé"
Object {_type: "Images", value: Array(0)}
_type:"Images"
value:Array(0) []
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}
\\searchTerm = "han solo"
Object {_type: "Images", readLink: "https://api.cognitive.microsoft.com/api/v7/images/…", webSearchUrl: "https://www.bing.com/images/search?q=han%20solo&FO…", totalEstimatedMatches: 868, nextOffset: 43, …}
nextOffset:43
readLink:"https://api.cognitive.microsoft.com/api/v7/images/search?q=han%20solo"
totalEstimatedMatches:868
value:Array(35) [Object, Object, Object, …]
webSearchUrl:"https://www.bing.com/images/search?q=han%20solo&FORM=OIIARP"
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}
https://www.starwarsnewsnet.com/wp-content/uploads/2017/01/Alden-Ehrenreich-as-Han-Solo-4.jpg
Thank you for your help :)