Hibernate lucene only searches in 60 first records

Trường Đăng Nguyễn :

I have more than 500 records in Table but Hibernate lucene only search in 60 top records.

I use the hibernate session instead of the entity manager.

How can I search in all records. This is my code:

My 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>

My Entity:

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

My 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

Thanking you.

yrodiere :

The most likely explanation is that your entities haven't been indexed.

  1. Did you take care of indexing pre-existing data, for example using a Mass indexer?
  2. Did you check the logs to see if there are indexing errors?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=349439&siteId=1