zoukankan      html  css  js  c++  java
  • Orders Search in RavenDB

    One of the things that we have been working on recently is our internal ordering system. We did a major upgrade on how it works, and along the way, we moved it to RavenDB. This post is to talk specifically about one feature in the system, Order Search.

    As you can probably guess, order search is something that is quite important. It is annoying to an extent, because users come to us with all sort of information about an order, from “I ordered last year some stuff” to “with order id E12312312”. The later is very easy, the former tends to be somewhat of a challenge to find.

    So I set out to try to figure out if we can do something better than just the standard gigantic search screen. For example, here is how you can search an order using Plimus:

    image

    There is way too much stuff there. Not to mention that the backend of such a screen is likely complex. Instead, I choose to go with a different metaphor:

    image

    The question is, how to do it?

    It turns out that this is really quite simple to do with RavenDB, here is the full index:

    public class Orders_Search : AbstractIndexCreationTask<Order, Orders_Search.ReduceResult> {     public class ReduceResult     {         public string Query { get; set; }         public DateTime LastPaymentDate { get; set; }     }      public Orders_Search()     {         Map = orders => from order in orders                         select new                         {                             Query = new object[]                             {                                 order.FirstName,                                  order.LastName,                                  order.OrderNumber,                                  order.Email,                                  order.Email.Split('@'),                                 order.CompanyName,                                 order.Payments.Select(payment => payment.PaymentIdentifier),                                 order.LicenseIds                             },                             LastPaymentDate = order.Payments.Last().At                         };     } } 

    And here is the UI for that:

    image

    But the question here is, how does this work?

    Well, it turns out that RavenDB has some really interesting behavior when you feed it an IEnumerable. Instead of trying to index the IEnumerable as a single value, it index that as a multi value field.

    That means that for each order, we are going to actually store the following data in the Query field:

    • Ayende  (FirstName)
    • Rahien   (LastName)
    • E11111111 (Order Number)
    • ayende@ayende.com (Email)
    • ayende (Email.Split(‘@’) first part)
    • ayende.com (Email.Split(‘@’) second part)
    • Hibernating Rhinos (Company)
    • E111111 (PaymentIdentifier for first payment)
    • E111234  (PaymentIdentifier for second payment)
    • E123412 (PaymentIdentifier for third payment)
    • EFA32826-1E09-48FA-BC0E-9A9AAF0FDD70 (LicenseIds#1)
    • 95CDDED2-2D19-48AF-991D-1284446CB7A3 (LicenseIds #2)

    Because we store all of those values inside a single field, we can query for either one of them. Hell, we can even enable full text search on the field and allow even more interesting searches.

    And the best thing, it pretty much Just Works. The user can put anything that might identify the order, and we will figure it out for him. And since the user is often me, I am very happy about it.

  • 相关阅读:
    jQuery $.each用法
    JSON.parse()和JSON.stringify()
    创建对象,初始化对象属性,给节点分派一个合成事件
    javascript 兼容W3c和IE的添加(取消)事件监听方法
    tomcat发布后项目classes下无编译文件
    纯css实现计数器效果
    js点击元素输出对应的index
    鼠标滚轮监听防“抖动”
    原生dom的querySelector、querySelectorAll方法
    spring mvc 通过url传来的参数乱码的解决方法
  • 原文地址:https://www.cnblogs.com/shihao/p/2320528.html
Copyright © 2011-2022 走看看