Linq search with transformer returning incorrect results.

26 views
Skip to first unread message

cutting chai

unread,
Mar 27, 2015, 5:09:53 PM3/27/15
to rav...@googlegroups.com
I have a collection called users which stores my user documents. Recently I moved to using transformers for my results and now my search is broken. 

Transformer definition is as below: 
public UserTransformer()
        {
            this.TransformResults = users => from user in users 
                                             let userId = user.Id.ToString().Replace("users/", string.Empty)
                                             let client = user.ClientId.HasValue ? this.LoadDocument<DataObjects.Client>("clients/" + user.ClientId.Value) : null
                                             select new
                                                        {
                                                            Id = userId,
                                                            user.EmailAddress,
                                                            user.FirstName,
                                                            user.LastName,
                                                            user.LastLoginDate,
                                                            user.PhoneNumber,
                                                            user.IsActive,
                                                            user.IsVerified,
                                                            user.Role,
                                                            user.IsAutoBilled,
                                                            user.IsInvoiceEmailed,
                                                            user.LogoUrl,
                                                            Client = client != null ? new
                                                                                          {
                                                                                              Id = user.ClientId.GetValueOrDefault(), 
                                                                                              client.OperatingName,
                                                                                              client.LegalName,
                                                                                              client.LogoUrl
                                                                                          } 
                                                                                          : null
                                                        };
        }

Search is as below: 
var users = this.work.Query<User>();

            switch (this.Role)
            {
                case Constants.Role.Merchant:
                    users = !this.Client.Customers.IsNullOrEmpty() ? 
                        users.Where(x => x.ClientId == this.ClientId || x.Id.In(this.Client.Customers)) : 
                        users.Where(x => x.ClientId == this.ClientId);
                    break;
                case Constants.Role.User:
                    users = !this.User.Customers.IsNullOrEmpty() ? 
                        users.Where(x => x.Id.In(this.User.Customers)) : 
                        users.Where(x => x.Id == this.UserId);
                    break;
            }

            return users.TransformWith<UserTransformer, UserDetail>();

Here is the traffic log from ravendb: 
http://localhost:8080/databases/ronin/indexes/dynamic/Users?&query=ClientId:1 OR %40in<__document_id>:(UserDetails%2F33%2CUserDetails%2F34) &pageSize=0&resultsTransformer=UserTransformer

Query: ClientId:1 OR @in<__document_id>:(UserDetails/33,UserDetails/34) 
Time: 7 ms

The index: 
from user in docs.Users
select new {
Id = user.__document_id,
ClientId = user.ClientId,
CreatorId = user.CreatorId,
EmailAddress = user.EmailAddress,
IsActive = user.IsActive,
IsVerified = user.IsVerified,
PasswordResetToken = user.PasswordResetToken,
VerificationId = user.VerificationId
}

Now the keys for user documents are users/33 and users/34 but it is looking for userdetails/33 and userdetails/34. I assume this is what breaks the search. How can I fix the issue? Also, it seems to not be using the index. Do I have to name the index in the query clause?

Tal Weiss

unread,
Mar 27, 2015, 5:57:58 PM3/27/15
to rav...@googlegroups.com
Hi,
regarding the indexing if you want to run on top of an index you either provide the name of the index to the Query(<index name>,<is mapreduce>) or you provide the type of the index creation task.
Query<User,UserIndex>()
try to run the query ontop of the index and see if this resolve the issue.
If not look for the documents that have those ids: UserDetails/33,UserDetails/34 check if the somehow got in their metadata Raven-Entity-Name : "User" (shouldn't happen but worth checking...)

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Tal Weiss l Core Team Developer Mobile:+972-54-802-4849

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/ 

cutting chai

unread,
Mar 27, 2015, 6:05:13 PM3/27/15
to rav...@googlegroups.com
Metadata

Raven-Entity-NameUsers
Etag01000000-0000-0001-0000-00000000000F
Last-Modifiedan hour ago (27/03/2015 20:45 (UTC))
Size in KB0.87

The metadata is as above. Specifying the index name didn't change much except that the query used the named index. The results remain unchanged. What seems to be happening is that it is using the 
users.TransformWith<UserTransformer, UserDetail>();

to decipher the document id string and hence looking for userdetails/33 and userdetails/34 which causes those documents which are users/33 and users/34 to not be returned. 
Reply all
Reply to author
Forward
0 new messages