0

I am trying to create a hibernate full text search using hibernate-search-4.3.0.Final.jar There is no errors in this application, but my Lucene query unsing the query DSL doesn't return any results. I mean It doesn't return any of rows in the table. can any one please help me.

This is my function:

OgmConfiguration cfgogm=new OgmConfiguration();
        cfgogm.configure("hibernate.cfg.xml");
        serviceregistry=new ServiceRegistryBuilder().applySettings(cfgogm.getProperties()).buildServiceRegistry();
        sessionfactory=cfgogm.buildSessionFactory(serviceregistry);         
        Session session= sessionfactory.openSession(); 


        FullTextSession fulltextsession= Search.getFullTextSession(session);
        QueryBuilder querybuilder=fulltextsession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
        org.apache.lucene.search.Query lucenequery=querybuilder.keyword().onField("IdU").matching("96645").createQuery();
        org.hibernate.search.FullTextQuery fulltextquery=fulltextsession.createFullTextQuery(lucenequery, User.class);
        List result=fulltextquery.list();
        System.out.println(result.toString());

and this is my POJO class:

@Entity
@Table(name="Users")
@Indexed
public class User {
    @Id
    @GeneratedValue(generator="mongodb_uuidgg")
    @Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
    private String  _id;
    @Column(name="City")
    @Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
    private String city;
    @Column(name="UserID")
    @Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
    private int IdU;
...
TangoStar
  • 551
  • 2
  • 8
  • 24

3 Answers3

2

I would use Luke to verify that your queries actually return what you want from the index.

[edit...] If Luke shows that the index is empty, you will need to look at your indexing setup.

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
  • Thanks. could zou please explain me, how can I use Luke to verify that my queries return what I want from the index – TangoStar Aug 21 '13 at 21:24
  • I tried using Luke but when I navigate to the index folder I get no result, it says ( Number of fields:0, Number of documents:0, Number of terms:0 ) – TangoStar Aug 22 '13 at 10:47
1

Most likely, the configuration for the id field is incorrect. It should be:

@Id
@GeneratedValue(generator="mongodb_uuidgg")
@DocumentId
private String  _id;

(i.e. @DocumentId instead of @Field).

Codo
  • 75,595
  • 17
  • 168
  • 206
0

Have you actually indexed the data? You need to create the initial index, if you start with an existing database. You can use the programmatic index API and the mass indexer to create the initial index. Once you have the initial index and you are you use incremental indexing the index will stay in sync with database changes (provided changes are made via the Hibernate/JPA API).

Other than that have look at the lg file. Is there anything in there? If you still have the issue please post the code you use to index the data.

Hardy
  • 18,659
  • 3
  • 49
  • 65
  • Hi Hardy, thank you for you answer :) the only thing which I did about indexing is: write `@indexed` at the top of class and for each Field I wrote `@Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)` I am using MongoDB and I want to implement a very simple query like "SELECT City FROM Users WHERE UserID=***" .Which Log file should I control? for lucene I have a directory and both of them looks like [this](http://babakbsn.persiangig.com/luke.png) – TangoStar Aug 27 '13 at 15:29
  • I have wrote another [Post](http://stackoverflow.com/questions/18444717/fulltext-search-in-mongodb-using-hibernate-ogm), may be you find more information – TangoStar Aug 27 '13 at 15:31
  • 1
    The Luke screenshot is showing no documents, so you need to index first. If you want to index the data from an existing database have a look at http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#manual-index-changes. If you start with an empty database you will need to insert data via the JPA/Hibernate API and rely on the automatic index updates. You cannot point Hibernate Search at an existing database and expect things to work. At some stage an index needs to be build first. – Hardy Sep 01 '13 at 12:59