I'm trying to replace my current search bar, located in the header of my React app, using SearchBox from SearchUI.
When a user clicks a match I use onSelectAutocomplete to apply some custom logic to decide what page I redirect them to, which works fine.
But if the user types a partial match and hits enter, I would like to collect all the results and redirect him to a search page, where I display all the results with facets.
I can't figure out how I can get the results so I can forward the user to the search page.
You should be able to override the onSubmit function to redirect the customer to the search page, providing the query in the url. Autocomplete | Elastic docs
Thank you for the fast reply.
So if I redirect them to the search page, I need to do another search, not use the existing results?
And one more unrelated question: after the redirect, the search term is not cleared from SearchBox. Can you please tell me how I can clear the search term?
Thanks!
So the example I shared above is where the search box is present globally on the site and the onSubmit handler will navigate the user to the global search page. On the search page, the search experience has the search term populated, to reflect the search state.
Is there a reason why you dont want the searchbox to reflect what is the search state?
It makes sense to leave the search term in the search box while on the global search page, but if I navigate away from the search page, the search term still remains in the SearchBox.
In this case, I would like to clear the search term.
Thanks for all the rapid replies!
I have two final questions if you are still able to help, although it's not related to the topic:
is there a way to add two fields with custom formatting to SearchBox titleField? eg. 'name - description'
The facets currently show fields that have empty strings, is there a way to exclude them?
1- Could you explain more on how you want it to be custom formatted, potentially a screenshot of what you want?
2 - is there a way you can stop indexing empty values into the field? Its not ideal to exclude them at presentation.
the SearchBox autocompleteResults titleField seems to accept only one field.
But I would like to display two fields. "field1 - field2".
If I have:
{
field1: "foo",
field2: "bar",
}
When I search for 'foo', I would like to display in the search results: "foo - bar".
As a workaround, I added an extra field that has both values in the format above. Was just wondering if there's a better way to do this.
fixed that by replacing empty values with null.
The thing I couldn't figure out, how to clear the search term from the SearchBox.
If I navigate away from the search page, the search term isn't cleared from my SearchBox.
It makes sense to leave the search term in the search box while on the global search page, but if I navigate away from the search page, the search term still remains in the SearchBox.
In this case, I would like to clear the search term.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.