Question

I am working on a website allevents.in(Basically it is an event discovery and event promotion platform) , in this website I want to apply solr search.

And I am using Solarium as a php-client. Now when you will go to the website I am working on quick Search(green button on header).

So now I want to search events like "Concerts in New York" then it would give me the events in New York(This is quite working).

But I want to have results when some one search only "Concerts" then it should give me results from my current location or results from nearest location.

So how can I find current location. So that when I only search "Music events", then it will give me results nearer to my current location or city.

I am using geofilt() and geodist().

Was it helpful?

Solution

As I see you are already familiar with the geolocation filters provided by solr.

So what is your problem here? Do you already provide the geolocation when you index your data?

If not you should consider an API giving you geolocations for an given address so you can index it along your other data. See here

Then at search time to get the location of the person currently visiting your website check this out: HTML5 Location. As a failover you can fetch the approximate position of the person by using IP resolving APIs like this one: IP Resolver (There are others you can use if you search the web a little)

I hope this answers your question.

Edit: after your last post.

As I said before you get the location using the HTML5 location.

First you could add two hidden fields to your html form (I use jquery syntax):

//The form you use for the submission of your search query 
<form action="search.php" method="post">

//Here are your form elements below are the hidden fields. 

<input type="hidden" name="long" value=""/>
<input type="hidden" name="lat" value=""/>

</form> 

<script type="text/javascript">

//Getting the location once the page finished loading
$( document ).ready(
function()
{
  if (navigator.geolocation)
  {
     navigator.geolocation.getCurrentPosition(showPosition);
  }
});

//Location callback. We set the long and lat values of the hidden fields. 
function showPosition(position)
{
    $('[name="lat"]').val(position.coords.latitude);
    $('[name="long"]').val(position.coords.longitude);  
}

</script>

Now the form was submitted we need to access the values we set at the hidden fields.

//The form was submitted so in your form submission handling code:
$long = $_POST["long"];
$lat= $_POST["lat"];

//Now you have your variables. You can now put them inside your query
//DO your query

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top