Thanks for all of the great suggestions.
I’ve been able to query the search service using ember-ajax and it seems pretty straightfoward.
However, being new to ember I’m struggling with figuring out how to wire up the incoming data from the search engine to the template. I feel like I’m missing something obvious.
Here’s what I have in my routes/search.js:
export default Ember.Route.extend({
ajax: Ember.inject.service(),
model() {
},
searchResults: null,
submit(searchTerm) {
return this.get('ajax').request('api/q/srch', {
method: 'POST',
dataType: 'json',
data: JSON.stringify({
text: searchTerm,
similarity:"TFIDF",
highlights:false,
maxResults:500,
weighted:true
})
}).then(function(data) {
console.log('searched');
return data;
})
.catch(function(error) {
debugger;
});
},
actions: {
hitEngine: function(searchTerm) {
let newResults = this.submit(searchTerm).then(function(data) {
this.set('searchResults', data);
}.bind(this));
}
}
});
Then, in my template, I have the following:
<div id="main_content">
<div class="search_area">
<form>
Search: {{input value=searchTerm type="text" name="search_input" class="search"}}
<button {{action "hitEngine" searchTerm}}>Submit</button>
</form>
</div>
<div class="search_results_area">
{{#each searchResults.data.items as |item|}}
{{item.digest.text}}
{{/each}}
</div>
</div>
One thing that I know is wrong is my use of bind() in the hitEngine action. There must be a more Ember-like way of doing that. But I can’t figure out how to access the data returned by the ajax promise otherwise.
When I use set() to update the value of searchResults, the template does not update even thought the value of searchResults appears to be successfully set.
Sorry for the elementary questions. Having to use ember-ajax threw me for a bit of a loop after expecting to be able to use Ember Data and models right out of the box!
Thanks for the help.