Hibernate lucene 只搜索前 60 条记录
Hibernate lucene only searches in 60 first records
我在 Table 中有 500 多条记录,但是 Hibernate lucene 只搜索 60 条最热门的记录。
我使用休眠会话而不是实体管理器。
如何在所有记录中搜索。
这是我的代码:
我的hibernate.cfg
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.globally_quoted_identifiers">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.id.new_generator_mappings">true</property>
<property
name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.search.default.indexBase">D:/tvc/indexes</property>
<mapping class="com.hellojob.entities.WebsiteOrderContract" />
</session-factory>
</hibernate-configuration>
我的实体:
@Entity
@Indexed
@AnalyzerDef(name = "customanalyzer",
charFilters = {
@CharFilterDef(factory = MappingCharFilterFactory.class
//, params = {@Parameter(name = "mapping", value = "org/hibernate/search/test/analyzer/mapping-chars.properties")}
)
},
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class), // @TokenFilterDef(factory = StopFilterFactory.class, params = {@Parameter(name="words", value= "org/hibernate/search/test/analyzer/stoplist.properties" ),@Parameter(name="ignoreCase", value="true")})
})
@Table(name = "Website_OrderContract")
public class WebsiteOrderContract implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", insertable = false, updatable = false)
private Integer id;
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO, analyzer = @Analyzer(definition = "customanalyzer"))
@Column(name = "Name")
private String name;
}
我的 DAO:
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder()
.forEntity(WebsiteOrderContract.class).get();
org.apache.lucene.search.Query query = qb
.all()
.createQuery();
FullTextQuery hibQuery = fullTextSession.createFullTextQuery(query, WebsiteOrderContract.class);
hibQuery.setFirstResult(0);
hibQuery.setMaxResults(10);
rs = hibQuery.list();
System.out.println(hibQuery.getResultSize()); // 60 results, must be 590
System.out.println(rs.size()); // 10 result
谢谢。
最可能的解释是您的实体尚未编入索引。
- 您是否负责为预先存在的数据编制索引,例如使用 Mass indexer?
- 您是否检查日志以查看是否存在索引错误?
我在 Table 中有 500 多条记录,但是 Hibernate lucene 只搜索 60 条最热门的记录。
我使用休眠会话而不是实体管理器。
如何在所有记录中搜索。 这是我的代码:
我的hibernate.cfg
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.globally_quoted_identifiers">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.id.new_generator_mappings">true</property>
<property
name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.search.default.indexBase">D:/tvc/indexes</property>
<mapping class="com.hellojob.entities.WebsiteOrderContract" />
</session-factory>
</hibernate-configuration>
我的实体:
@Entity
@Indexed
@AnalyzerDef(name = "customanalyzer",
charFilters = {
@CharFilterDef(factory = MappingCharFilterFactory.class
//, params = {@Parameter(name = "mapping", value = "org/hibernate/search/test/analyzer/mapping-chars.properties")}
)
},
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class), // @TokenFilterDef(factory = StopFilterFactory.class, params = {@Parameter(name="words", value= "org/hibernate/search/test/analyzer/stoplist.properties" ),@Parameter(name="ignoreCase", value="true")})
})
@Table(name = "Website_OrderContract")
public class WebsiteOrderContract implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", insertable = false, updatable = false)
private Integer id;
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO, analyzer = @Analyzer(definition = "customanalyzer"))
@Column(name = "Name")
private String name;
}
我的 DAO:
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder()
.forEntity(WebsiteOrderContract.class).get();
org.apache.lucene.search.Query query = qb
.all()
.createQuery();
FullTextQuery hibQuery = fullTextSession.createFullTextQuery(query, WebsiteOrderContract.class);
hibQuery.setFirstResult(0);
hibQuery.setMaxResults(10);
rs = hibQuery.list();
System.out.println(hibQuery.getResultSize()); // 60 results, must be 590
System.out.println(rs.size()); // 10 result
谢谢。
最可能的解释是您的实体尚未编入索引。
- 您是否负责为预先存在的数据编制索引,例如使用 Mass indexer?
- 您是否检查日志以查看是否存在索引错误?