내 프로젝트에서 최대 절전 모드 검색을 통합하려고합니다. 내 모델에 대한 색인이 생성되지만 내 검색어로 인해 결과가 반환되지 않는 이유가 있습니다. 나는 지금 몇 시간 동안이 문제를 해결하려고 노력해 왔지만 내가하는 일은 아무 것도없는 것처럼 보인다.최대 절전 모드 검색 + spring3 + jpa
도메인 개체 :
@Entity
@Table(name = "roles")
@Indexed
public class Role implements GrantedAuthority {
private static final long serialVersionUID = 8227887773948216849L;
@Id @GeneratedValue
@DocumentId
private Long ID;
@Column(name = "authority", nullable = false)
@Field(index = Index.TOKENIZED, store = Store.YES)
private String authority;
@ManyToMany
@JoinTable(name = "user_roles", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "username") })
@ContainedIn
private List<User> users;
...
}
DAO :
public abstract class GenericPersistenceDao<T> implements IGenericDao<T> {
@PersistenceContext
private EntityManager entityManager;
...
@Override
public FullTextEntityManager getSearchManager() {
return Search.getFullTextEntityManager(entityManager);
}
}
서비스 :
@Service(value = "roleService")
public class RoleServiceImpl implements RoleService {
@Autowired
private RoleDao roleDAO;
...
@Override
@SuppressWarnings("unchecked")
public List<Role> searchRoles(String keyword) throws ParseException {
FullTextEntityManager manager = roleDAO.getSearchManager();
TermQuery tquery = new TermQuery(new Term("authority", keyword));
FullTextQuery query = manager.createFullTextQuery(tquery, Role.class);
return query.getResultList();
}
}
테스트 :
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@Transactional
public class TestRoleService extends Assert {
@Autowired
private RoleService roleService;
@Test
public void testSearchRoles() {
roleService.saveRole(/* role with authority="test" */);
List<Role> roles = roleService.searchRoles("test");
assertEquals(1, roles.size()); // returns 0
}
}
구성
<persistence-unit name="hibernatePersistence" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider" />
<property name="hibernate.search.default.indexBase" value="indexes" />
</properties>
</persistence-unit>
<!-- Entity manager -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="hibernatePersistence" />
</bean>
<!-- Transaction manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- Enable the configuration of transaction behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="org.myproject" />
실제로 데이터베이스는 해당 기관 필드 값과 일치하는 역할로 채워집니다. 엔티티 관리자는 내 모든 정규 CRUD 테스트가 성공할 때만 유효합니다. 오류가 전적으로 최대 절전 모드 검색 (3.1.1.GA)과 관련되어 있음을 의미하지만 잘못된 위치는 어디입니까?
DB가 전체 텍스트 검색을 지원합니까? – Roman
HSQLDB를 사용하고 있습니다. – Jeroen
수정 : 도메인 개체의 색인이 올바르게 지정되지 않았습니다. – Jeroen