I'm using the Search API with a database back-end.

I would like search results that are tagged Editorial to be favoured over results not tagged Editorial. So, for example, if two articles match a search query, and one is tagged Editorial, I'd like to see the Editorial one listed first.

Can this be done?



It would be insanely complex to do this properly, since you need to alter some very core Search API mechanics, much of which is handled by the database backend and not search api itself.

What you could do as a hack, it to

  1. Create two fields: A and B.
  2. Select a non existing word like ethsrtsghtpofksd
  3. Add the word in field A when it's an editorial and in field B when it's not an editoral.
  4. Set the searcg weight for field A to be higher than field B
  5. Add the word to all searches before search API sends it to the DB.

Since the word is used in all searches and it always is matches (either in field A or B) it won't effect the results, but the weight they get will be different since field A will get a boost. I haven't tried this before, but it should work. But like I said it's a hack so it's not a pretty solution, but it's a clever way of avoiding to mess with the internal workings of Search API module.

  • genius, although I use ethsrtsghtpofksd all the time, so I'd have to pick another word. Hmmm. Also considering loading - say 30 - results and sorting those post-search. No-one ever wants more than 30 results anyway! – artfulrobot Mar 30 '12 at 16:06
  • @artfulrobot The problem loading a set of results, is both handling the sorting without messing up how Search API does things especially with facets etc. Also doing that you might end up with close to 0 editorials since they might only start to appear after the loaded set. – googletorp Mar 30 '12 at 16:08
  • yeah. get that. Still, I'm already mangling user input (e.g. to map "youth" to "young people") so I can be pretty sure that if something is relevant it will appear high up. But it's a good point, thanks for your help. – artfulrobot Mar 30 '12 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.