title: building multiple indexes with hibernate search
body: <p>I'm working on full-text-search functionality within a spring MVC project. The search function has to be able to search for multiple entities (which can selected by the user). I created a RequestMapping to the following function which allows me to build indexes for the @Indexed classes in my model.</p>
  
  <pre><code>public void bouwIndex(HttpServletResponse response) throws InterruptedException {
      OutputWriter output = new HttpResponseOutputWriter(response);
      FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
      fullTextEntityManager.createIndexer().startAndWait();
      output.writeLn("Lucene index built!");
  }
  </code></pre>
  
  <p>Let's say I have two classes (Profielwerkstuk and Begrip) which I have annotated and want to have indexed. When add the @Indexed annotation to the Profielwerkstuk class but not to the Begrip class and call the index-builder URL, Profielwerkstuk gets indexed correctly and within reasonable time (20 seconds or so) and searching Profielwerkstukken on this index works perfectly fine. Similarly, when the @Indexed annotation is added to the Begrip class but not to the Profielwerkstuk class, the index for Begrip is also created correctly and within reasonable time (10 seconds or so). </p>
  
  <p>Problems arise when I add the @Indexed class to both the Profielwerkstuk class and the Begrip class and try to built the indexes, now creating the indexes ran for over 10 hours without completing (I terminated it after 10 hours). I would expect that the task to be completed by the indexer would be the same as first building the Profielwerkstuk index and then building the Begrip index, which are both tested to complete within reasonable time. Does anyone have an idea what might be causing my indexer to take so long?</p>
  
  <p><strong>Edit:</strong>
  On request the relevant, annotated parts of Profielwerkstuk and Begrip are added.</p>
  
  <p>Begrip:</p>
  
  <pre><code>@Indexed
  @Analyzer(impl = DutchAnalyzer.class)
  public class Begrip {
  
      @Field
      private String naam;
  
      @Lob
      @Field
      private String omschrijving;
  
      @OneToMany(mappedBy = "begrip")
      @IndexedEmbedded(includePaths = { "onderwerp.naam" })
      private List&lt;OnderwerpBegripRelatie&gt; onderwerpen;
  
      @OneToOne(optional=true, cascade=CascadeType.ALL)
      @IndexedEmbedded(includePaths = { "content", "elementen.content" })
      private ContainerElement inhoud;
  }
  </code></pre>
  
  <p>Profielwerkstuk:</p>
  
  <pre><code>@Indexed
  @Analyzer(impl = DutchAnalyzer.class)
  public class Profielwerkstuk {
  
      @Field
      private String titel;
  
      @OneToOne(cascade = CascadeType.ALL)
      @IndexedEmbedded(includePaths = { "content", "elementen.content" })
      private ContainerElement inhoud;
  
      @Lob
      @Field
      private String bronvermelding;
  
      @OneToMany(mappedBy="profielwerkstuk")
      @IndexedEmbedded(includePaths = { "vraag", "toelichting", "eindtermen.keywords.keyword" })
      private List&lt;Onderzoeksvraag&gt; onderzoeksvragen = new ArrayList&lt;Onderzoeksvraag&gt;();
  }
  </code></pre>
  
  <p>I can add to this that the class OnderwerpBegripRelatie as embedded in Begrip is not related to Profielwerkstuk, and Onderzoeksvraag in Profielwerkstuk is not related to Begrip. The ContainerElement part might also be of help in answering the question, as both Profielwerkstuk and Begrip have a ContainerElement field with @IndexedEmbedded.</p>
  
  <p>ContainerElement:</p>
  
  <pre><code>public class ContainerElement extends Element {
  
      @OneToMany(mappedBy="container", cascade = CascadeType.ALL)
      @IndexedEmbedded(includePaths = { "content" })
      protected List&lt;Element&gt; elementen;
  }
  </code></pre>
  
  <p>And its parent class Element:</p>
  
  <pre><code>public class Element {
  
      @Lob
      @Field
      private String content;
  }
  </code></pre>