简体   繁体   中英

ReactiveSearch running a saved query

I have saved a query in a DB and recalled it for running again. However, I do not know how re-run the query.

I obtain the query in the onChange and saved the value to the DB as a string for recalling later so it can be worked on.

<ReactiveBase app={this.props.app} url={config.elastic.URL} >
        <StateProvider
          onChange={(prevState, nextState) => {
            queryString = nextState;
            console.log('onChange');
          }}

I was looking at a way to put that query string in the DataSearch component if that is the correct thing to do. The query is quite large as I have additional components attached to the search.

If I set the value of the DataSearch to my queryString I can not type in the search bar

<DataSearch
                dataField={this.props.refinement.searchBar}
                componentId="search"
                placeholder="Search books or videos"
                autosuggest={false}
                debounce={debounce}
                showClear={true}
                customQuery={this.props.customQuery}
                defaultValue={this.props.defaultValue}
                value={queryString}
              >
              </DataSearch>

also the query is an elastic search query so I get a search bar full of JSON. I can get the indavidual elements and set queryString to that which gives me half of what I want but with a searchbar I can not type into.

var objectQuery = JSON.parse(selectedQueryString);
queryString = objectQuery.search.value;

Update

This helped in being able to type in the searchBar and update the value and may even be most of the way there for the DataSearch component.

value={this.state.value}
    onChange={(value, triggerQuery, event) => {
        this.setState(
            {
                value,
            },
            () => triggerQuery(),
        );
  }}

You can not push the query string back into the component and let it handle all the components used to create the query. You have to get the values from the query string and set the values of the components again. The query then will be re-run using via the onChange mehtod.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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