1

I am using SearchAPI on a website with 20,000 entities indexed. Searching through them with SearchAPI is pretty simple. Its fast. I want to keep it as fast as possible with very low overhead, without using Views.

I've created the appropriate code needed to create a form, blocks, and a page callback via a custom module. What I would like to do is have someone use a custom search form, hit submit, and be sent to the search results page callback.

What is the best way to store and read from form values in a page callback? Is there any way to have values persist outside of $_SESSION? Or is that the best method? If I wrote a method in my search class that inspected $_POST and did proper validation on it, would it be better to use that to keep executing a search based on that?

I already have paging methods worked out in the code, but kind of scratched my head on how to execute a form, then when using a pager, keep those values for querying the next set. I think I am close, but wanted some input if there is a way I am not seeing.

2
  • Just wondering why you are trying to write your own custom code to create a form, block, page callback etc, and not using drupal.org/project/search_api_page that will do all of this for you?
    – user842
    Oct 18, 2012 at 14:43
  • Because I want to search by multiple fields, not just one. It's not just a general text search, I want to have 5-9 different fields to search by. I also want control over the form, and its placement on the page, the labels, etc. I want the search in the sidebar wherever I want to display it. I don't want a search form at the top of the search page itself. Also, it isn't outputting a pager, and I want to theme the results page, the result itself, result counter, and show filters. Also, its loading entities from the database- I am using cached HTML of SearchAPI.
    – Kevin
    Oct 18, 2012 at 15:29

1 Answer 1

0

Realized I never added a follow up. Search API Page does not solve all the cases, and this is possible in Drupal 8 as well.

A query string was added on form submission, redirecting to my url + query string args. These prefill form values (sanitized of course) and modify the initial Search API query. Extra work was done to store some data in session, so that the query could be repeated on detail pages for sidebar results (prev/next navigation in the same result set).

Using the normal Drupal pager worked fine as well.

As part of this work, a module was born: https://www.drupal.org/project/search_api_view_modes

Here is an example of doing it in Drupal 8: https://gist.github.com/kevinquillen/cad07541347385744b161a26690ab75d

Taking this route allows you to create and provide a very tailored, controlled experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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