Skip to content

Commit

Permalink
Added matched_fields and highlight filter to highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Jun 14, 2015
1 parent 10cecae commit 3f8a4e4
Showing 1 changed file with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.sksamuel.elastic4s

import org.elasticsearch.search.highlight.HighlightBuilder

import scala.language.implicitConversions

/** @author Stephen Samuel */
trait HighlightDsl {

Expand Down Expand Up @@ -30,31 +32,38 @@ class HighlightOptionsDefinition {
_boundary_max_scan = max
this
}

def boundaryChars(chars: String): this.type = {
_boundary_chars = Option(chars)
this
}

def requireFieldMatch(requireFieldMatch: Boolean): this.type = {
_requireFieldMatch = requireFieldMatch
this
}

def tagSchema(tagSchema: TagSchema): this.type = {
_tagSchema = Option(tagSchema)
this
}

def order(order: HighlightOrder): this.type = {
_order = Option(order)
this
}

def encoder(encoder: HighlightEncoder): this.type = {
this._encoder = Option(encoder)
this
}

def postTags(iterable: Iterable[String]): this.type = postTags(iterable.toSeq: _*)
def postTags(tags: String*): this.type = {
this._postTags = tags
this
}

def preTags(iterable: Iterable[String]): this.type = preTags(iterable.toSeq: _*)
def preTags(tags: String*): this.type = {
this._preTags = tags
Expand Down Expand Up @@ -82,53 +91,59 @@ class HighlightDefinition(field: String) {

val builder = new HighlightBuilder.Field(field)

def fragmentSize(f: Int): this.type = {
builder.fragmentSize(f)
def boundaryChars(boundaryChars: String): this.type = {
builder.boundaryChars(boundaryChars.toCharArray)
this
}

def noMatchSize(size: Int): this.type = {
builder.noMatchSize(size)
def boundaryMaxScan(boundaryMaxScan: Int): this.type = {
builder.boundaryMaxScan(boundaryMaxScan)
this
}

def numberOfFragments(n: Int): this.type = {
builder.numOfFragments(n)
def forceSource(forceSource: Boolean): this.type = {
builder.forceSource(forceSource)
this
}

def query(query: QueryDefinition): this.type = {
builder.highlightQuery(query.builder)
def fragmenter(fragmenter: String): this.type = {
builder.fragmenter(fragmenter)
this
}

def phraseLimit(limit: Int): this.type = {
builder.phraseLimit(limit)
def fragmentOffset(n: Int): this.type = {
builder.fragmentOffset(n)
this
}

def boundaryMaxScan(boundaryMaxScan: Int): this.type = {
builder.boundaryMaxScan(boundaryMaxScan)
def fragmentSize(f: Int): this.type = {
builder.fragmentSize(f)
this
}

def requireFieldMatchScan(requireFieldMatch: Boolean): this.type = {
builder.requireFieldMatch(requireFieldMatch)
def highlightFilter(filter: Boolean): this.type = {
builder.highlightFilter(filter)
this
}

def boundaryChars(boundaryChars: String): this.type = {
builder.boundaryChars(boundaryChars.toCharArray)
def highlighterType(`type`: String): this.type = {
builder.highlighterType(`type`)
this
}

def forceSource(forceSource: Boolean): this.type = {
builder.forceSource(forceSource)
def matchedFields(fields: String*): this.type = matchedFields(fields)
def matchedFields(fields: Iterable[String]): this.type = {
builder.matchedFields(fields.toSeq: _*)
this
}

def fragmenter(fragmenter: String): this.type = {
builder.fragmenter(fragmenter)
def noMatchSize(size: Int): this.type = {
builder.noMatchSize(size)
this
}

def numberOfFragments(n: Int): this.type = {
builder.numOfFragments(n)
this
}

Expand All @@ -137,6 +152,16 @@ class HighlightDefinition(field: String) {
this
}

def query(query: QueryDefinition): this.type = {
builder.highlightQuery(query.builder)
this
}

def phraseLimit(limit: Int): this.type = {
builder.phraseLimit(limit)
this
}

def preTag(tags: String*): this.type = {
builder.preTags(tags: _*)
this
Expand All @@ -147,13 +172,8 @@ class HighlightDefinition(field: String) {
this
}

def fragmentOffset(n: Int): this.type = {
builder.fragmentOffset(n)
this
}

def highlighterType(`type`: String): this.type = {
builder.highlighterType(`type`)
def requireFieldMatchScan(requireFieldMatch: Boolean): this.type = {
builder.requireFieldMatch(requireFieldMatch)
this
}
}

0 comments on commit 3f8a4e4

Please sign in to comment.