What do you do when you find something you like? If it’s a favorite dish at a restaurant, you order it every time you go. But if this is something like a good book or a TV show, you’ll typically want to check out similar stuff to enjoy, as well. On a more serious note, if you are looking at a bug report, you might want to figure out if there have been other instances of the same issue or similar ones in the past — hopefully as you are typing the bug report.
The feature, in general, is called More Like This, and it is a nice way to smart-up your application. I’m going to use this blog as an example because More Like This usually requires a significant dataset to be meaningful. We are going to define the following index:
And configure the index to use Term Vectors as part of the indexing process:
Once this initial configuration is done, you can now go to RavenDB and ask it to suggest similar posts to an existing one. Here is how this is done:
This asks RavenDB to find posts similar to PR Review: Encapsulation stops at the assembly boundary, and the result is:
Note that you don’t have to specify an existing document, you can also send the values you want to match on directly:
And this will give you the same results!