0

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().

Lain
  • 2,166
  • 4
  • 23
  • 47
sohan
  • 17
  • 5

1 Answers1

0

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.

Esquive
  • 181
  • 7
  • So is there any function or facility in solr that will give me the current location and give me results nearer to my location. – sohan Feb 01 '14 at 09:50
  • Well for getting the current location of your user you must extend solr using an API I mentionned before. So no there is no built-in method in solr to get the current location of a user of your site. On the other hand if you managed to get the location: solr provides facilities you can get results near to your location. It is described here: http://wiki.apache.org/solr/SpatialSearch – Esquive Feb 02 '14 at 19:31
  • I want to get my value of the field ‘Latitude’ and ‘Longitude’ into a variable in order to pass it as an argument in below function: $query->createFilterQuery('city')->setQuery($helper->geofilt(doubleval('latitude'),doubleval('longitude'),'geo',25)); $query->addSort(($helper->geodist('geo','latitude','longitude')), Solarium_Query_Select::SORT_ASC); And it only pass pt=0,0 as shown below and no results: fq={!geofilt+pt%3D0,0+sfield%3Dgeo+d%3D25} So how to get field values of ‘latitude’ and ‘longitude’ in geofilt() Sothat i can get results and value with in that 'latitude' and 'longitude' ? – sohan Feb 04 '14 at 07:57
  • Thanks Esquive. I got my answer. – sohan Feb 05 '14 at 13:25