简体   繁体   English

将AWS.cloudSearch与javaScript一起使用

[英]Using AWS.cloudSearch with javaScript

I'm trying to use AWS cloudSearch on my site, and I'm missing something fundamental. 我正在尝试在我的网站上使用AWS cloudSearch,而且我遗漏了一些基本的东西。 I've had no luck finding a working example. 我没有找到一个有效的例子。

In my HTML head I've included the SDK. 在我的HTML头文件中,我已经包含了SDK。 per: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-intro.html per: http//docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-intro.html

<script type="text/javascript" src="https://sdk.amazonaws.com/js/aws-sdk-2.0.31.min.js"></script>

Then in my script tag I have this snippet (with my creds, not the ones shown here). 然后在我的脚本标签中我有这个片段(我的信条,而不是这里显示的)。 I used hard coded creds for my testing per: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html 我使用硬编码信用证进行测试: http//docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html

var s3 = new AWS.S3({region: 'ap-southeast-2', maxRetries: 15});
AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});
console.log(AWS);
//
var cloudsearch = new AWS.CloudSearch();

When it tries to execute the last line javaScript tells me: Uncaught TypeError: undefined is not a function 当它尝试执行最后一行时,javaScript告诉我:Uncaught TypeError:undefined不是函数

I've been unable to find a demo, example or tutorial. 我一直无法找到演示,示例或教程。 The docs don't even have working examples. 文档甚至没有工作示例。

Can you help? 你能帮我吗?

Thank you for your time. 感谢您的时间。

That error is saying it doesn't find reference to cloudsearch when you are calling the new AWS.Cloudsearch() . 该错误表示当您调用新的AWS.Cloudsearch()时,它找不到对cloudsearch的引用。

The script you reference doesn't appear to have a reference to cloudsearch api. 您引用的脚本似乎没有对cloudsearch api的引用。 I think you need to build it out like they specify in Building the SDK for Use in the Browser . 我认为您需要像在构建浏览器中使用的SDK中指定的那样构建它。

For kicks I replicated the error you received, then did a browser build as specified by the link above. 对于踢,我复制了你收到的错误,然后做了上面的链接指定的浏览器构建。 It worked. 有效。

Upon further investigation after looking through the libraries. 在浏览图书馆后进一步调查。 I think you probably want to use CloudSearchDomain to issue searches to a given domain setup within cloudsearch. 我想您可能希望使用CloudSearchDomain向cloudsearch中的给定域设置发出搜索。

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html

The other cloudsearch library is all administrative/setup related to Search domain creation and other administrative types of objects. 另一个云搜索库是与搜索域创建和其他管理类型的对象相关的所有管理/设置。 Looks like there are some issues with CORS/setup for cloudsearch in general so if you want to issue this straight from the browser might be a bit tricky. 看起来一般来说云搜索的CORS /设置存在一些问题,所以如果你想直接从浏览器发出这个问题可能有点棘手。

The most common way to get around the CORS issue is to use a proxy. 解决CORS问题的最常见方法是使用代理。

The easiest way to play around with search from the browser\\local is using a form, as suggested here. 从浏览器\\ local搜索搜索的最简单方法是使用表单,如此处所示。

Amazon CloudSearch query Amazon CloudSearch查询

<form action="https://$YOURSEARCHDOMAIN/2013-01-01/search" method="get">
    <label>Search: <input name="q" /></label>
    <input type="hidden" name="q.parser" value="simple" />
    <button type="submit">Search</button>
</form>

above solution is pretty much cut and paste\\play, works like the AWS cloudsearch console, and returns the json to the browser. 上面的解决方案几乎是cut and paste \\ play,就像AWS cloudsearch控制台一样,并将json返回给浏览器。 Not sure if you can incorporate suggests without the api directly. 不确定你是否可以在不使用api的情况下加入建议。 You will need to open up your access policy to work, I believe. 我相信你需要打开你的访问政策才能工作。

I tried a variety of access policies and various tricks to get around the CORS issue, all no dice. 我尝试了各种访问策略和各种技巧来解决CORS问题,所有这些都没有骰子。

You actually need the CORS plugin for chrome to make this work properly. 实际上,您需要使用chrome的CORS插件才能使其正常工作。

Created an angularjs project that demos this and added to git hub. 创建了一个angularjs项目,演示了这个并添加到git hub。 You need CORS-anywhere to route properly to the domain. 您需要CORS-anywhere以正确路由到域。

https://github.com/tkntobfrk/amazon-cloudsearch-angular https://github.com/tkntobfrk/amazon-cloudsearch-angular

project uses suggesters to search domain data and populate the input field with autocomplete data. 项目使用建议器搜索域数据并使用自动完成数据填充输入字段。 Uses bootstrap.ui typeahead. 使用bootstrap.ui typeahead。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM