0
hibernate検索用のサンプルプロジェクトを作成しましたが、例外なく正常に動作しますが、その文字列でオブジェクトを持つ文字列を検索すると、私は何をすべきかわからない!誰かが私を助けることができます... プロジェクトはmavenベースで、私は休止状態と休止状態の検索のために休止状態注釈を使用します。 は、ここに私のhibernate.cfg.xmlファイルです:Hibernate検索で正しい結果が返されない
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/eprnews
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">***</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<!--
<property name="hibernate.hbm2ddl.auto">create-drop</property>
Hibernate Search -->
<!-- org.hibernate.search.store.FSDirectoryProvider -->
<!-- org.hibernate.search.store.RAMDirectoryProvider for test -->
<!--
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
-->
<property name="hibernate.search.default.directory_provider">filesystem</property>
<property name="hibernate.search.default.indexBase">./indexes</property>
<!--
-->
<property name="hibernate.search.worker.execution">async</property>
<property name="hibernate.search.default.optimizer.transaction_limit.max">100</property>
<!-- Mapped classes -->
<mapping class="net.leemoo.test.entity.NewsEntity"/>
</session-factory>
</hibernate-configuration>
とここに私の実体である:
@Entity
@Table(name="news")
@Indexed
@AnalyzerDef(
name = "PersianAnal",
charFilters = @CharFilterDef(factory = PersianCharFilterFactory.class),
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters={
@TokenFilterDef(factory = ArabicNormalizationFilterFactory.class),
@TokenFilterDef(factory = PersianNormalizationFilterFactory.class)
}
)
public class NewsEntity {
@Id
@GeneratedValue
private Long id;
@Field
@Analyzer(definition="PersianAnal")
private String title;
@Field
@Analyzer(definition="PersianAnal")
private String newsAbstract;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
@Analyzer(definition="PersianAnal")
private String content;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
@DateBridge(resolution=Resolution.DAY)
private Date creationDate;
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
@DateBridge(resolution=Resolution.DAY)
private Date modifiedDate;
private Integer viewsCounter;
@Field
@Analyzer(definition="PersianAnal")
private String keywords;
private Boolean jqueryNews;
private Boolean photoNews;
and setters and getters...
、これは私が検索に使用するコードです:
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
FullTextSession fullTextSession = Search.getFullTextSession(session);
try {
// fullTextSession.createIndexer().startAndWait();
QueryBuilder gb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(NewsEntity.class).get();
Query query = gb.keyword().
onFields("title", "newsAbstract", "content").
matching("test").createQuery();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, NewsEntity.class);
List<NewsEntity> result = (List<NewsEntity>)hibQuery.list();
System.out.println(result.size());
} catch (Exception e) {
// e.printStackTrace();
}
session.getTransaction().commit();
session.close();
何私はする必要がありますか?助けてください....