RediSearch / redisearch-go

Go client for RediSearch
https://redisearch.io
BSD 3-Clause "New" or "Revised" License
298 stars 66 forks source link

Allow adding PHONETIC Attribute on Create Schema #87

Closed ashtul closed 3 years ago

ashtul commented 4 years ago

related to RediSearch/RediSearch#1607

sc := redisearch.NewSchema(redisearch.DefaultOptions).
        AddField(redisearch.Field{
            Name:     "text",
            Type:     redisearch.TextField,
            Sortable: true,
            Options:  "PHONETIC dm:en",
           }).
...

returns error Error on TextField serialization.

hualoqueros commented 4 years ago

Hi @ashtul

im sorry for mistake repo :)

Actually i still really need the question

filipecosta90 commented 4 years ago

Hi @ashtul

im sorry for mistake repo :)

Actually i still really need the question

Hi there @hualoqueros , thank you for bringing this forward. We should add support and examples of it in a short term :)

ashtul commented 4 years ago

@hualoqueros , would you be interested in creating a PR for this issue?

hualoqueros commented 4 years ago

Yup sore..

On Sun, 11 Oct 2020 at 19.31 Ariel Shtul notifications@github.com wrote:

@hualoqueros https://github.com/hualoqueros , would you be interested in creating a PR for this issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RediSearch/redisearch-go/issues/87#issuecomment-706697943, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCKDCJPO6S2OIQRL34HE63SKGQQ3ANCNFSM4SLRUMRQ .

filipecosta90 commented 4 years ago

Yup sore.. On Sun, 11 Oct 2020 at 19.31 Ariel Shtul @.***> wrote: @hualoqueros https://github.com/hualoqueros , would you be interested in creating a PR for this issue? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#87 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCKDCJPO6S2OIQRL34HE63SKGQQ3ANCNFSM4SLRUMRQ .

Hi there @hualoqueros , do you want me to push it? or kick it off and add you as reviewer/editor for that PR?

hualoqueros commented 4 years ago

Hi @filipecosta90 ,

sorry, do you mean you already enhance the PHONETIC attribute? but it will interesting if i can become reviewer/editor

filipecosta90 commented 3 years ago

Hi @filipecosta90 ,

sorry, do you mean you already enhance the PHONETIC attribute? but it will interesting if i can become reviewer/editor

Hi there @hualoqueros , can you please review #92 and check if that solves your issue? Tried adding you as a reviewer to that PR but it needs to be you to start your review there. Also added an new example availabe at godoc after merge:

example (exemplifies the CreateIndex function with phonetic matching on it in searches by default)

// Create a client
host := "localhost:6379"
password := ""
pool := &redis.Pool{Dial: func() (redis.Conn, error) {
    return redis.Dial("tcp", host, redis.DialPassword(password))
}}
c := redisearch.NewClientFromPool(pool, "myPhoneticIndex")

// Create a schema
schema := redisearch.NewSchema(redisearch.DefaultOptions).
    AddField(redisearch.NewTextFieldOptions("name", redisearch.TextFieldOptions{Sortable: true, PhoneticMatcher: redisearch.PhoneticDoubleMetaphoneEnglish})).
    AddField(redisearch.NewNumericField("age"))

// IndexDefinition is available for RediSearch 2.0+
// Create a index definition for automatic indexing on Hash updates.
// In this example we will only index keys started by product:
indexDefinition := redisearch.NewIndexDefinition().AddPrefix("myPhoneticIndex:")

// Add the Index Definition
c.CreateIndexWithIndexDefinition(schema, indexDefinition)

// Create docs with a name that has the same phonetic matcher
vanillaConnection := pool.Get()
vanillaConnection.Do("HSET", "myPhoneticIndex:doc1", "name", "Jon", "age", 25)
// Create a second document with a name that has the same phonetic matcher
vanillaConnection.Do("HSET", "myPhoneticIndex:doc2", "name", "John", "age", 20)
// Create a third document with a name that does not have the same phonetic matcher
vanillaConnection.Do("HSET", "myPhoneticIndex:doc3", "name", "Pieter", "age", 30)

// Wait for all documents to be indexed
info, _ := c.Info()
for info.IsIndexing {
    time.Sleep(time.Second)
    info, _ = c.Info()
}

_, total, _ := c.Search(redisearch.NewQuery("Jon").
    SetReturnFields("name"))

// Verify that the we've received 2 documents ( Jon and John )
fmt.Printf("Total docs replied %d\n", total)