def search(params: ItemSearchParameters): Either[Failure, List[Item]] = {
    try {
      db withDynSession {
        var q = Items.query

        q ={ k => q.filter(
          i => (i.title like "%" + k + "%")
              || (i.description  like "%" + k + "%")
          )} getOrElse q

        q ={ sid => q.filter(
          _.shopId === sid
          )} getOrElse q

    } catch {
      case e: SQLException =>

I am not sure it is the best answer because of var q


As I understood you correct, you want to make a filter by optional fields. Your second attempt is quiet closer to reality, the first has incorrect matching, you compare option fields to non option. You've answered your own answer while I was writing this response :)

I'd like to recommend you this MaybeFilter

Or here is modified version:

Maybe this can help you to solve your problem in a more generic way.

Related Query

More Query from same tag