1

I'm trying to create "Search API widget" using two exposed filters "search: Full text" + "taxonomy term: City"

The good example of what I want to achieve would be visible here:

http://olx.in/

Whenever you type in the city + full text search it generates the url such as:

http://olx.in/city-name/q-something/

However if I use exposed filters it doesnt seem to work in that way it creates links like this:

http://localhost/search?search_api_views_fulltext={something}&field_city={taxonomy-term-id}

When after I do the search I use facet filter with pretty paths it gives a bit better result:

 http://localhost/search/field_city/{name_of_region}/field_city/{name_of_region}/field_city/{name_of_sub_region}/field_city/{name_of_region}/field_city/{name_of_sub_region}/field_city/{name_of_city}search_api_views_fulltext=&field_city=1031

But I want the end result pretty much to look like this:

http://localhost/{name-of-city}/search-something

And after searching I want it to activate proper facets for the "field_city" so if after searching someone would want to add facet it would not create a {field_city}/{field_city}

And in order to do that, I was considering instead of using a "exposed taxonomy term filter" to use facet block for "Field_city" but no luck so far.

** Update 01.10.2015 **

I was doing research and I think that the "cities" and "categories" on OLX or any other decent portal are not actually facets or exposed filters, but they are Taxonomy pages with inherited search query.

  1. So if someone types in "Exposed full text search api" a "Yorkshire terrier"
  2. He is redirected to: http://localhost/search?search_api_views_fulltext={Yorkshire terrier}
  3. And on left sidebar he have "Taxonomy menu block" with vocabularies of "small ads categories" with terms such as "animals"
  4. He clicks on "animals" term and the search value follows him.
  5. http://localhost/small-ads-categories/animals/search?search_api_views_fulltext={Yorkshire terrier}
  6. Of course the taxonomy is a search api view
  7. However I also would want to extend this by adding a second parameter which is "city" <- not sure how to do that

Another feature that I'm trying to figure out how to create a "select box" for a city that is not a exposed filter but a link parameter.

For example: if someone wants to search for: Yorkshire Terrier + he selects locations from select box to be: London

Normally it is done by creating exposed taxonomy filter - however it generates ugly url, the thing that I'm considering is using the value that is selected to redirect user to the proper search results page. so if he selects Yorkshire Terrier in london he is redirected to:

http://localhost/london/search?search_api_views_fulltext={Yorkshire terrier}

Where london is also a taxonomy search api url.

** update: few hours later **

After further thinking and trying to solve this issue, using taxonomy terms view block seems like a good idea, but it displays ALL possible terms not only the terms that are related to current search query and that I'm not sure how could I limit ?

1

This module should help you getting rid of ugly URLs when using exposed filters: https://www.drupal.org/project/query_parameters_to_url

...

An example of a dirty URL like that could be: example.com/events?field_category_id[0]=100&field_category_id1=101&field_author_name[0]=John

Using this module you can transform the URL into: example.com/events/p/field_category_id/0__100--1__101/field_author_name/John

Or an even shorter URL if you use the provided alter hooks: example.com/events/p/cat_id/0__100--1__101/name/John

Isn't that a joy to look at?

...

Please refer also to this question to achieve the same thing writing your own module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.