Skip to content

Support multiple Search returnFields #986

Description

@blowmage

I've been troubleshooting some gcloud-ruby issues connecting to the Cloud Search API. I've been looking at gcloud-node's implementation, and I can't get find a way to specify multiple returnFields values.

Here is my setup:

$ nodejs
> var gcloud = require('gcloud')(...);
undefined
> var search = gcloud.search();
undefined
> var index = search.index('test');
undefined
> var printSearchResults = function(err, documents) {
...   if (err) {
.....     console.log('there was an error');
.....     console.log(err);
.....   } else {
.....     console.log('the search results were returned:');
.....     console.log(documents);
.....   }
... }
undefined

I can perform a simple search without specifying any returnFields values:

> index.search('ruby', printSearchResults);
undefined
> the search results were returned:
[ { metadata: {},
    baseUrl: '/documents',
    parent: 
     { metadata: {},
       baseUrl: '/indexes',
       parent: [Object],
       id: 'test',
       createMethod: undefined,
       create: undefined,
       delete: undefined,
       exists: undefined,
       get: undefined,
       getMetadata: undefined,
       setMetadata: undefined },
    id: 'gcloud-ruby',
    createMethod: undefined,
    setMetadata: undefined,
    fields: {} } ]

undefined

And I can specify a single returnFields value:

> index.search({query: 'ruby', returnFields: '*'}, printSearchResults);
undefined
> the search results were returned:
[ { metadata: {},
    baseUrl: '/documents',
    parent: 
     { metadata: {},
       baseUrl: '/indexes',
       parent: [Object],
       id: 'test',
       createMethod: undefined,
       create: undefined,
       delete: undefined,
       exists: undefined,
       get: undefined,
       getMetadata: undefined,
       setMetadata: undefined },
    id: 'gcloud-ruby',
    createMethod: undefined,
    setMetadata: undefined,
    fields: { summary: [Object], title: [Object], description: [Object] } } ]

undefined

The trouble I run into is specifying multiple values:

> index.search({query: 'ruby', returnFields: ['title', 'summary', 'description']}, printSearchResults);
undefined
> there was an error
{ errors: undefined,
  code: 400,
  message: 'Invalid JSON payload received. Unknown name "returnFields[1]": Cannot bind query parameter. Field \'returnFields[1]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "returnFields[2]": Cannot bind query parameter. Field \'returnFields[2]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "returnFields[0]": Cannot bind query parameter. Field \'returnFields[0]\' could not be found in request message.',
  response: undefined }

undefined
> 

Activity

  1. stephenplusplus commented on Dec 2, 2015

    @stephenplusplus
    Contributor

    Thanks for the report! I'll get on this 👍

  2. callmehiphop commented on Dec 3, 2015

    @callmehiphop
    Contributor

    I looked into this a little bit, request uses a module called qs internally, this is a code sample from their docs

    Qs.stringify({ a: ['b', 'c', 'd'] });
    // 'a[0]=b&a[1]=c&a[2]=d' 

    This explains the problem we're seeing and it looks like we can get around it by passing request a qsStringifyOptions object with indices set to false. Do we know if that's the standard way the upstream API deals with query strings? Just curious about if it would be safe to turn of indices globally or if we'll need to handle this on a case by case basis.

  3. stephenplusplus commented on Dec 7, 2015

    @stephenplusplus
    Contributor

    That's interesting. From the request docs, we can also use useQuerystring: true to use the default querystring module which loses the indices.

    But in this case, it looks like the API wants a string and not a list of strings:

    ... ... ...
    returnFields string List of fields to return in SearchResult objects. It can be fields from Document, the built-in fields _rank and _score, and fields defined in fieldExpressions. Use "*" to return all fields from Document.

    Looks like there is either a discrepancy in the type or an unknown delimter... subscribed to googleapis/google-cloud-ruby#450 so we can see what needs to be done here when that's resolved.

  4. added
    status: blockedResolving the issue is dependent on other work.
    and removed
    status: blockedResolving the issue is dependent on other work.
    on Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions