-
1. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 9, 2016 5:29 PM (in response to dansiviter)An @IndexEmbedded will create a synthetic field in the index in the parent entity, so this should work:
org.infinispan.query.dsl.Query q = Search.getQueryFactory(cache).from(myClass.class).orderBy("myNested.name", SortOrder.ASC).build();
-
2. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 12, 2016 9:47 AM (in response to gustavonalle)I've just given this a go and now I get:
ISPN000404: Unknown alias: myNested.
Is there some annotations I need to setup to ensure the alas is created? At the moment it only has @IndexEmbedded assigned to it with other values set.
-
3. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 12, 2016 10:07 AM (in response to dansiviter)Is the field in the child indexed (e.g. has @Field) in it?
-
4. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 12, 2016 10:36 AM (in response to gustavonalle)Thanks Gustavo, so I've updated it and it now works. However, as I'm using the Lucene text search is there a way to combine this and the embedded entity sorting?
Also, I'm a little confused to why works using just 'name' rather than 'name_toSort' which is set up as the @SortableField.
-
5. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 12, 2016 10:45 AM (in response to dansiviter)Could you post the entity mapping and the query that you are doing?
-
6. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 12, 2016 11:43 AM (in response to gustavonalle)Sorry, I'm not allowed. I'll keep plumbing away with ToParentBlockJoinSortField and see how far I can get.
-
7. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 12, 2016 12:00 PM (in response to dansiviter)Without knowing how are querying and how are you mapping I can't provide much help, but ToParentBlockJoinSortField is used in Lucene to do "index-time" joins: the idea is that you must index parent documents followed by all their nested or child documents, and this sort field allows you to sort parent docs based on child values. When using @IndexEmbedded in Hibernate Search, at index level there is no 'parent' or 'child' document, but rather just documents with denormalized fields, so ToParentBlockJoinSortField is not applicable.
-
8. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 12, 2016 12:19 PM (in response to gustavonalle)I totally understand you're assisting me blind here but I can assure you you've helped me a lot already.
Maybe adding a little more context might help: I want to use the Lucene StandardQueryParser to be able to perform string query parsing and fuzzy searches. This means the created query is converted into a CacheQuery (via SearchManager) to perform the search. To sort the results I've been passing it to CacheQuery#setSort(...) however I've not found a way for this to work yet with embedded entities. The way you've suggested does work great for programmatic searches but doesn't have the expressiveness of the Lucene Syntax. Is there anyway to link the two?
Thanks again.
-
9. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 12, 2016 12:35 PM (in response to dansiviter)Right, this should be equivalent to the previous sample, but using Lucene Queries:
CacheQuery cacheQuery = Search.getSearchManager(cache).getQuery(/** Lucene Query here **/, myClass.class); Sort luceneSort = new Sort(new SortField("myNested.name", SortField.Type.STRING, true)); cacheQuery.sort(luceneSort); List<Object> list = cacheQuery.list();
-
10. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 12, 2016 2:47 PM (in response to gustavonalle)I've tried and it does look like the results are coming back ordered.
One issues is I'm now getting this warning:
WARN: HSEARCH000289: Requested sort field(s) myNested.name are not configured for entity type foo.entity.MyObject mapped to index foo.entity.MyObject, thus an uninverting reader must be created. You should declare the missing sort fields using @SortableField.
@SortableField is defined on MyNested#name, any idea how to remove this warning? I don't want it polluting the log if this is just poor setup on my part.
-
11. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 15, 2016 5:28 AM (in response to dansiviter)Do you have more than one @Field defined in 'myNested.name'? Apparently the search engine is not detecting the upfront @SortableField in MyNested#name and is trying to sort on demand rather than using the most performant pre-calculated doc values structures in Lucene.
-
12. Re: Query Nested Fields in Hibernate Search/Infinispan
dansiviter Feb 17, 2016 6:41 AM (in response to gustavonalle)Yea, it's defined as:
@Fields({ @Field, @Field(name = "name_sort", analyze = Analyze.NO, store = Store.NO, index = Index.NO) }) @SortableField(forField = "name_sort") private String name;
Therefore, I would assume it should be able to link 'MyNested#name' to 'name_sort'.
-
13. Re: Query Nested Fields in Hibernate Search/Infinispan
gustavonalle Feb 18, 2016 5:56 AM (in response to dansiviter)Right, so the correct sort would be:
Sort luceneSort = new Sort(new SortField("myNested.name_sort", SortField.Type.STRING, true));