Skip to content

Lucene Query

MongoCamp Mongo Driver support the usage of Lucene Query to search in the MongoDb.

Usage

Explicit Usage

The LuceneConverter has the methods to parse a String to and Query and a other to the document conversion.

scala
val search = PersonDAO.find(LuceneQueryConverter.toDocument(luceneQuery), sortByBalance).resultList()

Implicit Usage

Like the Map to Bson conversion there is also an implicit method to convert Query to find Bson.

scala
val search = PersonDAO.find(luceneQuery, sortByBalance).resultList()

Parse String to Query

We have an individual parser to parse an string to Lucene Query, because the default Lucene Analyser is case-insensitive and convert all search data into lower case. So the best way to seach in MongoDb with Lucene Query is to use this code.

scala
val luceneQuery = LuceneQueryConverter.parse("(favoriteFruit:\"apple\" AND age:\"25\") OR name:*Cecile* AND -active:false AND 123", "id")

Read More

Lucene Cheatsheet

Released under the Apache License 2.0.