error in ObjectReader?

Apr 22, 2009 at 10:17 AM
Hello,

I am attempting to invoke a native Lucene query using the Search extension method and consistently get a Null Reference method when I try to access the results of this query.  Stepping through a unit test in the debugger, I have verified that the number of hits is returned as expected (I have also used Luke to verify the contents of the index).  However, I have noticed that something dodgy is happening in the following code block [the MoveNext() method of the internal Enumerator class of the ObjectReader]:

          var properties = from property in type.GetProperties()
                           from fieldAttribute in property.GetCustomAttributes(typeof(FieldAttribute), false)
                           select new { Property = property, FieldAttribute = fieldAttribute as FieldAttribute };

More specifically, this always yields an Enumerable object with NO values.  My question for you is therefore, is this code block correct, and if so, can you please tell me what I am doing wrong in my application code?  Here is a snippet of what I am doing:

            IIndex<Postcode_detail> idx =
                _indexSet
                        .Get<Postcode_detail>();

            Func<Postcode_detail, LocationResult> projector =
                x => new LocationResult()
                {
                    Postcode = x.Postcode,
                    City = x.City
                };

            
            Query<Postcode_detail> query =
                idx.CreateQuery<Postcode_detail>(
                    Expression.Constant(idx)
                ) as Query<Postcode_detail>;

            
            var result =
                    query
                        .Search<Postcode_detail>(queryString, defaultLocationSearchFields)
                        .Select<Postcode_detail, LocationResult>(
                            projector
                        ).ToList<LocationResult>();

Many thanks in advance.
Regards
Alex
Coordinator
Apr 23, 2009 at 8:04 AM
Send me your unit test code and I'll look at it and give u my thoughts.

Sorry, there's not enough info there to work it out yet.

I suspect query is being translated incorrectly, or your querystring doesn't include the right fields. Could definitely be a bug, send me the entire code and I'll investigate.

Apr 23, 2009 at 7:01 PM
Hello,

I can't send the exact test since it's utilizing some Mock utilities/constructs that (unfortunately) are for internal use only at my company.  However, I can provide you with a separate set of tests that illustrate the issue further.  Hopefully, I can make these tests available for you sometime before this weekend.  In the interim, I have found a work around and will submit this fix as part of the unit tests. 

That said, please take another look at the code block from the ObjectReader that I submitted initially: 
          var properties = from property in type.GetProperties()
                           from fieldAttribute in property.GetCustomAttributes(typeof(FieldAttribute), false)
                           select new { Property = property, FieldAttribute = fieldAttribute as FieldAttribute };


- if you decorate your data classes directly with 'Field' attributes, this code will return the correct values. 
- if you define a separate Metadata class that declares the field data for the indexed class, this code will never return any properties.

Regards,
Alex

On Thu, Apr 23, 2009 at 9:04 AM, CVertex <notifications@codeplex.com> wrote:

From: CVertex

Send me your unit test code and I'll look at it and give u my thoughts.

Sorry, there's not enough info there to work it out yet.

I suspect query is being translated incorrectly, or your querystring doesn't include the right fields. Could definitely be a bug, send me the entire code and I'll investigate.

Read the full discussion online.

To add a post to this discussion, reply to this email (linqtolucene@discussions.codeplex.com)

To start a new discussion for this project, email linqtolucene@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Apr 24, 2009 at 8:02 AM
Oh, I see now!

Yeah, ObjectReader shouldn't use reflection or Type.GetProperties, it should use the AttributeReader from Mapping.

It's easy to fix, but send me the unit test when u can so it'll never happen again.
Coordinator
Apr 24, 2009 at 8:09 AM
Hmm, also. I'm not sure ObjectReader is used anymore.

I'm not certain the expression parser is being used in your scenario.

The unit test will highlight any issues
Apr 28, 2009 at 10:30 AM
Here is the unit test demonstrating the correct way to retrieve 'fielded' attributes. 

Now, if the ObjectReader is not being used, then what is the preferred way to perform a native Lucene search using this package?  From what I could tell, the only way to do so is by invoking a Search extension method on a Query object. 

Coordinator
May 1, 2009 at 9:22 AM
Hi Ax76,

Sorry, I can't see the unit test you've attached. Could you please create a work item and attach it there? I think that's the conventional way of sharing files on codeplex..

I'm very curious about this too, I'll definitely check it out

-CV
May 1, 2009 at 3:16 PM
sorry about that, have posted the work item.

On Fri, May 1, 2009 at 10:22 AM, CVertex <notifications@codeplex.com> wrote:

From: CVertex

Hi Ax76,

Sorry, I can't see the unit test you've attached. Could you please create a work item and attach it there? I think that's the conventional way of sharing files on codeplex..

I'm very curious about this too, I'll definitely check it out

-CV

Read the full discussion online.

To add a post to this discussion, reply to this email (linqtolucene@discussions.codeplex.com)

To start a new discussion for this project, email linqtolucene@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com