Hi,
I'm using Search API programmatically (via GraphQL) and while using MLT queries I can't seem to set the boost on the fields used for comparison.
From discussing this on DrupalChat it was suggested I bring this up in the Search API issue queue since the only other option is to resort to hook alters (which we can't do as we are decoupled and have too many consumers with different needs).
I did manage to make this work with "solr_param" but the drawback is I need to specify the prefixes (which are hard to know from the frontend side).
Is there a possibility to support this?
I would be happy to assist with patches where needed.
Thanks!
Comments
Comment #2
kyuubi commentedComment #3
drunken monkeyHuh, just realized we neglected to actually properly define the
search_api_mltfeature anywhere in Drupal 8!However, if we do that, I guess we can just add a third parameter,
field boosts(or similar) to thesearch_api_mltoption. It should probably be an associative array, mapping field names to their boosts. And backends should be explicitly allowed to ignore them (which we couldn’t really prevent anyways, of course – but just to do things properly, since we’re changing an existing feature).Once it’s in the defintion, you can go to the Solr module and provide a patch there for supporting the new option.
I’m attaching a patch with a proposed feature definition. Please review!
Comment #4
borisson_For the "field boosts"-key, we explictly say that it is optional. For the fields key we don't but they both seem to be optional.
It would be nice to mark them in the same way?
Otherwise I think this is sufficient documentation about this.
Comment #5
mkalkbrennerI agree with Thomas' suggestion. But the UI to set the fields and their boosts should be added to Search API, just like for the other field boosts.
Comment #6
drunken monkeyWhy do you think
fieldsis optional, too?Looking at
\Drupal\search_api\Plugin\views\argument\SearchApiMoreLikeThis::query(), this is always set, and\Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getMoreLikeThisQuery()also expects it to always be present.So, I wouldn’t say it’s optional. It might have made sense to make it optional, but since it’s already used otherwise (and would, I think, add additional work for implementing backends), I don’t think we should change that.
The optional part is whether the backend actually looks at the setting, but it should always be set by modules using the feature, I’d say. (We could also remove that last sentence, basically saying backends need to take this into account, but I don’t see a point in that.)
I think a UI for this would be overkill at this point. Using this in custom search code, or in an alter hook, makes sense, but for the UI I’d say this is too much of a niche feature. If enough people speak up for it, we can still add a UI in a follow-up (and of course it should be in the Search API then), but I doubt that that will happen.
Comment #7
mkalkbrennerI just want to ensure that search_api_solr isn't responsible to alter the existing UI to add this feature. In case a UI is required it would be easier to implement it in search_api itself. If we don't offer a UI at all, I'm fine with it.
Comment #8
borisson_I think that was because it says: Backends can choose to ignore this field..
Comment #9
drunken monkeyAh, yes, that’s what I figured then. But it’s optional in the other direction, so to speak, in that case. It still has to be provided.
But so this is RTBC in both your opinions?
Comment #10
borisson_Yep!
Comment #12
drunken monkeyExcellent, thanks!
Committed.
Thanks again for weighing in, everyone!