-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
After you've cloned and set up the library, you might want to go through some examples. Inside the examples directory, you can find three python scripts showcasing the library's capabilities and a README briefly describing what each script demonstrates.
This Wiki page goes into some more detail about what each example is doing and when you might want to use that mode of operation.
To run any example script, first edit the constants at the top of the script. The matrix-nio client will require your homeserver, user id and password to authenticate as you. Additionally, we require the id of the source room (i.e. the room that is to be indexed) and the destination room (i.e. the room where the index will be stored as messages). Optionally, you can tweak the number of messages to index and the maximum size of each individual document event (details below).
When you're satisfied with the script's constants, just run the script from the root directory (as a module).
# Inside matrix-encrypted-search directory
# With an activated virtual environment
python -m examples.basic_indexFor each example, the driver code can be found under the main method. Other methods are individual independent steps in the script.
What it does: Indexes the latest N messages from a given room and searches through them
Mode of operation: If you have a static room (i.e. with no activity, being used for archival purposes), then you can index it in one a big encrypted store and use the lookup table to inexpensively search the archive.
Steps:
- Login using username and password, and sync client with current state of rooms
-
Fetch N messages from provided
SOURCE_ROOM -
Create encrypted index from messages, and then upload in chunks to
DESTINATION_ROOM - For each query, search in the created index and display the results
- Finally, delete the messages in the
DESTINATION_ROOMthat constitute this temporary index
What it does: Creates two indices for a room and searches through them together
Mode of operation: Usually, rooms will have several indices for the last week, last month, the month before that, etc. This example demonstrates how you can search through any combination of those indices.
Steps:
- Login using username and password, and sync client with current state of rooms
-
Fetch N1 messages from provided
SOURCE_ROOM -
Fetch N2 messages from provided
SOURCE_ROOM -
Create two encrypted indices from messages, and then upload them to
DESTINATION_ROOM - For each query, search in both indices simultaneously and display the results
- Finally, delete the messages in the
DESTINATION_ROOMthat constitute this temporary index
What it does: Creates two indices for a room, then merges them into a single index and searches through that
Mode of Operation: This example can be used in case an index is to be demoted and merged with another (say, if you want to merged the "January" index into the catchall "More than two months ago" index when April comes around).
Steps:
- Login using username and password, and sync client with current state of rooms
-
Fetch N1 messages from provided
SOURCE_ROOM -
Fetch N2 messages from provided
SOURCE_ROOM -
Create two encrypted indices from messages, and then upload them to
DESTINATION_ROOM -
Merge the two indices, deleting their databases and uploading the new index to
DESTIONATION_ROOM - For each query, search in the new index and display the results
- Finally, delete the messages in the
DESTINATION_ROOMthat constitute the merged index