简体   繁体   English

ReactiveSearch,DataSearch和索引用户查询

[英]ReactiveSearch, DataSearch and indexing user query

I'm using the DataSearch from Reactivesearch for an autocomplete feature and I'm trying to figure out how I can take the user's selected query and add that to my autocomplete index hosted at Appbaseio? 我正在使用Reactivesearch的DataSearch来实现自动完成功能,并且试图弄清楚如何将用户选择的查询添加到Appbaseio托管的自动完成索引中?

When I say user's selected query, I mean a query either typed in OR selected from DataSearch component dropdown list. 当我说用户的选定查询时,我的意思是键入一个查询或从DataSearch组件下拉列表中选择一个查询。

Here is what I've come up with so far 到目前为止,这是我想出的

<DataSearch
   componentId="SearchSensor"
   dataField={["original_title"]}
   className="search-bar"
   onValueSelected={
     function(value, cause, source) {
       console.log("current value: ", value)
     }
   }
   iconPosition="right"
   innerclassName={{
     list: "text-item"
   }}
   />

The onValueSelected above is taken straight from the docs . 上面的onValueSelected直接来自docs It seems that is the property that I need to work with in order to do this. 看来这是我需要处理的属性。 I'm just not sure how to connect it to my Appbaseio ES index? 我只是不确定如何将其连接到我的Appbaseio ES索引?

onValueSelected is the correct approach to get the selected value here. onValueSelected是在此处获取所选值的正确方法。 (You can also get the full query with onQueryChange if needed). (如果需要,您还可以使用onQueryChange获取完整查询)。 After getting this selected value in onValueSelected you can index this using a simple fetch request to your elasticsearch index or send it to a backend. onValueSelected获取此选定值后,您可以使用简单的fetch请求将该值onValueSelected您的onValueSelected索引中,或将其发送到后端。 There's also a helper library and the docs for rest you can try. 还有一个帮助程序库 ,您可以尝试其他文档

Also I would recommend pulling the indexing logic to a server instead of exposing it on client side since you would need the write credentials in order to perform a write. 另外,我建议将索引逻辑拉到服务器,而不要在客户端公开,因为您需要写凭据才能执行写操作。 This would keep your write credentials safer. 这样可以使您的写凭据更安全。

For example: 例如:

<DataSearch
  ...
  onValueSelected={(value) => {
    fetch('YOUR_SERVER_URL' or 'Elasticsearch URL', { method: 'POST', body: {...} })
  }
/>

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

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