コード例 #1
0
 /**
  * Helper method creating three books with the same title and summary. When searching for these
  * books the results should be returned in the order they got added to the index.
  */
 private void createTestBooks() {
   Transaction tx = fullTextSession.beginTransaction();
   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
   cal.set(2007, Calendar.JULY, 25, 11, 20, 30);
   Book book = new Book(1, "Hibernate & Lucene", "This is a test book.");
   book.setPublicationDate(cal.getTime());
   fullTextSession.save(book);
   cal.add(Calendar.SECOND, 1);
   book = new Book(2, "Hibernate & Lucene", "This is a test book.");
   book.setPublicationDate(cal.getTime());
   fullTextSession.save(book);
   cal.add(Calendar.SECOND, 1);
   book = new Book(3, "Hibernate & Lucene", "This is a test book.");
   book.setPublicationDate(cal.getTime());
   fullTextSession.save(book);
   cal.add(Calendar.SECOND, 1);
   book = new Book(10, "Hibernate & Lucene", "This is a test book.");
   book.setPublicationDate(cal.getTime());
   fullTextSession.save(book);
   cal.add(Calendar.SECOND, 1);
   book = new Book(4, "Groovy in Action", "The bible of Groovy");
   book.setPublicationDate(cal.getTime());
   fullTextSession.save(book);
   tx.commit();
   fullTextSession.clear();
 }
コード例 #2
0
 /** Helper method creating test data for number holder. */
 private void createTestNumbers() {
   Transaction tx = fullTextSession.beginTransaction();
   NumberHolder holder = new NumberHolder(1, 1);
   fullTextSession.save(holder);
   holder = new NumberHolder(1, 10);
   fullTextSession.save(holder);
   holder = new NumberHolder(1, 5);
   fullTextSession.save(holder);
   holder = new NumberHolder(3, 2);
   fullTextSession.save(holder);
   tx.commit();
   fullTextSession.clear();
 }
コード例 #3
0
  private void buildBoostedGetIndex(FullTextSession session) {
    Transaction tx = session.beginTransaction();
    BoostedGetDescriptionLibrary l = new BoostedGetDescriptionLibrary();
    l.setAuthor("H.G. Wells");
    l.setTitle("The Invisible Man");
    l.setDescription("Scientist discovers invisibility and becomes insane.");
    session.save(l);

    l = new BoostedGetDescriptionLibrary();
    l.setAuthor("H.G. Wells");
    l.setTitle("War of the Worlds");
    l.setDescription("Martians invade earth to eliminate mankind.");
    session.save(l);

    tx.commit();
  }
コード例 #4
0
  public void testQueryOnAllEntities() throws Exception {

    FullTextSession s = Search.getFullTextSession(openSession());

    Transaction tx = s.beginTransaction();
    Person person = new Person();
    person.setName("Jon Doe");
    s.save(person);
    tx.commit();

    tx = s.beginTransaction();
    QueryParser parser =
        new QueryParser(
            TestConstants.getTargetLuceneVersion(), "name", TestConstants.standardAnalyzer);
    Query query = parser.parse("name:foo");
    FullTextQuery hibQuery = s.createFullTextQuery(query);
    try {
      hibQuery.list();
      fail();
    } catch (SearchException e) {
      assertTrue("Wrong message", e.getMessage().startsWith("There are no mapped entities"));
    }

    tx.rollback();
    s.close();
  }
コード例 #5
0
  private void buildIndex(FullTextSession session, Transaction tx) throws Exception {
    tx = session.beginTransaction();

    ElectricalProperties ep = new ElectricalProperties();
    ep.setContent("Electrical Engineers measure Electrical Properties");
    session.save(ep);

    ep = new ElectricalProperties();
    ep.setContent("Electrical Properties are interesting");
    session.save(ep);

    ep = new ElectricalProperties();
    ep.setContent("Electrical Properties are measurable properties");
    session.save(ep);

    tx.commit();
    session.clear();
  }
コード例 #6
0
 private void buildIndex(FullTextSession session, Transaction tx) {
   for (int x = 0; x < titles.length; x++) {
     Dvd dvd = new Dvd();
     dvd.setTitle(titles[x]);
     dvd.setId(x);
     session.save(dvd);
   }
   tx.commit();
   session.clear();
 }