Is there a way to create a single exposed filter to search based on the aggregate address field data? So, you can search on city, state, and street address all in one filter? I was able to do this by setting up Search API, but I'd like to do it with a regular view so that I can utilize geofield as well. Any help would be incredibly appreciated.

Comments

Golem07’s picture

You could try the excellent Location Taxonomie module. I would but it does not support Profile or Profile2 entities (yet).

halefx’s picture

I'm in the exact same situation. Did you ever resolve this?

mrweiner’s picture

I ended up doing it with a combination of Search API and Views for now. Check out my post, #15, at https://drupal.org/node/1269608. You'll need to set up your search index (for which you can find a bunch of tutorials online) and then add all of your address field parts into an aggregate field. From there you can follow my directions in that post and use the code for a custom module to help out your search results with regard to searching for California vs. CA.

halefx’s picture

Thanks for the follow-up

mrweiner’s picture

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

Title: One exposed filter for ALL address field data? » Views filter for whole address
Category: support » feature
Status: Closed (fixed) » Active

This really seems like an obvious feature for basic views integration to me so I was surprised to find it wasn't possible.

I mean, if somebody is setting up a view that includes address data and wants an exposed "Contains" filter to allow address searching, I imagine they aren't going to want separate filters for each component of the address.

Maybe it's more difficult to implement than it sounds, but perhaps this can get some attention as a feature request.

hoff331’s picture

I agree 100%, the fact that this not out of the box is mind boggling. I switched to OpenLayers from Get_Locations on a side project just for fun... Get_locations comes with this functionality out of the box. Seems like I might switch back.

********************EDIT TO THIS STATEMENT**********************

This is SOMEWHAT possible out of the box... add an exposed filter using the field "Address:locality". It provides a text box that only works on City (ie. you cannot search country, zip, street address, etc). I assume the other fields Address:Zip, Address:Country, etc only work on their relative values.

Also, the text field is NOT case sensitive!

----

My views are set up with the openlayers master view and openlayers map page view all in the same View set. The exposed filters are set to display on all views (master, pages, blocks, etc).

morbiD’s picture

I've figured out a way of achieving this using an additional module but it makes the whole thing a lot more complicated than it should be, and requires Views 3.4 or higher:

  1. Install the views_field module.
  2. Edit your address field (admin/structure/types/manage/<content type>/fields/<field name>) and enable the new "Expose as base table" option, then in the "Columns to expose" list, select the address components you want to filter by in your view.
  3. Edit your view and add a new field for each of the address components you exposed in step 2 (you will find them under the "Field tables" group). You might want to exclude these fields from display to avoid cluttering up your view.
  4. Add an exposed filter of type "Global: Combine fields filter" with the operator set to "Contains" and in the "Choose fields to combine for filtering" list, select the fields you just added in step 3.
  5. Save your view. You should now have a single exposed filter that will perform a search on all of the address components you selected in step 4.

This seems to work for me, but it's not ideal. It would be far more user friendly for this module to supply its own filter.

Edit: I suppose an alternative to a "Whole Address" filter would be to provide fields for each address component, so that the "Global: Combine fields" filter could be used as above, without the requirement for the views_field module.

rszrama’s picture

Title: Views filter for whole address » Add a Views filter handler to perform a text search across all columns of an address field
Component: Miscellaneous » Code
Issue tags: +views

This isn't in here already because it's a non-trivial feature to add. Doesn't boggle my mind. : P

Just look at how the core Views "Combine fields filter" gets it wrong. (Hint: it only ever searches on the first column of a field, i.e. the address's country.)

I think it's a fine feature request, but I'm going to re-title it.

lmeurs’s picture

It would be super if Addressfield supported combined search in Views! +1

xmacinfo’s picture

I will try solution in #8.

But I also agree that Addressfield should be more friendly to Views exposed filter.

xpersonas’s picture

This was a shock for sure. #8 saved me. Views Field module is awesome!

gettysburger’s picture

I tried #8 and it worked great for me except for the State (administrative) field. Any ideas? I even tried the Sub Administrative Area.

rszrama’s picture

Did it not work for you w/ State because you were searching by the full name? Bear in mind the Views filter is searching data, and States would actually be stored as abbreviations.

gettysburger’s picture

Thanks. Yeah, it was the state abbreviation that got me.

rszrama’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Now that #991834: Address component Views support has landed, I'm not sure we need to do anything else here, do we? I created a local test that added the individual address components I wanted to search on as hidden fields, and I was able to create an exposed filter that combined the values of those Views fields for filtering the result set. Worked as expected, though as mentioned above, you have to watch out for administrative area abbreviations vs. full names.