#community-help

Implementing Directory-Specific Search with Typesense

TLDR M inquired about doing directory-specific searches using Typesense. Dima suggested storing all path combinations and using it in array filter. Kishore Nallan provided additional Typesense configuration advice to index special characters. M found these solutions helpful.

Powered by Struct AI
6
1mo
Solved
Join the chat
Aug 12, 2023 (1 month ago)
M
Photo of md5-c91fb7ae97aac6413aae82c46b27590b
M
11:06 AM
Hi everyone. Looking into replacing Elasticsearch with Typesense for some parts of our software and am currently trying to figure out (actually at the end of my own ideas) how to reflect a filesystem so that a search can be limited/filtered to a certain directory/path and its children (recursive). Is that a possible use-case?
Dima
Photo of md5-1b62114a658b760944aa7d2b4c274460
Dima
04:04 PM
I think the easiest way is to store all path combinations (e.g. /, /path, /path/to) in a field and then use it in array filter_by: https://typesense.org/docs/0.24.1/api/search.html#filter-parameters
04:05
Dima
04:05 PM
https://gist.github.com/b0g3r/64d7998b25f8a4b04f94737adc81df70 something like this. You can run docker typesense to test it out
04:06
Dima
04:06 PM
I found that Typesense (at least my version of it) ignores first /, however it shows the proof of concept
Aug 13, 2023 (1 month ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:11 AM
You can configure Typesense to index special characters by using the symbols_to_index configuration during collection creation.


curl -k "" -X POST -H "Content-Type: application/json" \                                                                                                                        
      -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
        "name": "docs",
        "fields": [        
          {"name": "title", "type": "string" },
          {"name": "points", "type": "int32" }
        ], "symbols_to_index": ["/"]
      }'             
Aug 19, 2023 (1 month ago)
M
Photo of md5-c91fb7ae97aac6413aae82c46b27590b
M
10:06 AM
Thanks guys. The array approach seems like a good fit for this.