Start United States USA — software Powering Up RavenDB Indexes With NuGet Packages

Powering Up RavenDB Indexes With NuGet Packages

281
0
TEILEN

In this article, I’ll showcase how to use these two features together to index EXIF metadata on images and run ML.NET sentiment analysis offline on product …
Join the DZone community and get the full member experience. In RavenDB 5, you can use third-party NuGet packages and load binary data (or „attachments“) within your indexes without any additional code deployment necessary. In this article, I’ll showcase how to use these two features together to index EXIF metadata on images and run ML. NET sentiment analysis offline on product reviews. In traditional NoSQL or RDMS databases indexing is usually an afterthought until queries slow down. In RavenDB, you cannot query without an index which makes your app fast by default. Traditional indexes are just lookup tables. In MongoDB, the aggregation pipeline can perform Map-Reduce operations but pipelines are executed by the client code at a point in time. In contrast, RavenDB indexes can perform complex operations that combine the benefits of MongoDB’s aggregation pipeline with the power of RDMS-style queries. Since indexes are built in parallel in the background, queries respond in milliseconds even under high load. This makes RavenDB one of the fastest NoSQL databases on the market. Imagine a photo gallery web app. If you want to show the date a photo was taken, you need to read its EXIF metadata. EXIF data is stored in the image binary and follows a specific structure. In a sophisticated app, the EXIF data can be read when the user uploads the image, asynchronously, and then saved back to the database for lookup later. This is fine but it also requires application code, not to mention services to handle the queuing infrastructure. Why go to all that trouble for simple use cases? We can tackle this without any custom code in RavenDB. Follow along yourself in the Live Test Playground where anyone on the Internet can play with RavenDB and make databases. To upload a binary file, you can “ attach ” it to a document just like you would an email. In the Studio interface, I’ll add a photo document with a few fields like the photo title and description: Once the document has been created, I can attach my photo. When I lived abroad in France, I took a photo of a garden in front of a chateau in Aix-en-Provence: I’ll attach that image using the sidebar in the Studio: For storing binary files in MongoDB, you have to decide between using BinData or using GridFS. In RavenDB, you have one choice. There’s no limit to attachment file size and they are stored separately from the document so they do not affect query performance. Now, I’ll create an index named Photos/WithExifAttributes: RavenDB indexes are defined C# or JavaScript and can be queried using Raven Query Language (RQL) which supports invoking C# or JavaScript functions respectively. Since I showcase NuGet in these examples, I’m using C# indexes. This will be a Map index, meaning we load data from a document and “select” fields that we want to query on. These fields are used for filtering in “where” clauses when querying. Using the new Attachment Indexing helpers to load the list of attachments and retrieve the reference to the photo, I’ll select its file name and size to query on: This is madness! Can we just stop for a moment and acknowledge that it’s so cool we can load the photo while indexing and have full access to it? I’ll issue a query and filter by the photo title: The Studio interface can show “raw” index entries which reveal the photo filename and size: The query took 0ms since indexes are built in the background enabling RavenDB to respond to queries instantly. Now I’ll kick it up a notch. In the index definition, I will add a NuGet package under “Additional Assemblies” for the MetadataExtractor package which supports reading EXIF metadata: I added some usings needed for running the MetadataExtractor. When writing any amount of complex indexing code, you can leverage the Additional Sources feature to upload source code files like C# or JavaScript and call functions directly from the Map/Reduce operations.

Continue reading...