Code Monkey home page Code Monkey logo

Comments (11)

dancannon avatar dancannon commented on May 29, 2024

You might not be getting a performance increase due to the fact that you are filtering multiple times. Try the following code:

rows, err := r.Table(CensusTableName).GetAllByIndex("Name", name).OrderBy(rethink.Desc("Year")).Run(session)

from rethinkdb-go.

lateefj avatar lateefj commented on May 29, 2024

Sorry about that! That was exactly what I was looking for. Will this also work for multiple column index?

from rethinkdb-go.

dancannon avatar dancannon commented on May 29, 2024

It should work with compound indexes. For example:

rows, err := r.Table(CensusTableName).GetAllByIndex("Name", field1, field2).OrderBy(rethink.Desc("Year")).Run(session)

Where the index Name contains two fields.

from rethinkdb-go.

lateefj avatar lateefj commented on May 29, 2024

Thanks so helpful I will try that next.

from rethinkdb-go.

wildattire avatar wildattire commented on May 29, 2024

@lateefj Did you ever get compound indexes working with gorethink? It works in the rethink data explorer but does not appear to work with gorethink at all. That is to say, it returns 0 rows for the exact same query that the data explorer returns rows.

from rethinkdb-go.

wildattire avatar wildattire commented on May 29, 2024

@dancannon Does the test suite cover compound indexes? Have other people successfully used them? They really don't seem to work at all. Regular secondary indexes work, and compound indexes work with the javascript driver, but not with gorethink.

from rethinkdb-go.

lateefj avatar lateefj commented on May 29, 2024

@wildattire I couldn't get them to work.

from rethinkdb-go.

robert-zaremba avatar robert-zaremba commented on May 29, 2024

@wildattire they works for me, but let's move a discussion to #65.

from rethinkdb-go.

skatiyar avatar skatiyar commented on May 29, 2024

@dancannon couldn't get following to work.

rows, err := r.Table(CensusTableName).GetAllByIndex("Name", value).OrderBy(rethink.Desc("Year")).Run(session)

Both Name and Year are indexed. Should they be compound indexed??

from rethinkdb-go.

dancannon avatar dancannon commented on May 29, 2024

I just create this simple program which seems to show it working. Could you maybe explain what is going wrong with your program?

package main

import (
    r "github.com/dancannon/gorethink"
    "github.com/davecgh/go-spew/spew"
)

func main() {
    r.SetVerbose(true)
    s, err := r.Connect(r.ConnectOpts{
        Address: "localhost:28015",
    })
    if err != nil {
        panic(err)
    }

    r.DB("issues").TableDrop("census").Exec(s)
    r.DB("issues").TableCreate("census").Exec(s)

    r.DB("issues").Table("census").IndexCreate("Name").Exec(s)
    r.DB("issues").Table("census").IndexWait().Exec(s)

    if err := r.DB("issues").Table("census").Insert(map[string]interface{}{
        "Name": "John Smith",
        "Year": 1970,
    }).Exec(s); err != nil {
        panic(err)
    }

    cursor, err := r.DB("issues").Table("census").GetAllByIndex("Name", "John Smith").OrderBy(r.Desc("Year")).Run(s)
    if err != nil {
        panic(err)
    }

    var v interface{}
    err = cursor.One(&v)
    if err != nil {
        panic(err)
    }

    spew.Dump(v)
}

from rethinkdb-go.

skatiyar avatar skatiyar commented on May 29, 2024

@dancannon Thanks for quick reply. It turns out that above doesn't work if orderBy is on indexed field.

r.DB("issues").Table("census").GetAllByIndex("Name", "John Smith").OrderBy(r.Desc("Year")).Run(s)

If Year is indexed and you give {Index: r.Desc("Year")} it gives error.

In that case orderBy should be

r.DB("issues").Table("census").OrderBy(r.OrderByOpts{Index: r.Desc("Year")}).Filter(map[string]interface{}{"Name": "John Smith"}).Run(s)

from rethinkdb-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.