Quality Assurance
[Drupal] How to create a custom Search View using the Search API, Views & Entity API ?
If you need to create a custom Search View then the Search API module is all you need to rely on. It is quite easy to create Views on search data using Search API. Read on to know how to create a custom Search View using the Search API, Views and Entity API.
Steps
- Firstly you would need to install the following modules.
1. Entity API 2. Views. 3. Database service 4. Apache Solr.
- Next you will have to add a server and node index
- Steps for adding a Server and Node index
1. To add a server, go to the configuration page of Search API module and click on Add server. 2. Next supply a name, click on enable and choose the service class that you have installed and your server will be ready. 3. Now to create a node index, there is a default node index in Drupal 7 which you can enable or click on add index & supply a name. For eg:Node index 4. Then select node from the item class. 5. Select the server that you have created from the options. 6. Click on create index. 7. Now you have to create the workflow. Click on the workflow tab. 8. Enable the URL field and all the processors and save. 9. The next step is to add the field that you need to search. 10.Click on the fields tab of the node index. 11.Mark the items that you want to be indexed and save. 12.If you need more fields you can add those by clicking on add related fields and adding those fields. 13. Now you to Reindex the site. Go to the configuration page of search settings and click on reindex button. 14. Now the fields you need are successfully indexed.
- Next we need to create a Search page
- Steps to create a Search page
1. If you want to set a search page, you need to install the Search Pages module and enable it. 2. You can set the search page by clicking on the search pages tab in search API configuration page. 3. Click on Add search page. 4. If you give a name, select the index that you create and a path for the page and your search page will now be ready 5. You can view your page by clicking on the page path.
- Now that we are ready with the indexed terms, we can create a Search View
- Steps to create a View
1. Go to Structures > Views > Add new view. 2. You have to select the node index that you have created to show. 3. You can create a page. 4. Now add the indexed fields one by one. 5. Add content type as contextual filter. 6. Select Full text as search criteria. 7. You can select unformated list , table etc as display settings. 8. Now create a path for the page. 9. Your view is ready.
Now if you want the page you had created to be displayed while you click on search's submit button you have to assign the node index's search block to a particular region and that is all there is to it.