I am searching for New York, NY in Algoliya places, but not sure how to get the perfect match from the response, programmatically. Would you please tell me how I can get that?
I want to get the perfect match as I get while using the application
Here is my search code,
$places = Algolia\AlgoliaSearch\PlacesClient::create($appId, $apiKey);
$result = $places->search('New York, NY' ,[
query=>'New York, NY',
type=>'city',
language=>'en'
]
);
var_dump($result);
Here is how the response looks like (sorry for clipping the text as it is a long text, )
array(6) {
[“hits”]=>
array(20) {
[0]=>
array(17) {
[“country”]=>
string(24) “United States of America”
[“is_country”]=>
bool(false)
[“is_highway”]=>
bool(false)
[“importance”]=>
int(16)
["_tags"]=>
array(4) {
[0]=>
string(4) “city”
[1]=>
string(10) “place/city”
[2]=>
string(10) “country/us”
[3]=>
string(15) “source/geonames”
}
[“postcode”]=>
array(145) {
[0]=>
string(5) “10001”
[1]=>
string(5) “10002”
[2]=>
string(5) “10003”
[3]=>
float(40.7127)
[“lng”]=>
float(-74.006)
}
[“objectID”]=>
string(7) “5128581”
["_highlightResult"]=>
array(4) {
[“country”]=>
array(3) {
[“value”]=>
string(24) “United States of America”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[“postcode”]=>
array(145) {
[0]=>
array(3) {
[“value”]=>
string(5) “10001”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[1]=>
array(3) {
[“value”]=>
string(5) “10002”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[2]=>
array(3) {
[“value”]=>
string(5) “10003”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[3]=>
array(3) {
[“value”]=>
string(5) “10004”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[4]=>
array(3) {
[“value”]=>
string(5) “10005”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[5]=>
array(3) {
[“value”]=>
string(5) “10006”
[“matchLevel”]=>
string(4) “none”
[“matchedWords”]=>
array(0) {
}
}
[6]=>
}
[41]=>
array(3) {
["value"]=>
string(5) "10044"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[42]=>
array(3) {
["value"]=>
string(5) "10045"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[43]=>
array(3) {
["value"]=>
string(5) "10055"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[44]=>
array(3) {
["value"]=>
string(5) "10060"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[45]=>
array(3) {
["value"]=>
string(5) "10065"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[46]=>
array(3) {
["value"]=>
string(5) "10069"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[47]=>
array(3) {
["value"]=>
string(5) "10080"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[48]=>
array(3) {
["value"]=>
string(5) "10081"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[49]=>
array(3) {
["value"]=>
string(5) "10087"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[50]=>
array(3) {
["value"]=>
string(5) "10090"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[51]=>
array(3) {
["value"]=>
string(5) "10101"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[52]=>
array(3) {
["value"]=>
string(5) "10102"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[53]=>
array(3) {
["value"]=>
string(5) "10103"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[54]=>
array(3) {
["value"]=>
string(5) "10104"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[55]=>
array(3) {
["value"]=>
string(5) "10105"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[56]=>
array(3) {
["value"]=>
string(5) "10106"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[57]=>
array(3) {
["value"]=>
string(5) "10107"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[58]=>
array(3) {
["value"]=>
string(5) "10108"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[59]=>
array(3) {
["value"]=>
string(5) "10109"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[60]=>
array(3) {
["value"]=>
string(5) "10110"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[61]=>
array(3) {
["value"]=>
string(5) "10111"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[62]=>
array(3) {
["value"]=>
string(5) "10112"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[63]=>
array(3) {
["value"]=>
string(5) "10113"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[64]=>
array(3) {
["value"]=>
string(5) "10114"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[65]=>
array(3) {
["value"]=>
string(5) "10115"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[66]=>
array(3) {
["value"]=>
string(5) "10116"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[67]=>
array(3) {
["value"]=>
string(5) "10117"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[68]=>
array(3) {
["value"]=>
string(5) "10118"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["importance"]=>
int(19)
["_tags"]=>
array(4) {
[0]=>
string(4) "city"
[1]=>
string(10) "country/us"
[2]=>
string(13) "place/village"
[3]=>
string(15) "source/geonames"
}
["postcode"]=>
array(1) {
[0]=>
string(5) "13417"
}
["county"]=>
array(2) {
[0]=>
string(18) "Town of Whitestown"
[1]=>
string(6) "Oneida"
}
["population"]=>
int(3136)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(8) "New York"
}
["admin_level"]=>
int(15)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(14) "New York Mills"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(43.1055)
["lng"]=>
float(-75.2914)
}
["objectID"]=>
string(7) "5128616"
["_highlightResult"]=>
array(5) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["postcode"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(5) "13417"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["county"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(18) "Town of Whitestown"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(6) "Oneida"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["administrative"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(17) "<em>New York</em>"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(true)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
["locale_names"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(23) "<em>New York</em> Mills"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(false)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
}
}
[2]=>
array(18) {
["country"]=>
string(24) "United States of America"
["is_country"]=>
bool(false)
["is_highway"]=>
bool(false)
["importance"]=>
int(16)
["_tags"]=>
array(4) {
[0]=>
string(23) "boundary/administrative"
[1]=>
string(4) "city"
[2]=>
string(10) "country/us"
[3]=>
string(15) "source/geonames"
}
["postcode"]=>
array(1) {
[0]=>
string(5) "07093"
}
["county"]=>
array(2) {
[0]=>
string(13) "Hudson County"
[1]=>
string(6) "Hudson"
}
["population"]=>
int(53366)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(10) "New Jersey"
}
["admin_level"]=>
int(8)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(13) "West New York"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(40.7879)
["lng"]=>
float(-74.0143)
}
["objectID"]=>
string(7) "5106292"
["_highlightResult"]=>
array(5) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["postcode"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(5) "07093"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["county"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(13) "Hudson County"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(6) "Hudson"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["administrative"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(19) "<em>New</em> Jersey"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(false)
["matchedWords"]=>
array(1) {
[0]=>
string(3) "new"
}
}
}
["locale_names"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(22) "West <em>New York</em>"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(false)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
}
}
[3]=>
array(18) {
["country"]=>
string(24) "United States of America"
["is_country"]=>
bool(false)
["is_highway"]=>
bool(false)
["importance"]=>
int(18)
["_tags"]=>
array(4) {
[0]=>
string(4) "city"
[1]=>
string(10) "place/town"
[2]=>
string(10) "country/us"
[3]=>
string(15) "source/geonames"
}
["postcode"]=>
array(1) {
[0]=>
string(5) "12010"
}
["county"]=>
array(2) {
[0]=>
string(17) "City of Amsterdam"
[1]=>
string(10) "Montgomery"
}
["population"]=>
int(17758)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(8) "New York"
}
["admin_level"]=>
int(15)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(9) "Amsterdam"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(42.9434)
["lng"]=>
float(-74.185)
}
["objectID"]=>
string(7) "5107152"
["_highlightResult"]=>
array(5) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["postcode"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(5) "12010"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["county"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(17) "City of Amsterdam"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(10) "Montgomery"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["administrative"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(17) "<em>New York</em>"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(true)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
["locale_names"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(9) "Amsterdam"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
}
}
[4]=>
array(18) {
["country"]=>
string(24) "United States of America"
["is_country"]=>
bool(false)
["is_highway"]=>
bool(false)
["importance"]=>
int(16)
["_tags"]=>
array(5) {
[0]=>
string(23) "boundary/administrative"
[1]=>
string(4) "city"
[2]=>
string(10) "place/town"
[3]=>
string(10) "country/us"
[4]=>
string(15) "source/geonames"
}
["postcode"]=>
array(1) {
[0]=>
string(5) "13069"
}
["county"]=>
array(2) {
[0]=>
string(13) "Oswego County"
[1]=>
string(6) "Oswego"
}
["population"]=>
int(11459)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(8) "New York"
}
["admin_level"]=>
int(8)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(6) "Fulton"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(43.3228)
["lng"]=>
float(-76.4172)
}
["objectID"]=>
string(7) "5118136"
["_highlightResult"]=>
array(5) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["postcode"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(5) "13069"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["county"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(13) "Oswego County"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(6) "Oswego"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["administrative"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(17) "<em>New York</em>"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(true)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
["locale_names"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(6) "Fulton"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
}
}
[5]=>
array(18) {
["country"]=>
string(24) "United States of America"
["is_country"]=>
bool(false)
["is_highway"]=>
bool(false)
["importance"]=>
int(16)
["_tags"]=>
array(5) {
[0]=>
string(23) "boundary/administrative"
[1]=>
string(4) "city"
[2]=>
string(10) "country/us"
[3]=>
string(13) "place/village"
[4]=>
string(15) "source/geonames"
}
["postcode"]=>
array(2) {
[0]=>
string(5) "13676"
[1]=>
string(5) "13699"
}
["county"]=>
array(2) {
[0]=>
string(21) "Saint Lawrence County"
[1]=>
string(12) "St. Lawrence"
}
["population"]=>
int(9829)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(8) "New York"
}
["admin_level"]=>
int(8)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(7) "Potsdam"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(44.6698)
["lng"]=>
float(-74.9813)
}
["objectID"]=>
string(7) "5132103"
["_highlightResult"]=>
array(5) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["postcode"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(5) "13676"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(5) "13699"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["county"]=>
array(2) {
[0]=>
array(3) {
["value"]=>
string(21) "Saint Lawrence County"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
[1]=>
array(3) {
["value"]=>
string(12) "St. Lawrence"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
["administrative"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
string(17) "<em>New York</em>"
["matchLevel"]=>
string(7) "partial"
["fullyHighlighted"]=>
bool(true)
["matchedWords"]=>
array(2) {
[0]=>
string(3) "new"
[1]=>
string(2) "ny"
}
}
}
["locale_names"]=>
array(1) {
[0]=>
array(3) {
["value"]=>
string(7) "Potsdam"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
}
}
}
[6]=>
array(17) {
["country"]=>
string(24) "United States of America"
["is_country"]=>
bool(false)
["is_highway"]=>
bool(false)
["importance"]=>
int(30)
["_tags"]=>
array(3) {
[0]=>
string(4) "city"
[1]=>
string(10) "country/us"
[2]=>
string(15) "source/geonames"
}
["county"]=>
array(1) {
[0]=>
string(15) "Richmond County"
}
["population"]=>
int(9519)
["country_code"]=>
string(2) "us"
["is_city"]=>
bool(true)
["is_popular"]=>
bool(false)
["administrative"]=>
array(1) {
[0]=>
string(8) "New York"
}
["admin_level"]=>
int(30)
["is_suburb"]=>
bool(false)
["locale_names"]=>
array(1) {
[0]=>
string(7) "Clifton"
}
["_geoloc"]=>
array(2) {
["lat"]=>
float(40.6201)
["lng"]=>
float(-74.0771)
}
["objectID"]=>
string(7) "5112956"
["_highlightResult"]=>
array(4) {
["country"]=>
array(3) {
["value"]=>
string(24) "United States of America"
["matchLevel"]=>
string(4) "none"
["matchedWords"]=>
array(0) {
}
}
["county"]=>
array(1) {
[0]=>
array(3) {
["value"]=>