I want to use the SearchAPI for a Profile2-type. I performed all the changes you describe on the homepage but for some reason the location doesn't turn up in the list of "Add related fields". I can't find the reason in the code. Some help would be appreciated.

Comments

grasmash’s picture

Are you using geofield?

jschoder’s picture

No. I am using Location. But as the description is saying it should work with Location as well.

After applying all the mentioned patches I still have one issue: The "LatLong Pair" doesn't turn up since Location currently doesn't offer a LatLong-Pair. The not yet applied new patch for Location that offers Entity integration has to be expanded by adding a LatLong-Pair. I will try to add the change locally and add the patch to Location as soon as everything seems to work out.

fragtom’s picture

I've tested to make an "computed field" with location-data, but the cf-field did not appear, too.. In a other project, I used geofield for holding geo-data.. That's really comfortable, but in the moment I'm not sure to migrate location-data to geofield, because I have not enough tested with location-pattern and other stuff with the geofield..

grasmash’s picture

Yeah, I'm not sure that this module actually does work with location. I haven't seen anything in the code to suggest that it does.

drunken monkey’s picture

The module, or rather the "Latitude/longitude" data type, require a comma-separated latitude and longitude as their base data. This is currently provided by the "LatLon Pair" property of Geofields.
If Location can also produce this format, it will work, otherwise it won't.

We could think about adding a processor to convert common other formats to ours, though, to resolve this issue.

drunken monkey’s picture

Title: Location-Field doesn't turn up » Add support for the Location module
Category: support » feature
Media Crumb’s picture

You know where I stand on this one DK!

Love to see that supported.

:)

gambry’s picture

Issue summary: View changes

Not sure if work made any progress, but as issue is still active I think is still on going.

Notable quick-and-dirty solution can be found here, using as hook_search_api_solr_documents_alter():

function mymodule_search_api_solr_documents_alter(array &$documents, SearchApiIndex $index, array $items) {
  if ($index->machine_name == 'events_index') {
    foreach ($documents as $id => $data) {
      $field = $data->getField('locs_search_api_aggregation_1');
      if (isset($field, $field['value'])) {
        $data->setField('locs_search_api_aggregation_1', preg_replace('/\s+/', ',', $field['value']));
      }
    }
  }
}

HOWEVER this solution won't work for multi-values location fields and additionally it's impossible to include in any module due the UI admin action of creating an aggregate field.

Another solution could be to extend the location subfields including a LatLong pair item.
Below an example targetting a 'field_location' on node type 'event':

/**
 * Implements hook_entity_property_info_alter().
 */
function mymodule_entity_property_info_alter(&$info) {

  $info['node']['bundles']['event']['properties']['field_location']['property info']['latlon_pair'] = array(
    'type' => 'text',
    'label' => 'LatLong Pair',
    'getter callback' => '_get_field_location_latlong_pair_value',
  );
}

function _get_field_location_latlong_pair_value($item, array $options, $name, $entity_type) {
  if (isset($item['latitude'], $item['longitude']) && !empty($item['latitude']) && !empty($item['longitude'])) {
    return $item['latitude'] . ',' . $item['longitude'];
  }

  return NULL;
}

This could be easily extendible looping and updating all instances of location types (using field_read_fields(array('type' => 'location')) and then field_read_instances()) so I'm more than happy to provide a patch.

Of course it would be much simpler and better if done directly on location module. :(

drunken monkey’s picture

As said:

We could think about adding a processor to convert common other formats to ours, though, to resolve this issue.

I think this should be simple enough to implement, so if you want to give that a try, go ahead!

gambry’s picture

I think this should be simple enough to implement, so if you want to give that a try, go ahead!

I left a comment on this issue as I think the Location module should be the house for this change.

If nobody replies in few weeks I'll suggest a patch in here.

Is that ok?

drunken monkey’s picture

Yes, sounds good. Thanks!

mausolos’s picture

I cannot get this to work, with or without the patch. No matter what I do, the lat/lng field does not come up, either in the field list or the add field drop-down. I do get the Address field, but since my goal is to search via view that has/returns province, state, country and title (with each of these as an independent output field), Address is almost useless.

  • Location Search and Node Search are checked off under admin/config/search/settings (Active search modules).
  • I'm using search_api/search_api_solr talking to a SOLR 5.4.1 instance.
  • In my Search Index, I have only one Bundle/content type checked (the one for which we have all the locations entered).
  • Data alterations are: Exclude unpublished nodes, Complete entity view (view mode: Full content).
  • Enabled processors are:
    • Ignore case (Fields to run on: Title, Address, Entity HTML output)
  • HTML Filter (Fields to run on: Address, Entity HTML output)
  • Tokenizer (Fields to run on: Title, Address, Entity HTML output)
  • Highlighting (default settings, no exclusions)
 Core                                   Search (search)                                                 Module  Enabled        7.50
 Display Suite                          Display Suite Search (ds_search)                                Module  Enabled        7.x-2.14
 Fields                                 Location CCK (location_cck)                                     Module  Enabled        7.x-3.7
 Location                               GMap (gmap)                                                     Module  Enabled        7.x-2.11
 Location                               GMap Location (gmap_location)                                   Module  Enabled        7.x-2.11
 Location                               Location (location)                                             Module  Enabled        7.x-3.7
 Location                               Location Entity (location_entity)                               Module  Enabled        7.x-3.7
 Location                               Location Search (location_search)                               Module  Enabled        7.x-3.7
 Location                               Node Locations (location_node)                                  Module  Enabled        7.x-3.7
 Other                                  Search 404 (search404)                                          Module  Enabled        7.x-1.4
 Search                                 Database search (search_api_db)                                 Module  Enabled        7.x-1.5
 Search                                 Search API (search_api)                                         Module  Enabled        7.x-1.20
 Search                                 Search API location (search_api_location)                       Module  Enabled        7.x-2.0-beta2
 Search                                 Search API location views (search_api_location_views)           Module  Enabled        7.x-2.0-beta2
 Search                                 Search views (search_api_views)                                 Module  Enabled        7.x-1.20
 Search                                 Solr search (search_api_solr)                                   Module  Enabled        7.x-1.11

Location Entity was enabled from the get-go. Not sure what to do next. Any ideas? Did I miss something?

Thanks!
Charles

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new1.82 KB

This should add support for Location fields.
Modules: Location, Location CCK, Location Entity.
On the index's "Fields" page, add the location field under "Add related fields". With this patch (and possibly after clearing cache, if you just applied it) one of the sub-fields will be "Latitude/longitude pair", machine name "latlon". Use that with the "Latitude/longitude pair" Search API field type and then proceed as normal.

Please review, and I can commit!

jandewit6’s picture

Works as a charm!
Thanks very much.

  • drunken monkey committed d0a6c63 on 7.x-2.x
    Issue #1723762 by drunken monkey: Added support for the Location module.
    
drunken monkey’s picture

Status: Needs review » Fixed

Good to hear, thanks for testing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.