title: Can a Hibernate Search FieldBridge configure facets for dynamic fields?
body: <p>Using Hibernate Search 5.11.3 with programmatic API (no annotations), is there a way to facet on dynamic fields added in a class or field bridge? I don't see any 'facet' config available in FieldMetadataBuilder when using MetadataProvidingFieldBridge.</p>
  
  <p>I have tried various combinations of luceneOptions.addSortedDocValuesFieldToDocument() and luceneOptions.addFieldToDocument() in the set() method. This successfully updates the index, but I cannot perform facet queries.</p>
  
  <p>I am trying to do a basic attribute facet/filter where I have a generic table of attributes with id/name and attribute values associated with products. For various reasons I am using the programmatic API and especially for attributes I can't make use of the @Facet annotation. So for a product, I added this class bridge to Product.class:</p>
  
  <pre><code>public class ProductClassTagValuesBridge implements FieldBridge
  {
      @Override
      public void set(String name, Object value, Document document, LuceneOptions luceneOptions)
      {
          Product product = (Product) value;
  
          for (TagValue v : product.getTagValues())
          {
              Tag tag = v.getTag();
              String tagName = "tag-" + tag.getId();
              String tagValue = v.getId().toString();
  
              // not sure if this line is required? Have tried with and without
              luceneOptions.addFieldToDocument(tagName, tagValue, document);
  
              luceneOptions.addSortedDocValuesFieldToDocument(tagName, tagValue, document);
          }
      }
  }
  </code></pre>
  
  <p>Then I build my (test) faceting request to search tag-56 (which I confirmed is in the index using Luke):</p>
  
  <pre><code>FacetParameterContext context = queryBuilder.facet()
          .name("tag-56")
          .onField("tag-56")
          .discrete();
  
  FacetingRequest facetingRequest = context.createFacetingRequest();
  </code></pre>
  
  <p>Which when used in the search/FacetManager gives me the error:</p>
  
  <p>org.hibernate.search.exception.SearchException: HSEARCH000268: Facet request 'TAG_56' tries to facet on  field 'tag-56' which either does not exist or is not configured for faceting (via @Facet). Check your configuration.</p>
  
  <p>I have also tried the custom config solution from the solution in this post: <a href="https://stackoverflow.com/questions/39574478/hibernate-search-configure-facet-for-custom-fieldbridge">Hibernate Search: configure Facet for custom FieldBridge</a></p>
  
  <p>For the custom field I added a field bridge to tagValues on my product. The same error occurs.</p>
  
  <pre><code>mapping.entity(Product.class).indexed()
      .property("tagValues", ElementType.FIELD).field()
          .analyze(Analyze.NO).store(Store.YES)
          .bridge(ProductTagValuesFieldBridge.class)
  </code></pre>