Replies: 2 comments
-
Wow, that's quite some work you put into this idea. I'll study it and come back to you! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I like the idea a lot! But for the implementation... I am struggling. First the things I like:
Than what I think you can improve upon:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Would anyone be interested in this package supporting searches across multiple indexes / model types? I feel this is a significant change so instead of opening up a PR, I wanted to see if this is something that would benefit anyone other than myself.
I recently found this package and started integrating it into one of my projects, however I have a few peculiar requirements that I had to work through:
All Results
page which displays results from different model typesThe first one was easy, I simply made
searchableAs
return a different index depending on the current app locale.But the second one is where things got tricky..
Implementation
The easiest approach would've been to just search once per model, merge the results and sort by score once again. However, I know that elasticsearch does support searching against multiple indexes at the same time, So I decided to reduce the amount of queries sent to elasticsearch and have it sort everything for me.
I know that elastic-scout-driver-plus has this sort of
join
feature but I require some flexibility in terms of elasticsearch version. That package won't let me swap away from ES 8 and might make it impossible to move to opensearch down the line.You can find a proof of concept on my fork (https://github.com/a-drew/Explorer/tree/search-across-multiple-indexes) (diff here)
elastic-scout-driver-plus
, I've added some generic classes for representing Hits, Documents and Highlights and modified theResults
class to let me easily grab collections of hits, documents or even models.Hit
is responsible for figuring out its own model.getAliases
method onto theElasticIndexAdapter
so that anIndexConfiguration
could be identified from its aliases.ElasticEngine::map
to support mapping to any model type, this could be further improved to reduce the amount of db queries.Builder
now has 2 new methodsjoin
andjoinMany
, these accept model instances or class names and will update the ES query to search across all the indices for the provided models.Builder
now overridespaginate
andpaginateRaw
returning a custom LengthAwarePaginator that can quickly swap between different search representations.Hit
class is resolved from the container so you can swap it out for your own subclass modify it to your liking.Usage
Ex: Finding Articles and Authors that contain the word
john
Ex: Paginated results containing Articles, Authors and Videos
All other query methods work as expected
Beta Was this translation helpful? Give feedback.
All reactions