Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Add Size Query Param for Elastic Search #715

Merged
merged 11 commits into from
Oct 17, 2016

Conversation

donaldwasserman
Copy link
Contributor

@donaldwasserman donaldwasserman commented Oct 7, 2016

Fixes #453.

Changes proposed in this pull request:
Added configurable Elastic Search size option.

I don't have elastic search running locally and it doesn't seem to be an issue with the server routes. Can submit a PR on those if you think it's necessary.

This is an exciting project

cc @HospitalRun/core-maintainers

Copy link
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donaldwasserman looks good to me. thanks for the PR!

@@ -138,6 +140,11 @@ export default Adapter.extend(PouchAdapterUtils, {
break;
}
}

if (!query.options.size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donaldwasserman I just tested this and I get the following error:
vendor.js:40820 Error while processing route: patients.search Cannot read property 'size' of undefined TypeError: Cannot read property 'size' of undefined
I believe this is because query.options is not passed in.

@@ -34,4 +34,4 @@ config.couchDbURL = config.getProtocol(config.couchDbUseSsl) + config.couchDbSer
config.couchAuthDbURL = config.getProtocol(config.couchDbUseSsl) + config.couchCredentials() + config.couchDbServer + ':' + config.couchDbPort;
// config.searchURL = 'http://localhost:9200'; ELASTIC SEARCH URL (OPTIONAL)
config.serverInfo = 'Development Ember CLI server';
module.exports = config;
module.exports = config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't be here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I realized that this size parameter never makes it to the call to elasticsearch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After stopping and thinking it through, it seems like _executeContainsSearch is the only method that makes elastic search requests? I know that's a pretty basic question, but this is pretty abstracted out for my simple brain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donaldwasserman correct... _executeContainsSearch is what ends up calling to /search/hrdb/ which is a proxy to ElasticSearch (or a temp view search using couchdb).

This part of the code needs to have the size parameter passed to it:

Ember.$.ajax(searchUrl, {
  dataType: 'json',
  data: {
    q: queryString,
    size: variableWithSize //Replace variableWithSize with whatever variable has the size.
  },
  success: successFn
});

Also, even if you don't have ElasticSearch installed you can still test to see if the value is being passed along by running a search from Patient and looking in the developer console to see what url the app is passing along to the search proxy. The url should end with &size=25

Copy link
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donaldwasserman can you address these changes? Once they are done, I think this PR is ready to go. Thanks!

_executeContainsSearch(store, type, query) {
const self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this because "this" is properly bound when you need it in the Ember.$.ajax call because

return new Ember.RSVP.Promise((resolve, reject) => {
});

is the same as

return new Ember.RSVP.Promise(function(resolve, reject) {
}).bind(this);

@@ -34,4 +34,4 @@ config.couchDbURL = config.getProtocol(config.couchDbUseSsl) + config.couchDbSer
config.couchAuthDbURL = config.getProtocol(config.couchDbUseSsl) + config.couchCredentials() + config.couchDbServer + ':' + config.couchDbPort;
// config.searchURL = 'http://localhost:9200'; ELASTIC SEARCH URL (OPTIONAL)
config.serverInfo = 'Development Ember CLI server';
module.exports = config;
module.exports = config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the change to server/config-example.js (eg put back the newline at the end of the file).

@donaldwasserman
Copy link
Contributor Author

should be all set

Ember.$.ajax(searchUrl, {
dataType: 'json',
data: {
q: queryString
q: queryString,
size: self.get('_esDefaultSize')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't try the code, but it appears this should be used instead of self.

@donaldwasserman
Copy link
Contributor Author

I forgot to commit the code that changed this to self. should be good now.

@jkleinsc
Copy link
Member

Thanks for the PR! Looks good to me, so I'll merge it in.

@jkleinsc jkleinsc merged commit d59c43e into HospitalRun:master Oct 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants