x2find / Nested2Find

Adds nested filtering to EPiServer Find's .NET API
4 stars 5 forks source link

Nested types cannot be found #1

Closed royosherove closed 9 years ago

royosherove commented 11 years ago

Hi. We have some code that would perfectly match this scenario, but maybe we are doing something wrong, or maybe there is a bug. we do not know. We have a CourseDetailsPage , that has sub pages of type CourseDateInfo (Each course has many dates). We try to run a query like this:

private IEnumerable DoSearch(string q, string qMonth, string qCategory, string qLocation) { var result = new CourseResult(); var client = SearchClient.Instance; client.Conventions.ContractResolver.ObjectContractInterceptors.Add(new IncludeTypeNameInNestedFieldNamesInterceptor()); client.Conventions.FieldNameConvention = new NestedFieldNameConvention();

        DateTime qDate = DateTime.Parse(qMonth);
        var dateResults = SearchClient.Instance.Search<CourseDetailsPage>()
                                      .For(q)
                                      .Filter(
                                          page =>
                                          page.Dates.MatchItem(d => d.CourseLocation.MatchCaseInsensitive(qLocation)))
                                      .GetResult();

        return dateResults;
    }

and this is the impl of the Dates property on the COurseDetailsPage:

public virtual List Dates { get { return GetDates().ToList(); } }

and we keep getting the error:

[WebException: The remote server returned an error: (500) Internal Server Error.] System.Net.HttpWebRequest.GetResponse() +8522892 EPiServer.Find.Connection.JsonRequest.GetResponse() +210 EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +131

[ServiceException: The remote server returned an error: (500) Internal Server Error. SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[g0-OSD1wQISzZnCph0MP3A][saandahl_bouvetno][0]: RemoteTransportException[[Burstarr][inet[/10.3.98.11:9300]][search/phase/query]]; nested: SearchParseException[[saandahl_bouvetno][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"query_string":{"query":"csm"}},"filter":{"nested":{"path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"_types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]]; nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }{[du1B8cSBRUWIrZY2xMYxCQ][saandahl_bouvetno][1]: SearchParseException[[saandahl_bouvetno][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"querystring":{"query":"csm"}},"filter":{"nested":{"path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]]; nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }]] EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +883 EPiServer.Find.Api.SearchCommand`1.Execute() +634

lindstromhenrik commented 11 years ago

Hi,

Make sure that you have indexed pages with nested objects as the 'mapping' will be added dynamically when the first object of the specific type is indexed.

Regards, Henrik

Skickat från min iPhone

25 jan 2013 kl. 14:42 skrev Roy Osherove notifications@github.com:

Hi. We have some code that would perfectly match this scenario, but maybe we are doing something wrong, or maybe there is a bug. we do not know. We have a CourseDetailsPage , that has sub pages of type CourseDateInfo (Each course has many dates). We try to run a query like this:

private IEnumerable DoSearch(string q, string qMonth, string qCategory, string qLocation) { var result = new CourseResult(); var client = SearchClient.Instance; client.Conventions.ContractResolver.ObjectContractInterceptors.Add(new IncludeTypeNameInNestedFieldNamesInterceptor()); client.Conventions.FieldNameConvention = new NestedFieldNameConvention();

    DateTime qDate = DateTime.Parse(qMonth);
    var dateResults = SearchClient.Instance.Search<CourseDetailsPage>()
                                  .For(q)
                                  .Filter(
                                      page =>
                                      page.Dates.MatchItem(d =>

d.CourseLocation.MatchCaseInsensitive(qLocation))) .GetResult();

    return dateResults;
}

and this is the impl of the Dates property on the COurseDetailsPage:

public virtual List Dates { get { return GetDates().ToList(); } }

and we keep getting the error:

[WebException: The remote server returned an error: (500) Internal Server Error.] System.Net.HttpWebRequest.GetResponse() +8522892 EPiServer.Find.Connection.JsonRequest.GetResponse() +210 EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +131

[ServiceException: The remote server returned an error: (500) Internal Server Error. SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[g0-OSD1wQISzZnCph0MP3A][saandahl_bouvetno][0]: RemoteTransportException[[Burstarr][inet[/10.3.98.11:9300]][search/phase/query]]; nested: SearchParseException[[saandahl_bouvetno][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"query_string":{"query":"csm"}},"filter":{"nested":{"path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"_types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]]; nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }{[du1B8cSBRUWIrZY2xMYxCQ][saandahl_bouvetno][1]: SearchParseException[[saandahl_bouvetno][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"querystring":{"query":"csm"}},"filter":{"nested":{" path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]]; nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }]] EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +883 EPiServer.Find.Api.SearchCommand`1.Execute() +634

— Reply to this email directly or view it on GitHubhttps://github.com/x2find/Nested2Find/issues/1.

royosherove commented 11 years ago

The objects seem to be indexed already, as are able to find the objects and the children separately, without nested queries.

On Fri, Jan 25, 2013 at 3:26 PM, Henrik Lindström notifications@github.comwrote:

Hi,

Make sure that you have indexed pages with nested objects as the 'mapping' will be added dynamically when the first object of the specific type is indexed.

Regards, Henrik

Skickat från min iPhone

25 jan 2013 kl. 14:42 skrev Roy Osherove notifications@github.com:

Hi. We have some code that would perfectly match this scenario, but maybe we are doing something wrong, or maybe there is a bug. we do not know. We have a CourseDetailsPage , that has sub pages of type CourseDateInfo (Each course has many dates). We try to run a query like this:

private IEnumerable DoSearch(string q, string qMonth, string qCategory, string qLocation) { var result = new CourseResult(); var client = SearchClient.Instance; client.Conventions.ContractResolver.ObjectContractInterceptors.Add(new IncludeTypeNameInNestedFieldNamesInterceptor()); client.Conventions.FieldNameConvention = new NestedFieldNameConvention();

DateTime qDate = DateTime.Parse(qMonth); var dateResults = SearchClient.Instance.Search() .For(q) .Filter( page => page.Dates.MatchItem(d => d.CourseLocation.MatchCaseInsensitive(qLocation))) .GetResult();

return dateResults; }

and this is the impl of the Dates property on the COurseDetailsPage:

public virtual List Dates { get { return GetDates().ToList(); } }

and we keep getting the error:

[WebException: The remote server returned an error: (500) Internal Server Error.] System.Net.HttpWebRequest.GetResponse() +8522892 EPiServer.Find.Connection.JsonRequest.GetResponse() +210 EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +131

[ServiceException: The remote server returned an error: (500) Internal Server Error. SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[g0-OSD1wQISzZnCph0MP3A][saandahl_bouvetno][0]: RemoteTransportException[[Burstarr][inet[/10.3.98.11:9300]][search/phase/query]];

nested: SearchParseException[[saandahl_bouvetno][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"query_string":{"query":"csm"}},"filter":{"nested":{"path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"___types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]];

nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }{[du1B8cSBRUWIrZY2xMYxCQ][saandahl_bouvetno][1]: SearchParseException[[saandahl_bouvetno][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"filtered":{"query":{"query_string":{"query":"csm"}},"filter":{"nested":{"

path":"Dates$$nested","filter":{"term":{"CourseLocation$$string.lowercase":"oslo"}}}}}},"filter":{"term":{"___types":"Bouvet.Web.ContentTypes.Pages.CourseDetailsPage"}}}}}]]];

nested: QueryParsingException[[saandahl_bouvetno] [nested] failed to find nested object under path [Dates$$nested]]; }]] EPiServer.Find.Api.Command.GetResponse(IJsonRequest request) +883 EPiServer.Find.Api.SearchCommand`1.Execute() +634

— Reply to this email directly or view it on GitHubhttps://github.com/x2find/Nested2Find/issues/1.

— Reply to this email directly or view it on GitHubhttps://github.com/x2find/Nested2Find/issues/1#issuecomment-12702573.

Thanks,

Roy Osherove

lindstromhenrik commented 11 years ago

I see that you added the conventions before searching but where they added before indexing?

client.Conventions.ContractResolver.ObjectContractInterceptors.Add(new IncludeTypeNameInNestedFieldNamesInterceptor()); client.Conventions.FieldNameConvention = new NestedFieldNameConvention();

Try to add the conventions in a initialization module or application_start (in Global.asax)

royosherove commented 11 years ago

Hi,

I moved the code to global.ascx: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); InitEpiFind(); }

    protected void InitEpiFind()
    {
        var client = SearchClient.Instance;
        client.Conventions.ContractResolver.ObjectContractInterceptors.Add(new IncludeTypeNameInNestedFieldNamesInterceptor());
        client.Conventions.FieldNameConvention = new NestedFieldNameConvention();

    }

I got 48 errors when I ran «EPiServer Find CMS Indexing Job”

Indexing job [bouvet.web] [Page]: Reindexing completed. ExecutionTime: 0minutes 7seconds Number of pages indexed: 48 Number of page errors: 48 Number of batch errors: 0 An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while indexing (Content): MapperParsingException[object mapping [ExistingLanguages$$nested] trying to serialize a value with no field associated with it, current value [en]]. An error occured while i...

lindstromhenrik commented 11 years ago

The problem here is that ExistingLanguages on EPiServer.Core.ILocalizable contains CultureInfo types that are by default serialized into an array of strings (and not into an array of objects as the nested type expects for "complex" objects). The dirty solution for this is to add CultureInfo to the list of "non-nested" types see https://gist.github.com/4654694. For the generel case there should be a convention where "non-nested" types could be added.

lindstromhenrik commented 11 years ago

I've changed the approach to only nest lists of type NestedList. See: https://github.com/x2find/Nested2Find/commit/1b1c95cb6d061eec8e8602036e3f63f9ce72780a and follow the updated Readme.

royosherove commented 11 years ago

thanks

On Thu, Feb 28, 2013 at 10:19 PM, Henrik Lindström <notifications@github.com

wrote:

I've changed the approach to only nest lists of type NestedList. See: 1b1c95chttps://github.com/x2find/Nested2Find/commit/1b1c95cb6d061eec8e8602036e3f63f9ce72780a and follow the updated Readme.

— Reply to this email directly or view it on GitHubhttps://github.com/x2find/Nested2Find/issues/1#issuecomment-14258178 .

Thanks,

Roy Osherove