In the previous videos, we have created servers and an index, and we have indexed our data. But we can't use the search yet because we haven't setup a search page, which is the last thing we need to do in order for users to search our site. We can create search pages using the Search API Pages module which creates simple and fast search pages or by using the Views module which offers its flexibility to create customizable search pages. In this video, I will show you how to create a search page using Search API Pages and walk you through its features. In the next video, we'll use Views to create a search page.
- Go to "Modules" (admin/modules) and enable:
- Search pages
- (Save Configuration)
Now that we have installed and enabled Search API pages, we can create a search page.
Create Search Page
- Go to "Configuration = > Search and Metadata => Search API => Search pages => Add search page" (admin/config/search/search_api/page/add)
- Search name: Search (This will be the page title of the search page.)
- Index: Node index (This determines which index this search will be based on.)
- [x] Enabled (This will make the search page accessible to users.)
- Search description: (Optional, I'll leave it blank.)
- Path: search-page (Specifies the path where the search page will be accessible.)
- (Create page)
Search Page Settings
This page give you options to configure how the search is executed and how results will be displayed.
- Query type: Multiple terms
- "Direct query" sends the unparsed keywords directly to the search server and allows the server to decide how to handle the search.
- "Single term" searches for items containing the keywords as a phrase, exactly as entered.
- "Multiple term" searches for keywords containing each of the entered words, for example, if I were to enter Modules Unraveled as keywords, it will search for items containing both the words "Modules" and "Unraveled". Quoting phrases with double quotes is allowed, so ""Modules Unraveled" Search Api" would return results that contain the phrase "Modules Unraveled" and the words "Search" and "API". This is the option that most users will expect.)
- Search fields: (This allows you to limit the fields that will be search to only those selected. If no fields are selected, all available fulltext fields will be searched.)
- Results per page: 10 (This specifies the number of results per page.)
- Allow GET override: (If checked, this will allow the user to override the results per page using the "per_page" parameter as in the example "?per_page=7".)
- [x] Show search form on result page (Enables the search form on the result page)
- View mode: (This allows you to decide how results should be displayed. I'll leave it set to "Themed as search results".)
- (Create page)
Finally, in order for users to be able to access the search functionality, we need to give them permission.
- Go to "People => Permissions"
- Scroll down to Search
- Grant "Access search pages" permission to:
- [x] Anonymous user
- [x] Authenticated user
- (Save permissions)
So, now if we go to "/search-page" we can test out the search.
Search API page also provides a search block to start a search from anywhere on the site. So let's enable and display the search block in the first sidebar.
Display search block in the sidebar
- Go to "Structure => Blocks" (admin/structure/block)
- Scroll down to the Disabled section
- Block: Search block: Search
- Region: Choose "Sidebar first"
- (Save blocks)
Now, when we go to the home page we'll see that we have the another search form in the first sidebar entitled "Search". In the search text box, enter the keywords that you want to search and click the "Search" button. As you see, we are redirected to the results page where it shows all content that matches the keywords that we've entered. It'll also show the number of results found and the time it took to perform the search.
If you've been using Drupal for any time at all, you probably already have experience with the Views module. Search API integrates with Views to let you create a custom search page that's more flexible than those offered by the Search API Search Page module. So, in the next video we'll create a search page using the Views module to see what it offers.