Hi there,
I’m in need of a simple full-text search feature. Unfortunately I fail to find a way, due to the need of passing the search input upwards. Any help would be much appreciated.
Page:
export default class Welcome extends React.Component {
constructor (props) {
super(props);
this.handleSearchInput = this.handleSearchInput.bind(this);
}
handleSearchInput(event) {
console.log("event.target.value", event.target.value)
// How do I get event.target.value to the Container, to pass it further to the publications for server side full-text search?
}
render() {
return (
<Content {...this.props}>
<IonItem input>
<input ref="searchBox" type="text" placeholder="Search..." onChange={this.handleSearchInput} />
</IonItem>
</Content>
);
Container
export default createContainer(() => {
// How do I get access to the searchTerm from the wrapped component here?
const sitesHandle = SitesPubs.getSites.subscribe(searchTerm);
const sitesDoc = Sites.find({}).fetch();
const sitesDocExists = !!sitesDoc;
return {
isLoading: !sitesHandle.ready(),
sites: sitesDocExists ? sitesDoc : null,
};
}, Page);
Publication (full text search needs to be server side)
export const getSites = new ValidatedPublication({
name: 'sites.getSites',
validate: null,
run(searchTerm) {
if (this.userId) {
return Sites.find({owner: this.userId});
}
if (searchTerm) {
return Sites.find(
// In the end, I need it server side, here. Because Minimongo does not support full-text search.
{ $text: { $search: searchTerm } },
{
fields: Object.assign({}, Sites.publicFields, scoreField),
sort: scoreField,
});
}
return Sites.find({}, {
fields: Sites.publicFields,
});
},
});
scoreField = {
score: { $meta: "textScore" },
};