Incorporating Full-Text Search functionality into your application can enable users to locate what they are searching for effortlessly. Searching for specific words or phrases within a database has always been a difficulty, particularly for relational databases. Throughout my career, I've had countless discussions/arguments with DBAs about the importance of implementing full-text search in a relational database. We are in totally different times now, and users want to search by voice, image, or video.
Full-Text Search functionality is not part of Azure Cosmos DB's Database Engine. Firstly, we must establish the Azure Cognitive Search service and link the data from Azure Cosmos DB to the Search Service. The process of setting up Azure Cognitive Search is relatively straightforward. Like other Azure services, you will need to answer similar types of questions beforehand. (Subscription, Resource Group, a name for the service, region, and tier)
I selected the Basic for Tier option. You can select the Free option if you want to try it.
For optimal performance, it is recommended that you set the indexing type of your Azure Cosmos DB collection to Consistent. "Consistent" means that your data file and index file will always be synchronized. As soon as data changes, the index file changes.
When running a Query, the default setting selects all content within a document. However, it's important to note that Cognitive Search is not free, and there are storage limits for each tier level. To avoid exceeding these limits, only searchable fields in the Query should be included. In my data model, I have chosen to include only the PostId, PostBody, Title, and Tags for Cognitive Search.
You may have noticed that I utilized the IS_DEFINED function to ensure that there is a value present for the PostId property. In order for the dataset to be compatible with Cognitive Search, it must have a key field. I have designated PostId as the key field. If PostId is undefined or null, the Cognitive Search indexer cannot function properly.
The PostId property is the partition key of my Azure Cosmos DB container. I included the id property in the Azure Cognitive index, too. This means I can make a point-read call to get a document from Azure Cosmos DB. Point-Read is the cheapest way to retrieve data from Azure Cosmos DB, and you should use it as much as you can to keep your Cosmos DB requests low.
No comments:
Post a Comment