When you are searching for results, don't wipe the current result set if
there are some previous results and the current query is returning 0
results. This is pretty common when you start typing, it's weird for the
results to randomly clear when looking for stuff.
I'm noticing duplicate notes in the database, which might happen when
the ingester and writer get spammed with the same note rapidly. Add a
sanity check during the write so that we only ever write a note once.
Fixes: 1cf898e0b2 ("ndb: update nostrdb")
Changelog-Fixed: Fix duplicate notes getting written to nostrdb
Signed-off-by: William Casarin <jb55@jb55.com>
Many different parts of the codebase could be opening transactions when
somewhere higher in the heirarchy on the main thread might already have
an active transaction. This can lead to failed transaction opening which
is bad.
Instead of relying on passing down the transaction to subviews, lets
keep track of the active transactions in a thread-local dictionary. That
way whenever we create a new transaction we can inherit the one that is
already active in the current thread.
Inherited transactions don't end the query when they are garbage
collected, we still expect the first-opened query to do this.
Due to the way the range queries work for newest-first searches, we can
have a situation where the MDB_SET_RANGE gets placed on either the
correct place or just after the correct place. To position the cursor
correctly, we jump back one if the search result prefix doesn't match.
Signed-off-by: William Casarin <jb55@jb55.com>
This allows users of nostrdb to selectively filter notes of any kind during
ingest.
Contact lists too big? Create a filter to reject them.
You only care about notes with specific kinds? Reject everything else.
Damus will use this for rejecting large events that might take up too
much space for storage, such as contact lists.
This commit also switched to ndb_config for configuring nostrdb, because
the arguments to ndb_init were getting out of hand.
Changelog-Added: Added ingest filter setting
Changelog-Changed: Switch to ndb_config for per-session ndb settings
Signed-off-by: William Casarin <jb55@jb55.com>
This changes the search algorithm to be much smarter and more efficient
at searching phrases.
It is also much simpler, using less intermediate data structures.
Signed-off-by: William Casarin <jb55@jb55.com>
Our word parser gets stuck on some notes with utf8 chars. Make sure we
are always advancing so we don't get stuck.
Signed-off-by: William Casarin <jb55@jb55.com>
This patch sets the stage for phrase searching. It collects data into
result sets based on words and the word's associated key. We can use
this data to select the best search results based on adjacent
word_indices.
Signed-off-by: William Casarin <jb55@jb55.com>
We will be writing more indices so I'm trying to clean this up a bit
before this function gets too messy
Signed-off-by: William Casarin <jb55@jb55.com>
custom kind+timestamp comparison function. This is used by lmdb to
perform b+ tree searches over the kind+timestamp index.
Signed-off-by: William Casarin <jb55@jb55.com>
Without this, we could accidently match `pr` for `#p` filters
Fixes: 30ed801285dd ("filters: add initial filter interface")
Signed-off-by: William Casarin <jb55@jb55.com>
This adds a way to construct filters and match them against notes. This
will be used by our query interface in the future.
Signed-off-by: William Casarin <jb55@jb55.com>