
As site visitor I want to be able to search documentation pages based on when they were updated, topics, title, and free text search. I also want to be able to sort the results by relevance, updated time or number of comments. This is important because it helps me find the documentation I am looking for.
How to Demo:
- As anonymous visitor, verify that you can find a link extended search on the website.
- At the resulting page, verify that there are search fields for topic, title and free text, as well as a way to show only pages that have been updated since a given date. There should also be controls to change sort order between search relevance, updated time and number of comments.
- Verify that each of these search criteria work individually.
- Verify that the sort criteria search relevance work, by searching for a word appearing both in titles and bodies on the website – documentation pages with the search phrase in the title should appear first.
- Verify that the other sort criteria work.
- Verify that the search results have links leading to the relevant documentation page.
Required Preparations:
The site should have a documentation content type, as provided by the first exercise in this suite, as well as topic tags as provided by the exercise in the taxonomy chapter.
Additional Comments:
- If you have done the exercise recently updated documentation pages in the previous chapter, the search page could be implemented as an additional page display rather than a completely separate view.
- If you have just recently created content, you may need to run cron before it appears in the search. (See other settings in the other basic Drupal core settings chapter.)
- The exposed filter for topics could use the reduce duplicate setting, preventing content from appearing more than once – which could be the case if you search for two topics and a documentation page has both these. Another option would be to enable the distinct setting – which would provide the same effect for the view as a whole. This is found under the query settings in the advanced section.
- The user story doesn't say that the results should be presented in a table. Usually, search pages result is something similar to a teaser list – which could be implemented in this case too. However, when doing advanced search it also makes sense to present a lot of information condensed into a table.
- Users who are not logged in have no use of the column marking if content has been updated since last viewed – Drupal doesn't keep track of anonymous visitors' page views in the same way as logged in users.
- All the search forms and sorting settings make the extended search page appear quite messy. In a real project, this would most likely lead to a new user story with the objective of making it easier to overview all the options.
Modules:
Additional Resources:
Downloads:
| Attachment | Size |
|---|---|
| 3.7 KB |
Suggested Solution:
- Add a new view. Give it the name extended search, and have it list content of type documentation page. (See creating new views in the Views basics chapter.)
- In the quick-wizard, also add a page display, showing 25 results with a pager, in a table of fields. Finally also add a menu link in the navigation menu. (See creating new views.)
- In the main configuration panel, add view fields that seem reasonable to display with search results – see the recently updated documentation pages exercise in the previous chapter for suggestions. Make sure to include page title, linked to the documentation page. (See adding view fields in the Views basics chapter.)
- Add three new filters, and mark all three as exposed – content: has taxonomy terms (limit to topic vocabulary), content: title (operator contains), and search: search terms. Provide them all with labels that makes it clear to end users that they are search fields. (See settings for exposed filters in chapter 10.)
- Add yet another filter, content: updated date and set the operator to greater than or equal to, in order to display pages updated at the given date or later. (See settings for exposed filters.)
- Remove the existing sort criteria. Add three new criteria, all exposed – search: score, content: updated date, and content: comment count. Set the default sorting to descending in each case, and change their labels to make it clear to end users what each sorting represent. (See settings for exposed sort criteria and pagers in chapter 10.)
Solution Video: