Ottoman Index: and Queries: - examples?

Hi,

I’m using Ottoman and in one of my models I have a typical name element

name: {
first: “string”,
last: “string”,
display: “string”
}

In Ottoman, how do a I create an index where I can return matches on any of the components of name? Is this something that can be done with a view or does it require N1QL? (Not played with that yet)

Extending this, how do I then return results for partial matches on each field?

Lastly, can anyone point me to docs and/or examples for creating queries: in Ottoman. http://ottomanjs.com/ doesn’t have enough for me to get my head around it.

Cheers,
Matt

Hey @kartaphilos,

You should be able to specify an index on the name field itself. Once you have done this, N1QL should provide indexing capabilities on the whole block. For instance:

var User = ottoman.model('User', {
    name: {
      first: 'string',
      last: 'string',
      display: 'string'
    }
  }, {
    indexes: {
      'findByName': {
        type: 'n1ql',
        by: 'name'
      }
    }
  }
});

User.findByName({first: 'Brett', last: 'Lawson'}, function(err, rows) {
  // Should have you're results
});

Cheers, Brett

Thanks @brett19. How do I get that work if I just supply a single string to search on against all fields in name? (I don’t always know what field the string I’m searching for will be in so want to search all fields in name

ie. If I made a call like User.findbyName( 'John', (err, rows) => {}); would it search for that string in all of name.first, name.last and name.display fields?

btw: How do I do partial string matches (ideally regex) in a find, ie. search for Bre*?

Ta,
Matt

Hey @kartaphilos,

Ottoman does not currently support the kind of query you are looking to do. The second iteration of Ottoman does have support for a simple version of what you are trying to do, but we do not yet have a stable release.

Cheers, Brett

@brett19. Bummer but thanks for the answer.

I guess I can build a function that queries each separately and combines the result sets together.

btw - roughly how far away is Ottoman v2? weeks, months, …?

Matt

@brett19
We can also query like this:

User.find({first: 'Brett', last: 'Lawson'}, (err, rows) => {
// Should have you're results
});

Am I right?