title: Discriminator Based Multi-Tenancy Filtering Using Hibernate Search
body: <p>I am attempting to add full text search to an entity using hibernate-search. Our schema uses discriminator based multi-tenancy, where each tenant is a <code>park</code> with an id. The model looks like this:</p>
  
  <pre><code>@Entity
  @Indexed
  public class ProductModel {
    @Field
    // park is the tenant 
    private Long parkId;
  
    @Field(index = Index.YES, analyze = Analyze.YES)
    @Analyzer(definition = "customanalyzer")
    private String name;
  
    @Field(index = Index.YES, analyze = Analyze.YES)
    @Analyzer(definition = "customanalyzer")
    private String description;
  }
  </code></pre>
  
  <p>When performing full text search, I will always be filtering based on a <code>parkId</code>. Would it make sense to annotate the <code>parkId</code> with <code>@Field</code>, and then add that filter to the lucene query like so:</p>
  
  <pre><code>org.apache.lucene.search.Query luceneQuery = qb
    .bool()
      .must(qb.keyword().onFields("parkId").matching(parkIdFilter)) 
  
      // any aditional queries, like on name, description
     .must(qb.keyword().onFields(fields).matching(textQuery).createQuery())
    .createQuery();
  </code></pre>
  
  <p>Or is there a better way to handle multi-tenancy using hibernate search with discriminator columns? I've seen the <a href="https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#section-multi-tenancy" rel="nofollow noreferrer">example mentioned in the docs</a> but don't know how to apply that to my particular use case.</p>