Facet for Guid

Vote:
 

I have an index of Product objects, each of which has a Manufacturer which has a Guid for an id. I would like to find out, for each Manufacturer, how many products it has.

I tried:

            var res = client.Search().TermsFacetFor(x => x.man.guid.ToString()).Take(0).GetResult(); 

            var hist = res.TermsFacetFor(x => x.man.guid.ToString());


But it doesn't work.

Of course if I directly save the guid as a string, it works. However, it seems like a lot of unnecessary conversion: to index the object, I convert the Guid to a string, then when get the results of a search I may have to convert the string back to a Guid. Is there a better way?

Thanks.

#150284
Jun 15, 2016 13:57
Vote:
 

You could do this:

.TermsFacetFor(x => (string)(object) x.Man.Guid)

and then

 var facets = result.TermsFacetFor(x => (string) (object) x.Man.Guid);

You'll have to convert the facet term to a guid though, but I would not worry about that.

And don't worry about the type conversion in the query. The Find framework will actually just look at the field name, which is "Man.Guid" in this case.

#150296
Jun 15, 2016 14:48
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.