<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
        <base href="https://hibernate.atlassian.net"> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0" bgcolor="#f5f5f5"> 
            <!-- header here --> 
            <tbody>
                <tr> 
                    <td id="header-pattern-container" style="padding: 0; border-collapse: collapse; padding: 10px 20px"> 
                        <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="header-avatar-image-container" valign="top" style="padding: 0; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="https://secure.gravatar.com/avatar/79949a8f596fe2becbb8f6282b0a093b?d=mm&amp;s=48" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td> 
                                    <td id="header-text-container" valign="middle" style="padding: 0; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="JulienBenichou" id="email_JulienBenichou" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=JulienBenichou" style="color:#6c797f;; color: #3b73af; text-decoration: none">Julien Benichou</a> <strong>updated</strong> an issue </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="email-content-container" style="padding: 0; border-collapse: collapse; padding: 0 20px"> 
                        <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; border-spacing: 0; border-collapse: separate"> 
                            <tbody>
                                <tr> 
                                    <!-- there needs to be content in the cell for it to render in some clients --> 
                                    <td class="email-content-rounded-top mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="page-title-pattern-first-line " style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="https://hibernate.atlassian.net/browse/HSEARCH" style="color: #3b73af; text-decoration: none">Hibernate Search</a> / <a href="https://hibernate.atlassian.net/browse/HSEARCH-2535" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-e41ca94e-3ffb-4859-b1b7-41987133d953" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HSEARCH-2535" style="color: #3b73af; text-decoration: none">HSEARCH-2535</a> </td> 
                                                </tr> 
                                                <tr> 
                                                    <td style="vertical-align: top;; padding: 0; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-2535" style="color: #3b73af; text-decoration: none">Facets on a String collection field</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  wrapper-special-margin" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff"> 
                                        <table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Change By:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <a class="user-hover" rel="JulienBenichou" id="email_JulienBenichou" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=JulienBenichou" style="color:#6c797f;; color: #3b73af; text-decoration: none">Julien Benichou</a> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  issue-description-container" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 5px; padding-bottom: 10px" bgcolor="#ffffff"> 
                                        <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0; border-collapse: collapse; padding: 0 0 10px"> <span class="diffcontext">Hi everybody,<br><br>I am trying to work with hibernate search facets.<br>I have three use cases :<br>- Faceting on a simple field -&gt; This is OK.<br>- Faceting on a Collection of entity (with an IndexEmbeded) -&gt; This is OK.<br>- Faceting on a simple Collection (like a Collection of String) -&gt; Thi does not work.<br><br>This is an example :<br><br>{code:java}<br>@Field(<br>&nbsp;&nbsp;&nbsp;&nbsp;name = CATEGORIES,<br>&nbsp;&nbsp;&nbsp;&nbsp;bridge = @FieldBridge(impl = StringCollectionFieldBridge.class),<br>&nbsp;&nbsp;&nbsp;&nbsp;analyze = Analyze.NO<br>)<br>@Facet(forField = CATEGORIES)<br>@</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">Transient</span> <span class="diffaddedchars" style="background-color:#ddfade;">ElementCollection</span> <span class="diffcontext"><br></span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">public Collection</span> <span class="diffaddedchars" style="background-color:#ddfade;">private List</span> <span class="diffcontext">&lt;String&gt;</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> getCategories</span> <span class="diffaddedchars" style="background-color:#ddfade;"> categories = new ArrayList&lt;String&gt;</span> <span class="diffcontext">()</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> {<br>&nbsp;&nbsp;&nbsp;&nbsp;return Lists.newArrayList(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterables.transform(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getBooks(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bindings.book().category()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;)</span> <span class="diffcontext">;<br></span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">}<br></span> <span class="diffcontext">{code}<br><br>I register my facets like this :<br><br>{code:java}<br>private FacetManager getFacetManager() {<br>&nbsp;&nbsp;&nbsp;&nbsp;return getFullTextQuery().getFacetManager();<br>}<br> <br>protected void registerFacet(FacetingRequest facetingRequest) {<br>&nbsp;&nbsp;&nbsp;&nbsp;getFacetManager().enableFaceting(facetingRequest);<br>}<br> <br>protected void registerFacet(String facetName, String fieldPath) {<br>&nbsp;&nbsp;&nbsp;&nbsp;FacetingRequest facetingRequest = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getFactory().getDefaultQueryBuilder().facet()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.name(facetName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.onField(fieldPath)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.discrete()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.includeZeroCounts(false)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.createFacetingRequest();<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;registerFacet(facetingRequest);<br>}<br>{code}<br><br>and get facets values like this :<br><br>{code:java}<br>protected Collection&lt;Facet&gt; getFacets(String facetName) {<br> return getFacetManager().getFacets(facetName);<br>}<br><br>@Override<br>public final List&lt;String&gt; listFacetValues(String facetName) {<br> return Lists.newArrayList(<br>&nbsp;&nbsp;Iterables.transform(<br>&nbsp;&nbsp;&nbsp;getFacets(facetName),<br>&nbsp;&nbsp;&nbsp;new SerializableFunction&lt;Facet, String&gt;() {<br>&nbsp;&nbsp;&nbsp;&nbsp;@Override<br>&nbsp;&nbsp;&nbsp;&nbsp;public String apply(Facet facet) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return facet.getValue();<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;)<br> );<br>}<br>{code}<br><br>So when I perform this code and try to get facets values, I get a list of String like :<br><br>{code:java}<br>["[category1,</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> category3</span> <span class="diffaddedchars" style="background-color:#ddfade;"> category2</span> <span class="diffcontext">]", "[</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">category4</span> <span class="diffaddedchars" style="background-color:#ddfade;">category1</span> <span class="diffcontext">]"</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">, "[category2, category5, category6</span> <span class="diffcontext">]</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">"]</span> <span class="diffcontext"><br>{code}<br><br>This is totally normal regarding the code in the Class<br><br>{code:java}<br>org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity<br>{code}<br><br>In fact, facets work well on a Collection of entities because it is detected that there is embeded objects. So the method {{buildDocumentFieldsForEmbeddedObjects}} is called.<br>In this method, ther is something like this :<br><br>{code:java}<br>// In a switch<br>case COLLECTION:<br>&nbsp;&nbsp;&nbsp;&nbsp;Collection&lt;?&gt; collection = objectInitializer.initializeCollection( (Collection&lt;?&gt;) value );<br>&nbsp;&nbsp;&nbsp;&nbsp;for ( Object collectionValue : collection ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buildDocumentFields(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collectionValue,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;faceting,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;embeddedTypeMetadata,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fieldToAnalyzerMap,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;processedFieldNames,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conversionContext,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objectInitializer,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;embeddedBoost,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;true<br>&nbsp;&nbsp;&nbsp;&nbsp;);<br>}<br>break;<br>{code}<br><br>So it's works because you iterate on each item. Moreover, multivalued (a FacetHandling property) is set to true.<br><br>However, on my use case, it is not an embeded. So multivalued property is set to false and the method which is called is this {{buildDocumentFieldsForProperties}} which called {{getFacetDocValues}} method on a collection object. In this method ther is something like this :<br><br>{code:java}<br>// In a switch<br>case STRING: {<br>&nbsp;&nbsp;&nbsp;&nbsp;String stringValue = value.toString();<br>&nbsp;&nbsp;&nbsp;&nbsp;if ( stringValue.isEmpty() ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return null;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;facetField = new SortedSetDocValuesFacetField(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;facetMetadata.getFacetName(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stringValue <br>&nbsp;&nbsp;&nbsp;&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;break;<br>}<br>{code}<br><br>This is applied directly on a collection object. That's why I get the result above.<br><br>I think I have a solution to fix the issue but I would like to know if this is really an issue or if I misunderstood something.<br><br>Thanks for the help.</span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> <script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "EmailMessage",
  "description": "View Issue",
  "potentialAction": {
    "@type": "ViewAction",
        "target": "https://hibernate.atlassian.net/browse/HSEARCH-2535?inbox=true&",
    "name": "View Issue"
      },
  "publisher": {
    "@type": "Organization",
    "name": "Atlassian",
    "url": "https://www.atlassian.com"
  }
}
</script> 
                                        <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="actions-pattern-container" valign="middle" style="padding: 0; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                                        <table align="left" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                                            <tbody>
                                                                <tr> 
                                                                    <td class="actions-pattern-action-icon-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-2535#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-d49d9550-ecc5-4183-9d16-19c30679f26c" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td> 
                                                                    <td class="actions-pattern-action-text-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-2535#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td> 
                                                                </tr> 
                                                            </tbody>
                                                        </table> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <!-- there needs to be content in the cell for it to render in some clients --> 
                                <tr> 
                                    <td class="email-content-rounded-bottom mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="footer-pattern" style="padding: 0; border-collapse: collapse; padding: 12px 20px"> 
                        <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian JIRA <span id="footer-build-information">(v1000.656.2#100024-<span title="71a5b157ecd6fc52905681569063805810158d50" data-commit-id="71a5b157ecd6fc52905681569063805810158d50}">sha1:71a5b15</span>)</span> </td> 
                                    <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                        <table style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="footer-pattern-logo-desktop-padding" style="padding: 0; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-e17d87ce-0b4b-4eaf-a052-d14cbc0d1bd2" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    </body>
</html>