matthias-samwald / find-me-evidence

An open-source medical search engine
GNU Affero General Public License v3.0
9 stars 1 forks source link

PubMed autocomplete should be called directly, not via server-side PHP script #10

Closed matthias-samwald closed 10 years ago

matthias-samwald commented 10 years ago

The current solution is too sluggish, also it might eventually get the FindMeEvidence server banned from the NCBI API because of too many requests.

Re-implement as direct AJAX calls from the browser to the PubMed API.

gpetz commented 10 years ago

doing a cross-domain ajax requests with $.getJSON returns: ReferenceError: NSuggest_CreateData is not defined http://preview.ncbi.nlm.nih.gov/portal/utils/autocomp.fcgi?dict=pm_related_queries_2&callback=jQuery19107535881639678947_1410267864034&q=diabet&_=1410267864035 because "As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently."

doing a cross-domain ajax request with $.get returns: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://preview.ncbi.nlm.nih.gov/portal/utils/autocomp.fcgi?dict=pm_related_queries_2&callback=?&q=diabet. This can be fixed by moving the resource to the same domain or enabling CORS. http://preview.ncbi.nlm.nih.gov/portal/utils/autocomp.fcgi?dict=pm_related_queries_2&callback=?&q=diabet

what I don't get, why https://gist.github.com/gpetz/55050eaac9f5e183acd4 is working

matthias-samwald commented 10 years ago

Well I guess the error is still caused by the cliend-side, not the remote PubMed server, right?

gpetz commented 10 years ago

@ReferenceError: As the NCBI API doesn't return valid JSON, we can't do JSONP. (The same-origin policy prevents access to DOM on different sites!) The do that to stop anyone outside ncbi.nlm.nih.gov from accessing the data.

@Cross-Origin Request Blocked: Using a CORS proxy somehow works schnappschuss 2014-09-13 18 12 48

@Gist Code: The 'return false;' (https://gist.github.com/gpetz/55050eaac9f5e183acd4#file-pubmed-L13) is somehow important. schnappschuss 2014-09-13 19 34 06

matthias-samwald commented 10 years ago

"Working hack" sounds good enough for the time being, right?

gpetz commented 10 years ago

successfully tested it on mobile versions of Safari, Firefox and Chrome:

2014-09-21 15 43 52

(fixed checkbox size issue in 3984e479a74b1140453e270bde1f9109f39689dc)