I am trying to implement a weighted partial text search using Mongo and Spring. My Mongo documents are structured like this:
{
"_id" : ObjectId("5947d610659f8e614887cbc9"),
"_class" : "co.ecg.alpaca.model.SearchIndexEntry",
"type" : "GroupAccessDevice",
"deviceId" : "Bogus_Device",
"devicesName" : "Bogus Device",
"properties" : {
"deviceType" : "Polycom VVX 500",
"netAddress" : "",
"macAddress" : "000111222111",
"serviceProviderId" : "Bogus",
"availablePorts" : "12",
"groupId" : "Bogus_Group",
"version" : ""
},
"tags" : [
{
"tag" : "Bogus_Device",
"score" : 10
},
{
"tag" : "Bogus Device",
"score" : 9
},
{
"tag" : "000111222111",
"score" : 7
},
{
"tag" : "Bogus_Group",
"score" : 3
},
{
"tag" : "Bogus",
"score" : 3
}
],
"createdBy" : "ALPACA_SYSTEM",
"createdDate" : ISODate("2017-06-19T13:48:00.473Z"),
"lastModifiedBy" : "ALPACA_SYSTEM",
"lastModifiedDate" : ISODate("2017-06-19T13:48:00.473Z"),
"cluster" : DBRef("broadworks_cluster", ObjectId("5947d60a659f8e614887cb1a")),
"parent" : DBRef("search_index", ObjectId("5947d610659f8e614887cbb7"))
}
What I want to do is use a partial regex search against tag.name and then sort them by the tag.score multiplied by the Levenshtein distance between the regex and tag.name. My question is, is this possible to do with one Mongo query, maybe some kind of aggregation?