DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • File Upload Security and Malware Protection
  • From On-Prem to SaaS
  • Chaining API Requests With API Gateway
  • Structured Logging

Trending

  • File Upload Security and Malware Protection
  • From On-Prem to SaaS
  • Chaining API Requests With API Gateway
  • Structured Logging
  1. DZone
  2. Data Engineering
  3. Databases
  4. Orders Search in RavenDB

Orders Search in RavenDB

Oren Eini user avatar by
Oren Eini
·
Jan. 09, 12 · News
Like (0)
Save
Tweet
Share
2.47K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Database

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • File Upload Security and Malware Protection
  • From On-Prem to SaaS
  • Chaining API Requests With API Gateway
  • Structured Logging

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: