Greetings! I’m evaluating typesense as a tools to ...
# community-help
d
Greetings! I’m evaluating typesense as a tools to look for content in the text of books. If someone is reading a particular book, and do a search, I’d like the results for that book to have the highest relevance, but I’d also like to incorporate results from other titles. Each document contains the plaintext content of a paragraph, the code that identifies the book, and other stuff. My hack is to append the current book’s code to the user’s search before submitting it, and to set the
queryBy
to
content, code
, which makes the search return relevant content, and prefer results containing the code. However, by appending the code to the user’s query, I effectively disable the prefix search, because their query is never at end of the query string (the code is). Is there a better way of handling this?
j
Interesting use case! You could split this into two searches in a multi_search request. Search 1: You’d add a filter_by to only search inside the books that the user is reading Search 2: Add a filter_by to exclude the books that the user is reading Then show the results from Search 1 first, if it returns hits. Then show results from Search 2
d
I looked at that, but I’m not sure how I could interleave results and still maintain some kind of relevance order.
j
But it sounds like you want to override the default relevance order if the user is reading a particular book right?
d
That’s right. I guess what I was looking for was some way to add x to the relevance of results for one particular book, so that results from other books would have a higher threshold to meet before appearing in the first page.
j
It’s not possible to do that, but that reminded me, this feature might be closer to what you’re looking for: https://typesense.org/docs/0.24.0/api/search.html#sorting-based-on-conditions
So you can essentially do something like
sort_by: _eval(book_id:<code>)
d
That seems to be the magic I was looking for
Copy code
sort_by: `_text_match:desc,_eval(code: "${book_code}"):desc`
Thank you!
👍 1
Nice product you have here. Well done!
j
Thanks Dave!