solr-scala-client is a simple Apache Solr client for Scala based on SolrJ.
The list of new features in 0.0.7:
- Add build for Scala 2.10
- Upgrade to SolrJ 4.2.0
- Support search result highlighting
In this entry, I introduce search result highlighting which is a new feature in this release.
How to Highlight?
You can configure the query to return the highlighted content using QueryBuilder#highlight(). The highlighted field is required, but prefix and suffix is not required. They are optional(default is <em>...</em>).
The highlighted content is set as the "highlight" property to the Map or the case class.
val result = client.query("content: Scala") // NOTE: unique key field is required. .fields("id") // Specify the highlighted field, prefix and postfix (prefix and postfix is optional). .highlight("content", "", "") .getResultAsMap() result.documents.foreach { doc: Product => println("id: " + doc("id")) println(doc("highlight")) // highlighted content is set as the "highlight" property }
In SolrJ, we have to map retrieved documents and highlighted contents using the unique key of the index schema. solr-scala-client expects that the unique key is "id".
If your schema has the different field as the unique key, you can specify the unique key name as following:
val result = client.query("content: Scala") .id("documentId") // Specify the unique key name .fields("documentId") .highlight("content", "", "") .getResultAsMap()
0 件のコメント:
コメントを投稿