Lucene Multi Term Query field search working example in Scala

val searchInput = Map(ā€œFirst Nameā€ -> ā€œJohnā€, ā€œLast Nameā€ -> ā€œDoā€)

val parser = new MultiFieldQueryParser(searchInput.keySet.toArray, new CaseInsensitiveWhitespaceAnalyzer())

parser.setDefaultOperator(QueryParserBase.AND_OPERATOR)

val queryString = searchInput.map(i => ā€œ(ā€œ + i._1.replaceAll(ā€œ ā€œ, ā€œ\\\\ ā€œ) + ā€œ:ā€ + i._2 + ā€œ*)ā€).mkString(ā€œ ā€œ)

val query = parser.parse(queryString)

--

--

--

Adrian is a software engineer, passionate about elegant code, photography and writing. Connect @ nenuadrian.com

Love podcasts or audiobooks? Learn on the go with our new app.

CS371P Spring 2021 Week 9: Irena Lee

Jenkins Shared Libraries

How to file an issue

Kubernetes Vulnerability Scan

Data Warehouse Integration: Refining Your Customer Data Stack

Keywords To Remember ā€œWhileā€ Learning To Code…

šŸŒ•The next generation NFT ā€œDeMetaā€ā€Šā€”ā€ŠInteroperable, Editable, Evolvable

Best Charts for Fintech Apps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian M. Nenu 😺

Adrian M. Nenu 😺

Adrian is a software engineer, passionate about elegant code, photography and writing. Connect @ nenuadrian.com

More from Medium

GitHub Packages: Publish and Consume Artifacts of a Spring Gradle Project

Cracking encrypted Java applications using jhsdb (hotspot debugger)

Unit Testing Apache Camel

How Apache Camel Facilitates Your Integration Tasks: Part 2