Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Specify document return order
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Hannes Johansson  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 7:13 am
From: Hannes Johansson <wishpi...@gmail.com>
Date: Wed, 30 May 2012 04:13:12 -0700 (PDT)
Local: Wed, May 30 2012 7:13 am
Subject: Specify document return order

I want to order a set of documents based on a property that is set by an
external system at runtime, when querying RavenDB. That is, I want to do
something like the following:

var resultFromService = service.GetResultOrderedExternally();

var query = _session.Advanced.LuceneQuery<ResultType>("BigIndex")

 .OrderByDescending(x => x.Id == resultFromService.First().Id);

foreach (var result in resultFromService) {

         var id = result.Id;

    query = query.ThenByDescending(x => x.Id == id);

}

var orderedQueryResult = query.ToList();

But surely, there must be a prettier and more effiecient way to do this?
The key issue here is that I can't index the property I want to sort by
since I don't have it when the index is built.

Cheers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 7:21 am
From: Matt Warren <mattd...@gmail.com>
Date: Wed, 30 May 2012 04:21:07 -0700 (PDT)
Local: Wed, May 30 2012 7:21 am
Subject: Re: Specify document return order

You can only order the results by a value that is indexed, so you would
have to add a field into the index (with the ordering from
the external service) to make this work. This is because the ordering is
done by Lucene as part of the query and it only has accessed to indexed
values.

If this isn't possible (which seems the case) then you have to do something
like the workaround you propose.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 8:05 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Wed, 30 May 2012 15:05:18 +0300
Local: Wed, May 30 2012 8:05 am
Subject: Re: [RavenDB] Re: Specify document return order

Note that this workaround won't actually work, you can only index by items
that are in the index, nothing else.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hannes Johansson  
View profile  
 More options May 30 2012, 11:56 am
From: Hannes Johansson <wishpi...@gmail.com>
Date: Wed, 30 May 2012 08:56:33 -0700 (PDT)
Local: Wed, May 30 2012 11:56 am
Subject: Re: [RavenDB] Re: Specify document return order

Yes, sorry, it was probably not apparent from the code snippet, but the
idea is that the external service has returned the result ordered by the
desired field, and then I pick the "Id" property, which is indexed in
Lucene and sort the whole result based on whether or not a product matches
that Id property.

This would of course mean that I will have to order the whole thing a
linear number of times, which is not exactly desirable, but I see no other
workaround. It was, however, surprisingly fast, and landed somewhere around
140 ms for 30k documents on my local machine.

Den onsdagen den 30:e maj 2012 kl. 14:05:18 UTC+2 skrev Oren Eini:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options May 31 2012, 5:36 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Thu, 31 May 2012 12:36:54 +0300
Local: Thurs, May 31 2012 5:36 am
Subject: Re: [RavenDB] Re: Specify document return order

That won't actually work.
You are basically doing a sort by id, and we collapse it all to a single
.OrderBy(x=>x.Id)

You can't do ordering by an external field, because you have to be able to
compare all values to all other values.
There _are_ ways to do that, but they are complex & slow.

What is the actual scenario that you are trying to use?

On Wed, May 30, 2012 at 6:56 PM, Hannes Johansson <wishpi...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hannes Johansson  
View profile  
 More options Jun 1 2012, 9:27 am
From: Hannes Johansson <wishpi...@gmail.com>
Date: Fri, 1 Jun 2012 06:27:39 -0700 (PDT)
Local: Fri, Jun 1 2012 9:27 am
Subject: Re: [RavenDB] Re: Specify document return order

Actually, this appears to work, but doesn't scale beyond a few thousand
documents.

var ordered = result.OrderByDescending(x => x.ProductId == 3000);
for (int i = 2999; i >= 0; i--)
{
 int closureCopy = i;
 ordered = ordered.ThenByDescending(x => x.ProductId == closureCopy);

}

                var res =  ordered.ToList();

The scenario is this:
I get a result from an external system, this result contains document Ids
for RavenDB and live pricing information which cannot be stored in ravendb.
What I want to do then is to fetch these ids in a particular order,
determined by the pricing. I will also do paging on the result, which is
why I cannot sort it after fetching it from RavenDB.

I've pondered taking apart the result from the external service and doing
the paging myself before fetching the result from RavenDB, but I was hoping
for a cleaner solution using the db. Do you see any possible solutions?

Den torsdagen den 31:e maj 2012 kl. 11:36:54 UTC+2 skrev Oren Eini:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile  
 More options Jun 1 2012, 9:40 am
From: Matt Warren <mattd...@gmail.com>
Date: Fri, 1 Jun 2012 06:40:38 -0700 (PDT)
Local: Fri, Jun 1 2012 9:40 am
Subject: Re: [RavenDB] Re: Specify document return order

If you have the ProductID (from the external service) in the correct order,
you can just load them directly by doing this:

     var listOfIDs = new [] { "product/5", "product/1", "product/18", ..};

   var products = session.Load<Product>(listOfIDs)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hannes Johansson  
View profile  
 More options Jun 1 2012, 10:19 am
From: Hannes Johansson <wishpi...@gmail.com>
Date: Fri, 1 Jun 2012 07:19:47 -0700 (PDT)
Local: Fri, Jun 1 2012 10:19 am
Subject: Re: [RavenDB] Re: Specify document return order

Yes, this does actually seem to be working for my scenario, I was not aware
that the documents would return in order. Thank you both very much for your
time!

Den fredagen den 1:e juni 2012 kl. 15:40:38 UTC+2 skrev Matt Warren:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Warren  
View profile  
 More options Jun 1 2012, 10:24 am
From: Matt Warren <mattd...@gmail.com>
Date: Fri, 1 Jun 2012 07:24:35 -0700 (PDT)
Local: Fri, Jun 1 2012 10:24 am
Subject: Re: [RavenDB] Re: Specify document return order

Yeah it returns them in the same order that the ID's are specified in, also
it will insert a null if the doc doesn't exist. This is so you know which
docs were loaded and you can match them up to the list of ID's you supplied.

Glad it worked.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »