28 January, 2022 seen 665This is an article back from 2014, when I had the vision to launch a web agency in Tbilisi, Georgia. In the end, I didn…
Default Drupal search function is pretty much OK, but if you are looking for ways to control and extend search behavior - you are stuck with out of box search.
I'll show you how you can boost your search functionality, by using just two (OK, three modules)
Download following modules:
Download and extract them into sites/all/modules folder
Enable Database search, Search API and Search views
Now we must add a search server and search index.
Let's start with Search server.
- Go to admin/config/search/search_api
- Click on Add server link
- Give it a name - I prefer to call it as DB Server, if you wish, you can enter Server description. Under dropdown from Service class chose Database service. Click Create Server.
Now go back to admin/config/search/search_api - you should see - your newly created server as enabled, and index as disabled.
- Click on the Edit button for Default node index.
- You must click check box next to Enabled button, and under Server, you must choose our newly created Server which we called DB Search (if you called it other way - you should see that name under drop down box). Click Save settings.
We are almost there - before indexing items, as it will appear in next window, after you will click Save settings, let's add some fields to index.
- Go to admin/config/search/search_api/index/default_node_index/fields
If you have made some custom changes to your Drupal site, like added custom fields, taxonomies e.t.c. and you would like them to be indexed in your search server - this is the place were to add fields to search index. If you are OK with default (Title and body) leave settings intact.
Now let's index our nodes. You should configure cron, so items are indexed automatically, but if you want manually index your search server, go to admin/config/search/search_api/index/default_node_index
- Click on Index now button to index 50 items, repeat it, so all your content is indexed, if you have too many nodes, use cron job.
Now we are ready to build our Search page.
Create a new View
Admin > Structure > Views > Add new view
- View name: Search
- Show: [the name of the Search index] (in the case of Default node index the default is "Default node index")
- Create a page [tick]
- Page title: Search
- Path: search
- Display format: Unformatted list of Fields
- Items to display: 10, use pager
Continue & edit (the new View)
Format: Show: Fields | Settings
Fields: Title, Body
- Fulltext search: Expose this filter, Required, Remember the last selection, Use as: search keys
- Indexed Node: Status: Operator: Is one of, Value: Published
- Search: Relevance, descending (if you don’t have an order with fuzzysearch you will get a PDO exception)
- Access: Permission: view published content
- No results behavior: Global: Text area “No results matched your search.”
- Exposed form in block: Yes
- Exposed form style settings: Submit button text: Search
Save the View. Add the exposed form block to a region.
Note that you will only receive results for partial matches that are longer than the minimum word length specified in the Index configuration.
It's up to you now, how are you gone to format display of your views page. As extra you could add Facets to be displayed on sidebar as well.
Here is the final search results page I made for this site: https://www.reinisfischer.com/do_search?keyword=yerevan