After the one month of community bonding, the actual coding period is started on 27th May. In the community bonding period, I talked with the mentors and set milestones for each week.
Following are the main goals I archived in this week😁 :
- Perform changes in the Person class, so it will create Lucene indexes.
- Create a new module’s skeleton and implement PatientLuceneQuery class in the module.
- Create Lucene queries for gender and birthdate search with the help of Lucene API.
What is Lucene and Lucene indexes?
Lucene is a full-text search library in Java which makes it easy to add search functionality to an application or website. Lucene indexes are similar to the inverted index which we normally see in the reference books. In the book’s inverted index, we see that word to page indexing i.e. particular word appears in which pages in the book. In a similar manner, the Lucene library generates the Lucene indexes for the fields present in the database.
OpenMRS’s Lucene API does not directly use Lucene library, It uses Hibernate search API which internally uses Lucene library.
For my 1st goal i.e for creating lucence indexes of Person class, I added the @Indexed annotation to the POJO class of Person. Also, I added the @Field annotation to gender and birthdate member of Person class which tells Hibernate to create a Lucene index for Person class with the fields gender and birthdate.
After that, I created a new PatientLuceneQuery class which consists the Lucene queries for searching the Patient with gender and birthdate. The following are the Lucene queries that are built on top of OpenMRS Lucene APIs:
LuceneQuery<Person> luceneQuery = LuceneQuery .newQuery(Person.class, sessionFactory.getCurrentSession(), query, fields);
DateLuceneQuery<Person> luceneQuery = DateLuceneQuery.newQuery(Person.class, sessionFactory.getCurrentSession(), query, field);
On the next week I’m will create Lucene queries which help to search patients with range of age. 😁