簡體   English   中英

Hibernate Search未建立索引

[英]Hibernate Search not indexing

我使用Hibernate Search 4.5.1編寫Spring web-app。 當我嘗試搜索時,它會返回空列表。 我認為索引中的問題。 索引的目錄已創建,但是在實體中保存目錄中的文件后,目錄不變。

這是我的春季配置文件

<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;
    }
}

我通過移動解決了問題

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

jpaProperties標記

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM