-2

I've some object :

{
    "name":  "universite paris sorbonne" ,
    "id":  "548272c9-6615-4e93-aa15-9af0a830c9a2"
}
{
    "name":  "universite paris dauphine" ,
    "id":  "943234f3-6615-4e93-aa15-9af0a830c9a2"
}
{
    "name":  "universite sorbonne nouvelle" ,
    "id":  "24f477f3-6615-4e93-aa15-9af0a830c9a2"
}

How can i do if i would like select each object which contain paris dau in their name ?

I've tried with that, but it doesn't work.

    curs, _ = r.Table("places").
    Filter(func(customer r.Term) interface{}{
        return customer.Field('name').Downcase().Contains(func (custo r.Term) interface{}{
            return custo.Match(".\\*" + strings.ToLower('paris dau') + ".\\*")
        })

any suggest ?

Shahriar
  • 13,460
  • 8
  • 78
  • 95
Fantasim
  • 876
  • 1
  • 12
  • 32

1 Answers1

1

I simplified your problem a bit by dumping the data into a map and then did a simple regexp match which works well.

package main

import (
  "fmt"
  "regexp"
)


func main() {
  data := map[string]string{
    "548272c9-6615-4e93-aa15-9af0a830c9a2": "universite paris sorbonne",
    "943234f3-6615-4e93-aa15-9af0a830c9a2": "universite paris dauphine",
    "24f477f3-6615-4e93-aa15-9af0a830c9a2": "universite sorbonne nouvelle",
  }

  var matches = make([]string, 0)
  for _, value := range data {
    matched, err := regexp.MatchString(".*paris dau.*", value)
    if err == nil && matched {
      matches = append(matches, value)
    }
  }

  fmt.Printf("Matches: %v\n", matches)
}
Shahriar
  • 13,460
  • 8
  • 78
  • 95
daplho
  • 1,113
  • 1
  • 11
  • 25