2014-11-10 5 views
0

Я пишу Spring веб-приложение, используя Hibernate Search 4.5.1. Когда я пытаюсь выполнить поиск, он возвращает список emty. Я думаю, что проблема в индексировании. Создан Dir для индексов, но после того, как сущность, сохраняющая файлы в каталоге, не изменяется.Hibernate Поиск не индексируется

Это моя весна конфигурационный файл

<beans 
     xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:security="http://www.springframework.org/schema/security" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.1.xsd 
http://www.springframework.org/schema/data/jpa 
      http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/security 
      http://www.springframework.org/schema/security/spring-security-3.2.xsd"> 

    <context:component-scan base-package="project"/> 
    <context:annotation-config/> 

    <jpa:repositories base-package="project" transaction-manager-ref="hibernateTransactionManager" 
         entity-manager-factory-ref="entityManagerFactory"/> 

    <bean id="entityManagerFactory" name="managerFactory" 
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="packagesToScan" value="project"/> 
     <property name="dataSource" ref="postgresDataSource"/> 
     <property name="validationMode" value="NONE"/> 
     <property name="jpaProperties"> 
      <props> 
       <prop key="hibernate.show_sql">true</prop> 
       <prop key="hibernate.hbm2ddl.auto">update</prop> 
       <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL81Dialect</prop> 
      </props> 
     </property> 
     <property name="persistenceProvider"> 
      <bean class="org.hibernate.jpa.HibernatePersistenceProvider"/> 
     </property> 

    </bean> 


    <bean id="postgresDataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
     <property name="driverClassName" value="org.postgresql.Driver"/> 
     <property name="url" value="jdbc:postgresql://localhost:5432/LabourExchange"/> 
     <property name="username" value="postgres"/> 
     <property name="password" value="123456"/> 
    </bean> 

    <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="dataSource" ref="postgresDataSource"/> 
     <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 

    <tx:annotation-driven transaction-manager="hibernateTransactionManager"/> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="postgresDataSource"/> 
     <property name="packagesToScan" value="project"/> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${hibernate.postgres.dialect}</prop> 
       <prop key="hibernate.max_fetch_depth">2</prop> 
       <prop key="hibernate.jdbc.fetch_size">50</prop> 
       <prop key="hibernate.jdbc.batch_size">8</prop> 
       <prop key="hibernate.show_sql">false</prop> 
       <prop key="hibernate.hbm2ddl.auto">validate</prop> 
       <prop key="hibernate.search.default.directory_provider">filesystem</prop> 
       <prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop> 
      </props> 
     </property> 
    </bean> 

    <!--security config--> 
    <security:http auto-config="true" use-expressions="true"> 
     <security:intercept-url pattern="/pages/**" access="isAuthenticated()"/> 
     <security:form-login 
       login-page="/auth/login.jsf" 
       default-target-url="/pages/home.jsf" 
       authentication-failure-url="/auth/login.jsf?status=error"/> 
     <security:logout logout-success-url="/hello.jsf"/> 
    </security:http> 

    <security:authentication-manager> 
     <security:authentication-provider user-service-ref="UserDetailsService"> 
     </security:authentication-provider> 
    </security:authentication-manager> 
</beans> 

Мой файл объект

@Entity 
@Table(name = "resumes") 
@Indexed 
public class Resume { 
    @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private long id; 

    @Column(name = "title") 
    @Field(index= Index.YES, analyze= Analyze.YES, store= Store.NO) 
    @NotBlank @Size(min = 10, max = 100) 
    private String title; 

    @Column(name = "text") 
    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO) 
    @NotBlank @Size(min = 50, max = 10000) 
    private String text; 

    @Column(name = "salary") 
    @NotNull 
    private double salary; 

    @ManyToOne(optional = false) 
    @JoinColumn(name = "creator_id") 
    private User creator; 

    public User getCreator() { 
     return creator; 
    } 

    public void setCreator(User creator) { 
     this.creator = creator; 
    } 

    public long getId() { 
     return id; 
    } 

    public void setId(long id) { 
     this.id = id; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getText() { 
     return text; 
    } 

    public void setText(String text) { 
     this.text = text; 
    } 

    public double getSalary() { 
     return salary; 
    } 

    public void setSalary(double salary) { 
     this.salary = salary; 
    } 
} 
+0

ли вы фиксируете TRANSACTI на? – Ralph

+0

Ральф, я сохраняю свои сущности с помощью метода сохранения репозитория JPA – Cortwave

+0

Вы совершили транзакцию? Hibernate Search Reference 4.5, глава 2.1 «Обзор» - «Чтобы быть более эффективным, Hibernate Search объединяет взаимодействия записи с индексом Lucene ...» – Ralph

ответ

0

Я решил проблему, переместив

<prop key="hibernate.search.default.directory_provider">filesystem</prop> 
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop> 

в jpaProperties тег

Смежные вопросы