How can I prioritize search country in Bing Maps Ajax - ajax

In current realization I just add country to query, but this logic is incorrect.
$.ajax({
url: 'https://dev.virtualearth.net/REST/v1/Locations/'
+ searchString + ' ' + currentCountry + '?c=' + currentCulture + ...,
dataType: 'script'
});
But if I try to search city out of currentCountry, I will find currentCountry, but not searchString .
Example: searchString = Boston, currentCountry = Australia
Second approach - remove currentCountry from query at all, but it will cause another bug.
I will not find less famous place in currentCountry
Example: searchString = Moscow, currentCountry = USA.
Result of this query will be - Moscow, Russia and not Moscow, Washington, D.C.
Is there some ability to specify search country?
First try of search will be in currentCountry, if it fails, then second will be in all World.

If you read the best practices for Bing Maps it actually recommends using the unstructured URL format rather than the structured format when geocoding as it will increase the accuracy of the results: https://msdn.microsoft.com/en-us/library/dn894107.aspx
In order to limit the results to a single country, simple append the country to the query.
Your code is close but there should be a comma, and you would be using the query parameter as the format you are using is meant for reverse geocoding coordinates. Here is a modified version of your code:
$.ajax({
url: 'https://dev.virtualearth.net/REST/v1/Locations?q='
+ encodeURIComponent(searchString + ', ' + currentCountry) + '?c=' + currentCulture + ...,
dataType: 'script'
});
You also want to encode the query value to ensure that special characters do not cause any issues.

According to Find a Location by Address you could get the latitude and longitude coordinates based on a set of address values for specific countries.
Example:
The query:
http://dev.virtualearth.net/REST/v1/Locations/US/Moscow?o=xml&key=BingMapsKey
Note: A structured URL specifies the location data for the country
(US in this example) as part of the URL path.
will return locations for Moscow situated in United States.

Related

Is it possible to do this with Power Query

good afternoon, I have a problem with a query in Power Query, I am making this query to a server and within the code there is a value that must be changing every month (green box (127)). It will be possible to change this value from an Excel cell as a parameter, and that this parameter is part of the code (M language) in Power Query ?
codigo completo
codigo detalle
Put your parameter value into a cell, and assign a named range to this cell - e.g. MyParameter
Now you can reference this named range in your Power Query, and include it in your query string:
MyParameter = Excel.CurrentWorkbook(){[Name="MyParameter"]}[Content]{0}[Column1],
Source = Sql.Database("MyServer", "CAMPANAS", [Query="SELECT * FROM [CAMPANAS].[dbo].[CTO] ct WHERE ct.Refresco = " & Text.From(MyParameter)]),

GeoDistance - Elasticsearch

I have a problem with the search for GeoDistance in Elasticsearch.
I have in my documents the latitude and longitude of the users according to the Zip code.
With that, I had to include in my system the autocomplete of google addresses to be able to search for a user closer to the given address and I added a radius bar, where I need to inform that I want users close to that address in up to X KM of distance.
The problem is, if I search for a more precise address, with street name, elastic normally finds the user.
But if I enter a more general address, such as a city or country, the search returns nothing.
I believe it has something to do with the search radius, but I haven't found a solution for that.
Here is my code:
if (filters.Latitude! = null && filters.Longitude! = null)
{
//filtros.RangeLogradouro = 20 Km
andQuery & = queryBuilder.GeoDistance (b => b
.Distance (Distance.Kilometers (filters.RangeLogradouro))
.Field (p => p.Location)
.Boost (1.1)
.ValidationMethod (GeoValidationMethod.IgnoreMalformed)
.Location (new GeoLocation (latitude: filters.Latitude, longitude: filters.Longitude))
);
}
Has anyone experienced this problem and managed to solve it?
Thank you.

XPath to track if a product is: in stock/its price

I am a complete beginner who knows a little bit of HTML and Java so my question might sound very dumb.
I'm basically trying to use Google Spreadsheets in order to track the availability of an item/its price on this website. I'm using the "IMPORTXML" function and have no trouble getting the title of the product or its description. However I cannot get the price as it needs me to select a size first, which I don't know how to do through the "IMPORTXML" function.
Right now, this returns "Imported content is empty.":
=IMPORTXML("https://www.artisan-jp.com/fx-hien-eng.html","//p[#id='price']")
Would creating a function through Google Script work? If so, how do I do it?
Thank you!
You won't be able to do fetch any data with IMPORTXML since Javascript is used to display the price. With IMPORTFROMWEB addon, you can activate JS rendering but you'll only get the price of the default product.
It's probably better to use Selenium + Python (or any other language) to achieve your goal. That way you'll be able to click and select a specific product.(size, color, hardness)
If you really want to do this with a Google solution, you'll have to write your own custom function in Google Apps Script (send a POST request over a specific url : https://www.artisan-jp.com/get_syouhin.php). Something like :
function myFunction() {
var formData = {
'kuni': 'on',
'sir': '140',
'size': '1',
'color': '1',
};
var options = {
'method' : 'post',
'payload' : formData
};
Logger.log(UrlFetchApp.fetch('https://www.artisan-jp.com/get_syouhin.php', options).getContentText());
}
In the first part (formData), your declare the parameters of the POST. These parameters correspond to the properties of the product.
Sir :
XSoft = 140
Soft = 141
Mid = 142
Size :
S = 1
M = 2
L = 3
XL = 4
Color :
Red = 1
Black = 5
Output :
You'll get the reference number, the description of the product and its price.
When the product is not in stock, there's a preceding NON in the output.
It's up to you now to extract the data of interest from the output and to populate the cells of your workbook.
Assuming your function is named "mouse". Just use SPLIT to display the data properly.
=SPLIT(mouse();"/")
To extract the price only, you can use SPLIT then QUERY. SUBSTITUTE is used to coerce the result to a number.
=SUBSTITUTE(QUERY(SPLIT(mouse();"/");"select Col4");".";",")*1

Splitting XPATH produces more results than the actual possible

I have been trying to gather some historical data of managers of football clubs and noticed a weird behaviour. I am trying to scrape the history table of the clubs managed by a manager from this website : https://www.transfermarkt.co.in/carlo-ancelotti/profil/trainer/523
With the entire xpath as a single input to fetch the response, the code works alright as expected
clubs = response.xpath("//div[#id='yw1']//td[#class='hauptlink no-border-links']//a/text()").extract()
print(clubs)
Output : ['Everton', 'SSC Napoli', 'Bayern Munich ', 'Real Madrid', 'Paris SG',\
'Chelsea', 'Milan', 'Juventus', 'AC Parma', 'Reggiana', 'Italy']
That's the list of clubs from the foretold history table. However, while the xpath is split as shown in the following code, it fetches names of clubs from the other table too in spite of it having a totally different div id. I mean it's not 'yw1' for the other table
career_table = response.xpath("//div[#id='yw1']")
clubs = career_table.xpath("//td[#class='hauptlink no-border-links']//a/text()").extract()
print(clubs)
Output : ['Everton', 'SSC Napoli', 'Bayern Munich ', 'Real Madrid', 'Paris SG',\
'Chelsea', 'Milan', 'Juventus', 'AC Parma', 'Reggiana', 'Italy', 'Milan', 'Retired',\
'AS Roma', 'Milan', 'AC Parma', 'AS Roma', 'Parma U19', 'AC Parma', 'Reggiolo', 'Parma U19']
Can someone enlighten me, what is that I'm missing here?
You need to use relative XPath (starting .):
clubs = career_table.xpath(".//td[#class='hauptlink no-border-links']//a/text()").extract()
print(clubs)

lucene.net, document boost not working

i am a beginner & developing my very first project with lucene.net i.e. an address search utility, lucene.net 3.0.3
using standard analyzer, query parser, (suppose i have a single field, Stored & Analyzed as well)
- sample data : (every row is a document with a single field)
(Postcode and street column concatenated)
UB6 9AH Greenford Road something
UB6 9AP Greenford Road something
UB1 3EB Greenford Road something
PR8 3JT Greenford Road something
HA1 3QD something Greenford Road
SM1 1JY something Greenford Road something
Searching
StringBuilder customQuery = new StringBuilder();
customQuery.Append(_searchFieldName + ":\"" + searchTerm + "\"^" + (wordsCount));
// this is for phrase matching
foreach (var word in words.Where(word => !string.IsNullOrEmpty(word)))
{
customQuery.Append(" +" + _searchFieldName + ":" + word + "*");
}
// this is prefix match for each word
Query query = _parser.Parse(customQuery.ToString());
_searcher.Search(query, collector);
all above (searching) working fine
Question
if i search for "Greenford road" ,
i may want that row that has 'SM1' should come up (means i want to priorities result as per postcode)
i have tested Query-Time-Boost and it works fine
but i may have a long list of priority postcodes sometimes (so i don't want to loop over each postcode and set its priority at query time
I WANT DOCUMENT TIME BOOSTING
but whatever document boost i set (at the time of indexing), it doesn't effect my search results
doc.Add(new Field(SearchFieldName, SearchField, Field.Store.YES, Field.Index.ANALYZED));
if (condition == true)
{
doc.Boost = 2; // or 5 or 200 etc (nothing works)
}
please HELP
i tried to understand similarity and scoring, but its too much mathematics there...
please help....
I recently had this problem myself and I think it might be due to wildcard queries (It was in my case at least). There is another post here that explains the issue better, and provides a possible solution:
Lucene .net Boost not working when using * wildcard

Resources