Distance search issue
I'm using Low Search to give users a choice of searching using either a keyword or distance from a given postcode. The keyword search is working perfectly, but I'm having some issues with the distance search. Although I appreciate that some of my problems are not directly related to Low Search, I would appreciate some pointers on how to solve my problem.
When I hard code the latitude and longitude in a hidden field, the search works as expected. However, it is not practical to expect the users to know the latitude and longitude of their search location so I using a postcode lookup instead.
I have successfully implemented a postcode to lat/long geocode script which is triggered using an onsubmit() form event. This script fills out a hidden form field (with a "name=distance:from" attribute), which I have checked using browsers dev tools and it successfully sets the value of the hidden field to the correct latitude and longitude in the format needed by Low Search. The script then returns true to submit the form, but, instead of the distance-based search, Low Search returns all the entries in the chosen channel in date order, newest first.
I don't understand why search works correctly with a fixed value in the hidden field, but fails with a dynamically set value. I would appreciate any pointers to how I can find out what is going on. I am using EE 2.8.1 and Low Search 3.1.4.
Replies
Low 29 Apr 2014 18:41
When using your JS script, what is the search URI for the distance search that isn't giving the correct search results? And what does the search log tell you for such a search?
Steve Rowling 29 Apr 2014 18:52
The search log doesn't have the distance:from parameter listed at all for failed searches, which is odd, because if I edit the JS to return false instead of true after geocoding, using the browser's developer tools, I can see the hidden distance:from field with the correct value in the DOM.
An example of the encoded search URI for a failed search is eyJyZXN1bHRfcGFnZSI6ImZpbmQtYS1yb29tXC9zZWFyY2gtcmVzdWx0cyIsImRpc3RhbmNlOnRvIjoibGF0aXR1ZGV8bG9uZ2l0dWRlIiwiZGlzdGFuY2U6dW5pdCI6Im1pIiwicG9zdGNvZGUiOiJSSDE3IDdTUSIsImRpc3RhbmNlOnJhZGl1cyI6IjUiLCJzdWJtaXQiOiJTZWFyY2ggZm9yIHJvb21zIn0
Low 29 Apr 2014 19:00
The distance:from parameter isn't sent along with the form. If it was, it would appear in the URI and in the search log. If it does appear in the developer tools, it might be that it is added either after the search is submitted, or the field is added outside of the form.