Package org.hibernate.search

Examples of org.hibernate.search.FullTextSession


    assertFindsByRoadName( "new" );
  }
 
  public void testUpdatingOutOfTransaction() {
    assertFindsByRoadName( "buonarroti" );
    FullTextSession fullTextSession = Search.getFullTextSession( sessions.openSession() );
    try {
      BusStop busStop = (BusStop) fullTextSession.get( BusStop.class, 1L );
      busStop.setRoadName( "new road" );
      fullTextSession.flush();
    }
    catch (org.hibernate.AssertionFailure ass) {
      fail( ass.getMessage() );
    }
    finally {
      fullTextSession.close();
    }
    assertFindsByRoadName( "new" );
  }
View Full Code Here


    }
    assertFindsByRoadName( "new" );
  }
 
  public void assertFindsByRoadName(String analyzedRoadname) {
    FullTextSession fullTextSession = Search.getFullTextSession( sessions.openSession() );
    Transaction tx = fullTextSession.beginTransaction();
    TermQuery ftQuery = new TermQuery( new Term( "stops.roadName", analyzedRoadname ) );
    FullTextQuery query = fullTextSession.createFullTextQuery( ftQuery, BusLine.class );
    query.setProjection( "busLineName" );
    assertEquals( 1, query.list().size() );
    List results = query.list();
    String resultName = (String) ((Object[])results.get(0))[0];
    assertEquals( "Linea 64", resultName );
    tx.commit();
    fullTextSession.close();
  }
View Full Code Here

    s.close();
  }

  // Technically this is checked by other tests but let's do it anyway. J.G.
  public void testDefaultFetchSize() throws Exception {
    FullTextSession s = Search.getFullTextSession( openSession() );
    prepEmployeeIndex( s );

    s.clear();
    Transaction tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );

    ScrollableResults projections = hibQuery.scroll();
    projections.beforeFirst();
    Object[] projection = projections.get();
    assertNull( projection );

    projections.next();
    assertTrue( projections.isFirst() );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

    tx.commit();
    s.close();
  }

  public void testFetchSizeLargerThanHits() throws Exception {
    FullTextSession s = Search.getFullTextSession( openSession() );
    prepEmployeeIndex( s );

    s.clear();
    Transaction tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 6 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1000, result[0] );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

    tx.commit();
    s.close();
  }

  public void testFetchSizeDefaultFirstAndMax() throws Exception {
    FullTextSession s = Search.getFullTextSession( openSession() );
    prepEmployeeIndex( s );

    s.clear();
    Transaction tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1000, result[0] );
    results.scroll( 2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1003, result[0] );
    // check cache addition
    results.next();
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1004, result[0] );

    results.scroll( -2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1002, result[0] );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

    s.persist( getDepts4() );
    s.flush();
    tx.commit();

    tx = s.beginTransaction();
    FullTextSession session = Search.getFullTextSession( s );

    // The equipment field is the manufacturer field  in the
    // Departments entity after being massaged by passing it
    // through the EquipmentType class. This field is in
    // the Lucene document but not in the Department entity itself.
    QueryParser parser = new QueryParser( "equipment", new SimpleAnalyzer() );

    // Check the second ClassBridge annotation
    Query query = parser.parse( "equiptype:Cisco" );
    org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );
    List<Departments> result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "incorrect number of results returned", 2, result.size() );
    for (Departments d : result) {
      assertEquals("incorrect manufacturer", "C", d.getManufacturer());
    }

    // No data cross-ups.
    query = parser.parse( "branchnetwork:Kent Lewin" );
    hibQuery = session.createFullTextQuery( query, Departments.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertTrue( "problem with field cross-ups", result.size() == 0 );

    // Non-ClassBridge field.
    parser = new QueryParser( "branchHead", new SimpleAnalyzer() );
    query = parser.parse( "branchHead:Kent Lewin" );
    hibQuery = session.createFullTextQuery( query, Departments.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertTrue( "incorrect entity returned, wrong branch head", result.size() == 1 );
    assertEquals("incorrect entity returned", "Kent Lewin", ( result.get( 0 ) ).getBranchHead());

    // Check other ClassBridge annotation.
    parser = new QueryParser( "branchnetwork", new SimpleAnalyzer() );
    query = parser.parse( "branchnetwork:st. george 1D" );
    hibQuery = session.createFullTextQuery( query, Departments.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "incorrect entity returned, wrong network", "1D", ( result.get( 0 ) ).getNetwork() );
    assertEquals( "incorrect entity returned, wrong branch", "St. George", ( result.get( 0 ) ).getBranch() );
    assertEquals( "incorrect number of results returned", 1, result.size() );
View Full Code Here

    s.persist( getDepts4() );
    s.flush();
    tx.commit();

    tx = s.beginTransaction();
    FullTextSession session = Search.getFullTextSession( s );

    // The equipment field is the manufacturer field  in the
    // Departments entity after being massaged by passing it
    // through the EquipmentType class. This field is in
    // the Lucene document but not in the Department entity itself.
    QueryParser parser = new QueryParser( "equipment", new SimpleAnalyzer() );

    // Check the second ClassBridge annotation
    Query query = parser.parse( "equiptype:Cisco" );
    org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );

    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.DOCUMENT );

    ScrollableResults projections = hibQuery.scroll();
    assertNotNull( projections );
View Full Code Here

    s.persist( getDept3() );
    s.flush();
    tx.commit();

    tx = s.beginTransaction();
    FullTextSession session = Search.getFullTextSession( s );

    // The branchnetwork field is the concatenation of both
    // the branch field and the network field of the Department
    // class. This is in the Lucene document but not in the
    // Department entity itself.
    QueryParser parser = new QueryParser( "branchnetwork", new SimpleAnalyzer() );

    Query query = parser.parse( "branchnetwork:layton 2B" );
    org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Department.class );
    List result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "incorrect entity returned, wrong network", "2B", ( (Department) result.get( 0 ) ).getNetwork() );
    assertEquals( "incorrect entity returned, wrong branch", "Layton", ( (Department) result.get( 0 ) ).getBranch() );
    assertEquals( "incorrect number of results returned", 1, result.size() );

    // Partial match.
    query = parser.parse( "branchnetwork:3c" );
    hibQuery = session.createFullTextQuery( query, Department.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "incorrect entity returned, wrong network", "3C", ( (Department) result.get( 0 ) ).getNetwork() );
    assertEquals( "incorrect entity returned, wrong branch", "West Valley", ( (Department) result.get( 0 ) ).getBranch() );
    assertEquals( "incorrect number of results returned", 1, result.size() );

    // No data cross-ups .
    query = parser.parse( "branchnetwork:Kent Lewin" );
    hibQuery = session.createFullTextQuery( query, Department.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertTrue( "problem with field cross-ups", result.size() == 0 );

    // Non-ClassBridge field.
    parser = new QueryParser( "branchHead", new SimpleAnalyzer() );
    query = parser.parse( "branchHead:Kent Lewin" );
    hibQuery = session.createFullTextQuery( query, Department.class );
    result = hibQuery.list();
    assertNotNull( result );
    assertTrue( "incorrect entity returned, wrong branch head", result.size() == 1 );
    assertEquals("incorrect entity returned", "Kent Lewin", ( (Department) result.get( 0 ) ).getBranchHead());
View Full Code Here

    tx.commit();
    s.close();
  }

  public void testFetchSizeNonDefaultFirstAndMax() throws Exception {
    FullTextSession s = Search.getFullTextSession( openSession() );
    prepEmployeeIndex( s );

    s.clear();
    Transaction tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:ITech" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );
    hibQuery.setFirstResult( 1 );
    hibQuery.setMaxResults( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    results.next();
    Object[] result = results.get();
    assertEquals( "incorrect entityInfo returned", 1002, result[0] );

    results.scroll( 2 );
    result = results.get();
    assertEquals( "incorrect entityInfo returned", 1004, result[0] );

    results.next();
    result = results.get();
    assertNull( result );

    results.scroll( -8 );
    result = results.get();
    assertNull( result );

    // And test a bad forward scroll.
    results.scroll( 10 );
    result = results.get();
    assertNull( result );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

    tx.commit();
    s.close();
  }

  public void testFetchSizeNonDefaultFirstAndMaxNoHits() throws Exception {
    FullTextSession s = Search.getFullTextSession( openSession() );
    prepEmployeeIndex( s );

    s.clear();
    Transaction tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );

    Query query = parser.parse( "dept:XXX" );
    org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
    hibQuery.setProjection( "id", "lastname", "dept" );
    hibQuery.setFetchSize( 3 );
    hibQuery.setFirstResult( 1 );
    hibQuery.setMaxResults( 3 );

    ScrollableResults results = hibQuery.scroll();
    results.beforeFirst();
    Object[] result = results.get();
    assertNull( "non-null entity infos returned", result );

    //cleanup
    for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
    tx.commit();
    s.close();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.FullTextSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.