All,
I’m trying to build a simple search on text list.
The filtered resultset gives write number of rows but incorrect data rows.
Any help is greatly appreciated. Thanks
Sample code:
import Program from './Program.svelte';
import { ProgramsCollection } from '../api/ProgramsCollection';
let programs = [];
let filter = {};
let search = '';
$m: programs = ProgramsCollection.find(filter).fetch();
const handleSubmit = () => {
if (search != '') {
filter = { title: new RegExp(search, 'i') };
} else {
filter = {};
}
};
<div class="panel">
<input class="program-title" type="text" name="search" placeholder="Type to search programs" bind:value={search} />
<button on:click={() => handleSubmit()}>Filter Now </button>
</div>
{#each programs as program, i}
<Program {program} />
{/each}
Can you give us an example of your output? By “right amount but incorrect” you mean that there are eg. 4 programs but the search string is not applied correctly?
Of course you need to subscribe, but I assume you either have a global subscription or the autopublish package installed. If the collection is big, you should reimplement the current solution in a more efficient way, but that does not answer your question now.
You don’t need a text index as the filtering is happening locally at the moment. And as for the database, the regex search works fine, but is generally slow (again, it depends on the collection size).
You can try to display the filter value on the page. I remember having issues that the regex had been considered the same although the string inside has changed. I don’t know what was the exact situation though. You can also doublecheck that the programs var does get recalculated: