Posted on 28/11/2024 10:27:24
Setting Up Content Search in Dynamicweb 10 CMS
This guide will walk you through the process of setting up content search in Dynamicweb 10 CMS. You'll learn how to create a repository, add an index using the Content Index Builder, create a query on the index, and set up a summary field for free-text search. We'll then implement the search on a page using the Query Publisher with a Razor template that includes a search box and a list of search results. Finally, we'll explore next steps to enhance the search functionality, such as setting up spell/term suggestions and introducing filtering using facets.
1. Creating a Repository
A repository in Dynamicweb is a container that holds indexes and queries. Here's how to create one:
- Access the Backend: Log in to your Dynamicweb administration interface.
- Navigate to Repositories: Go to Settings > Repositories.
- Add a New Repository:
- Click on Add Repository.
- Enter a Name for your repository (e.g.,
ContentSearchRepo
).
- Optionally, add a Description.
- Click Save.
2. Adding an Index Using the Content Index Builder
Indexes enable efficient searching by organizing content data. To add an index:
- Select Your Repository: Click on the repository you just created.
- Add a New Index:
- Click on Add Index.
- Choose Content Index Builder from the list of available index builders.
- Configure the Index:
- Name: Enter a name for the index (e.g.,
ContentIndex
).
- Areas to Index: Select the content areas to include (e.g., pages, paragraphs).
- Fields: Define which content fields to index (e.g.,
Title
, Body
, Summary
).
- Filters: Apply any necessary filters to exclude unwanted content.
- Build the Index:
- Save your settings.
- Click Build Index Now to generate the index.
3. Creating a Query on the Index
Queries define how you retrieve and display data from the index.
- Navigate to Queries:
- Within your repository, go to the Queries tab.
- Add a New Query:
- Click Add Query.
- Provide a Name for the query (e.g.,
ContentSearchQuery
).
- Configure Query Criteria:
- Criteria: Set up conditions for filtering search results based on fields.
- Sorting: Define how results should be sorted (e.g., by relevance or date).
- Parameters: Enable user input parameters for dynamic searching (e.g.,
FreeText
for search terms).
- Save the Query.
4. Setting Up a Summary Field for Free-Text Search
A summary field allows you to combine multiple fields for full-text search.
- Edit the Index Fields:
- Go back to your ContentIndex.
- Navigate to the Fields tab.
- Add a Summary Field:
- Click Add Field.
- Choose Summary Field.
- Configure the Summary Field:
- Name: Enter a name (e.g.,
CombinedContent
).
- Included Fields: Select the fields to include (e.g.,
Title
, Body
).
- Analyzer: Choose an appropriate text analyzer for processing (e.g.,
StandardAnalyzer
).
- Save and Rebuild:
- Save the summary field.
- Rebuild the index to include the new field.
5. Setting Up the Search on a Page
Using the Query Publisher
The Query Publisher module displays search results based on your query.
- Navigate to Content:
- Select or Create a Page:
- Choose the page where you want the search feature or create a new one.
- Add the Query Publisher Module:
- In the page content area, click Add Paragraph.
- Add the Query Publisher module to the paragraph.
- Configure the Module:
- Repository: Select
ContentSearchRepo
.
- Query: Choose
ContentSearchQuery
.
- Template: Assign a Razor template (we'll create one next).
- Parameters: Map the
FreeText
parameter to a query string (e.g., q
).
Creating a Razor Template with a Search Box and Search Results
- Create a Template File:
- In your website's file system, navigate to the templates folder for Query Publisher (e.g.,
/Templates/QueryPublisher
).
- Create a new Razor (.cshtml) file (e.g.,
SearchResults.cshtml
).
- Add the Model Declaration:
- Design the Search Box:
- Display Search Results:
- Handle Pagination (Optional):
- If your query supports pagination, you can add navigation controls.
- Save the Template.
6. Next Steps to Improve the Search
Setting Up Spell/Term Suggestions
Enhance user experience by suggesting correct spellings for search terms.
- Enable Suggestions in the Index:
- Edit your ContentIndex.
- Go to the Suggestions tab.
- Enable suggestions and configure settings like Minimum Term Frequency.
- Rebuild the Index:
- Rebuild the index to include suggestion data.
- Modify the Razor Template:
Introducing Filtering with Facets
Facets allow users to filter search results by categories or attributes.
- Define Facets in the Index:
- Edit your ContentIndex.
- Navigate to the Facets tab.
- Add facets based on fields like
Category
or Author
.
- Configure Facets in the Query:
- Edit
ContentSearchQuery
.
- Under Facets, select the facets to include.
- Update the Razor Template:
- Handle Facet Selections:
- Ensure selected facets are applied to the query and results by using the URLs provided in the facet values.