Hi everyone,

General problem:
I've created a view with exposed filters that searches users based on their role and their proximity/distance. The problem I am running into is that filtering by certain roles seems to produce accurate location results, while certain roles return no results at all.
Thank you for your help.

More detail:

  • When it searches users with a role id of 6 by proximity, the search returns nothing. Without entering anything into proximity, it returns the 2500 users properly.
  • When it searches users with a role id of 8 by proximity, the search returns properly.
  • As you can see from the two queries below, the only changes is the users_roles.rid from 6 to 8.

Could this be a problem with the amount of users it's trying to query? Does anybody have any other possible problems?

Extra information:
If you want to give the live version a try, go to: http://grodan101.com/store

I'm also using Profile 2, but that does not affect the filter criteria.

Queries:

Working properly:

SELECT users.picture AS users_picture, users.uid AS uid, users.name AS users_name, users.mail AS users_mail, location.lid AS location_lid, profile_users.pid AS profile_users_pid, location.name AS location_name, 'profile2' AS field_data_field_store_hours_profile2_entity_type, 'profile2' AS field_data_field_website_profile2_entity_type, (IFNULL(ACOS(0.828169832503*COS(RADIANS(location.latitude))*(-0.475718165272*COS(RADIANS(location.longitude)) + -0.879597764453*SIN(RADIANS(location.longitude))) + 0.56047723284*SIN(RADIANS(location.latitude))), 0.00000)*6371396.0928) AS location_distance_sort
FROM 
{users} users
INNER JOIN {profile} profile_users ON users.uid = profile_users.uid
LEFT JOIN {location_instance} location_instance ON users.uid = location_instance.uid
LEFT JOIN {location} location ON location_instance.lid = location.lid
INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid
WHERE (( (users.status <> '0') AND (users_roles.rid = '8') )AND( (location.latitude > '26.8526552378' AND location.latitude < '41.3249607622' AND location.longitude > '-127.154385345' AND location.longitude < '-109.657854655') AND ((IFNULL(ACOS(0.828169832503*COS(RADIANS(location.latitude))*(-0.475718165272*COS(RADIANS(location.longitude)) + -0.879597764453*SIN(RADIANS(location.longitude))) + 0.56047723284*SIN(RADIANS(location.latitude))), 0.00000)*6371396.0928) < '804673.5') ))
ORDER BY location_distance_sort ASC, location_name ASC
LIMIT 30 OFFSET 0

Returns nothing:

SELECT users.picture AS users_picture, users.uid AS uid, users.name AS users_name, users.mail AS users_mail, location.lid AS location_lid, profile_users.pid AS profile_users_pid, location.name AS location_name, 'profile2' AS field_data_field_store_hours_profile2_entity_type, 'profile2' AS field_data_field_website_profile2_entity_type, (IFNULL(ACOS(0.828169832503*COS(RADIANS(location.latitude))*(-0.475718165272*COS(RADIANS(location.longitude)) + -0.879597764453*SIN(RADIANS(location.longitude))) + 0.56047723284*SIN(RADIANS(location.latitude))), 0.00000)*6371396.0928) AS location_distance_sort
FROM 
{users} users
INNER JOIN {profile} profile_users ON users.uid = profile_users.uid
LEFT JOIN {location_instance} location_instance ON users.uid = location_instance.uid
LEFT JOIN {location} location ON location_instance.lid = location.lid
INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid
WHERE (( (users.status <> '0') AND (users_roles.rid = '6') )AND( (location.latitude > '26.8526552378' AND location.latitude < '41.3249607622' AND location.longitude > '-127.154385345' AND location.longitude < '-109.657854655') AND ((IFNULL(ACOS(0.828169832503*COS(RADIANS(location.latitude))*(-0.475718165272*COS(RADIANS(location.longitude)) + -0.879597764453*SIN(RADIANS(location.longitude))) + 0.56047723284*SIN(RADIANS(location.latitude))), 0.00000)*6371396.0928) < '804673.5') ))
ORDER BY location_distance_sort ASC, location_name ASC
LIMIT 30 OFFSET 0

Comments

mandclu’s picture

It sounds like a permissions issue. Does role 6 have permission to see longitude and latitude?

paulsham’s picture

I figured out the problem and it was my lack of understanding with the module.
We were importing the users directly into the database due to the amount and I thought we had included all the location information into the right tables, but missed the fact that the Location module calculates the latitude and longitude when you enter postal code in. Because we were going directly into the database, this calculation was not happening.

ankur’s picture

Status: Active » Closed (fixed)
raulmuroc’s picture

To work views + location (filter distance/proximity) + profile2, we should adapt the following D6 code to D7:

global $user;
$latitude = db_result(db_query("SELECT location.latitude AS latitude, location.longitude AS longitude FROM location location LEFT JOIN location_instance location_instance ON location.lid = location_instance.lid LEFT JOIN node node ON location_instance.vid = node.vid WHERE node.uid='%d' AND type='profile'", $user-&amp;gt;uid));
$longitude = db_result(db_query("SELECT location.longitude AS longitude FROM location location LEFT JOIN location_instance location_instance ON location.lid = location_instance.lid LEFT JOIN node node ON location_instance.vid = node.vid WHERE node.uid='%d' AND type='profile'", $user-&amp;gt;uid));
return array(
'longitude' =&amp;gt; $longitude,
'latitude' =&amp;gt; $latitude
);

This code is introduced under distance/proximity filter through PHP code for latitude,longitude.

Help is welcome! :-)

mikefyfer’s picture

Did you make any progress on implementing this with profile2 in D7?

Thanks

raulmuroc’s picture

Status: Closed (fixed) » Needs work

Not really and I won't have time. I am full cuz of job.

Sorry about that.

raulmuroc’s picture

Category: bug » support
Status: Needs work » Closed (fixed)

No bug to be fixed, more like a support request indeed. Just needed to port the code stated above to D7. That's just a workaround somebody must find out cleverly :-)

raulmuroc’s picture

Category: support » feature
Status: Closed (fixed) » Active

Now is correct. Hope this aims people to work harder on this issue.

damienmckenna’s picture

Category: Feature request » Bug report
Issue summary: View changes

Shouldn't "inconsistent results" be a bug? :-)