I added the PaddedIntegerBridge into the field (depends on the test suite).
But it still search nothing if I search the range of integer. Can you show me a simple runnable example?
Best regards,
Eric
Code:
try {
EntityManager em = EMUtil.getEntityManager();
em.getTransaction().begin();
Article a = new Article();
a.setWorker("Wonderful");
a.setTitle("Line " + 100);
a.setText("Testing");
a.setPage(100);
Article a1 = new Article();
a1.setWorker("Hello World");
a1.setTitle("Line " + 50);
a1.setText("Testing Super Lucene");
a1.setPage(80);
em.persist(a1);
em.persist(a);
em.getTransaction().commit();
FullTextSession ftSession = Search.createFullTextSession((Session)em.getDelegate());
QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
Query qry = parser.parse("page:[50 TO 100]");
org.hibernate.Query fullTextQuery = ftSession.createFullTextQuery(qry, test.model.Article.class);
List<Article> result = fullTextQuery.list();
System.out.println(".........." + result.size());
for(Article art : result) {
System.out.println(art);
}
em.close();
} catch(Exception ex) {
ex.printStackTrace();
}
Code:
@Entity
@Indexed
public class Article implements Serializable {
public static final long serialVersionUID = 1L;
private long id;
private String worker;
private String title;
private String text;
private int page;
public Article() {
;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@DocumentId
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
@Field(index=Index.TOKENIZED)
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
@Field(index=Index.TOKENIZED)
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
@Field(index=Index.UN_TOKENIZED)
@FieldBridge(impl=PaddedIntegerBridge.class, params = @Parameter( name="pasdding", value="5" ) )
public int getPage() {
return this.page;
}
public void setPage(int page) {
this.page = page;
}
public String getWorker() {
return this.worker;
}
public void setWorker(String worker) {
this.worker = worker;
}
@Transient
public String toString() {
return worker + ":" + title + ", " + text + ", page=" + page;
}
}