我正在开发一个网站allevents.in(基本上它是一个事件发现和事件推广平台),在这个网站上我想申请solr搜索。
我正在使用Solarium作为php客户端。现在,当您进入网站时,我正在进行快速搜索(标题上的绿色按钮)。
所以现在我想搜索像“纽约音乐会”这样的活动然后它会给我纽约的活动(这很有效)。
但是我希望有一个搜索结果只有“音乐会”然后它应该从我当前的位置或最近的位置的结果给我结果。
那么我怎样才能找到当前位置。因此,当我只搜索“音乐事件”时,它会给我更接近我当前位置或城市的结果。
我正在使用geofilt()和geodist()。
答案 0 :(得分:0)
我认为您已经熟悉solr提供的地理定位过滤器。
那么你的问题是什么?在索引数据时是否已提供地理定位?
如果不是,您应该考虑使用API为您提供给定地址的地理位置,以便您可以将其与其他数据一起索引。 See here
然后在搜索时获取当前访问您网站的人的位置,请检查:HTML5 Location。 作为故障转移,您可以使用IP解析API来获取此人的大致位置,如下所示:IP Resolver(如果您在网上搜索一下,还可以使用其他人)
我希望这能回答你的问题。
上一篇文章后编辑。
正如我之前所说,使用HTML5位置获取位置。
首先,您可以在html表单中添加两个隐藏字段(我使用jquery语法):
//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>
现在表单已提交,我们需要访问我们在隐藏字段中设置的值。
//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
希望这会有所帮助。