-
Notifications
You must be signed in to change notification settings - Fork 0
Search
The search module included in the base-build is a custom module that includes dependencies and modules to get you up and running with search.
- You have installed Drupal using the BC base-build.
- You are logged in with an account that has administrative access to the site.
- go to
/admin/modules
- in the search box, search for
bcbb_search
- check the box to the left of
bcbb_search
- Scroll to the bottom of the page
- click Install
TIP: If you have access to the command line, you can install by typing
drush en bcbb_search
from the directory containing your project
On a content type, there is a display mode available to store the fields you want indexed in a search.
- Go to
/admin/structure/types/manage/my_content_type
- Click the tab that says Manage display
- Scroll to the bottom of the page
- expand Custom display settings
- select Search index, 3. click save.
- specify the fields you want indexed in search
- select the Search index display
- move fields you do not want indexed to the Disabled section.
- save
For search to work, a database server needs to be configured. By default, Drupal will create a default search DB. For small projects, you can leave this alone. For large projects, it is best to use an external search DB such as SOLR and connect your Drupal project to it.
Note: If you start with a default Drupal DB server, then switch over to Solr, go to
/admin/config/search/search-api/index/default_index/processors
, look for processors with the comment "It is recommended not to use this processor with the selected server.", de-select them and save.
- Go to
/admin/config/search/search-api/index/default_index/edit
- Under Datasources choose the source you want to index, usually this will be Content
- Under Configure the content datasource, choose the bundle you want to index. This will be a list of content types.
Note, If you have additional datasources, you will have the option to configure them here. For example, if you chose Taxonomy term as a datasource, you will see Configure the taxonomy term datasource.
- save
Manage the search fields at /admin/config/search/search-api/index/default_index/fields
- In the General section, click edit in the operations column
- Select the user role to be used in the rendering of the HTML. The most common is Anonymous user which would render the HTML as if it were being viewed by the anonymous user.
- In View mode select Search index. This is the view mode you created earlier and contains the fields you want indexed.
- Do this for each of your content sources
- save
By default, the BC base build will come with a search view. This view should contain fields to be displayed in search results, along with any field to be used as a facet. Hide a facet field if you do not want it to display in the search results.
-
Go to
/admin/structure/views/view/site_search
-
Add Search: Excerpt as a field. The excerpt is displayed when people search for keywords.
Note: Because of the way Views renders individual fields, if a single search item is to have further HTML structure, it is easier to hide all the fields and then use a Custom text field to structure the results. The default search view is structured this way and the Global: Custom text field is rendered in the view. The Global: Custom text field uses tokens of the fields
{{ field_name }}
to determine the final render. This field can only render fields that appear before it. We recommend keeping at the bottom of the field list. -
If there are certain fields that are used as a facet source, add them as fields in this view. They are the required source of the facets you will configure.
- The filter Search: Fulltext search (the keyword filter) is exposed to the user
- The sort criteria is the Relevance. If date is an important aspect of order, it is better to boost a date field in search settings and leave the view sort as relevance.
- The Header contains the results summary that you see at the top of the search page
Once the search view is complete, fields defined in that view can be used as facets.
- Go to
admin/config/search/facets
- Click add facet
- Under Facet source choose View site search, display block
- Choose the field in that view to be used as a facet
- The value entered the Name field will display in the facets column on the search page.
- Save
Once you save a facet, the configuration page opens for the facet you just created.
- The widget should be a list of links, ensure that show the amount of results is selected.
- if the facet will contain a large number of results, limit it by using the Soft limit option
- Note: do not set the reset link as these will be controlled by the facet summary
- If the facet is a hierarchical taxonomy vocabulary, and that hierarchy needs to be maintained, select Build hierarchy tree
- if there is a dependancy on another facet, choose Dependent facet to configure which other facet controls the appearance of this one
- Choose Date item processor for date facets to ensure proper date functionality
- For taxonomy vocabulary facets, select Transform entity ID to label or only the TIDs will display
- Set the “Operator” to
AND
. This is typical behaviour for facets to narrow search results. Use cases will vary, but most of the timeAND
is the preferred operator. - Save
- go to
/admin/config/search/facets
and validate that you see the facet you created in the list
- go to
admin/config/search/facets
- in the operations column, select
edit
ordelete
There are many ways to build a search page in Drupal. The default method used by the base-build is to use a custom panel page. With this approach, each of the individual blocks, facets, summaries, and other items can easily be placed and themed.
- Go to
admin/structure/page_manager/manage/site_search/general
- Under Variants on the left, click Search site to expand it and click on Content
-
Exposed form: site_search-block_1 is enabled by default. This is the exposed filter from the view. If it is missing, or if you need to add a different search block:
- Select Add block
- Select the block you want to add, most likely in the Views section
- Select add block
- Current search filters are available by default this is the facet summary. You can remove them, replace them or add another block.
- Add the search results view. This is the view you previously configured. by default, it will be
views_block:site_search-block_1
- By default, the
bcbb_search
module includes the Conent type facet. Add facets you have created by:- Select Add block
- Select the facet block you want to add, it will be in the Facets section
- Select add block
- Select Update and save at the bottom of the page.
Note: while you are working with the content section of the variant, you will see regions Top, Left and Right. These are the regions as displayed on the search results page. Moving blocks between regions will affect where they display on the search page.