title: Using more than one keyword for index search with Hibernate Search
body: <p>My application, that uses <strong>Hibernate Search 4.5.0.Final</strong>, is working fine when I try to search with just one keyword. But if I try to use two keywords, the second keyword is not used by Hibernate Search, just the first one is considered by HS.</p>
  
  <p>For example, if I try to search "James", the search works fine and the application returns all "James" that I have in the index. But if I try to search "James Hetfield", the results are, again, all "James" and not the unique result with name "James Hetfield". I need to treat "James Hetfield" as <strong>"James <em>AND</em> Hetfield"</strong>.</p>
  
  <p><strong>EDIT:</strong> I've made a mistake. The search works with two keywords, <strong>but with "OR" and not "AND"</strong>.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>public List&lt;Person&gt; search(String keywords) throws DAOException {
      try {
          FullTextEntityManager fullTextEm = Search.getFullTextEntityManager(this.entityManager);
          QueryBuilder qb = fullTextEm.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get();
          Query query = qb.keyword().onFields("name", "email", "username", "phone").matching(keywords).createQuery();
          FullTextQuery fullTextQuery = fullTextEm.createFullTextQuery(query);
          fullTextQuery.setProjection("name", "email", "username", "phone");
          Sort sortField = new Sort(new SortField("name_order", SortField.STRING));
          fullTextQuery.setSort(sortField);
          return fullTextQuery.getResultList();
      }
      catch (Exception e) {
          logger.error("Error searching index: " + keywords, e);
          throw new DAOException(e);
      }
  }
  </code></pre>