I have start learning Solr, and trying to understand and implement same query like one i have done in mysql, to return results in same order and logic.
What i need:
default mysql example query / without search params:
SELECT
*
FROM
postings Postings
// LEFT JOIN query ..
WHERE
(
// where query..
)
ORDER BY
Postings.premium DESC, // <--- bool (1),
FIELD(Postings.source, "local") DESC,
Postings.cpc DESC
and example with search parameter:
SELECT
MATCH (Postings.title) AGAINST ('developer' IN BOOLEAN MODE) AS `Postings__relavance_title`,
MATCH (Postings.description) AGAINST ('developer' IN BOOLEAN MODE) AS `Postings__relavance_description`,
// other Fields
FROM
postings Postings
// LEFT JOIN queries ...
WHERE
(
MATCH (
Postings.title, Postings.description
) AGAINST ('developer' IN BOOLEAN MODE)
)
ORDER BY
(Postings__relavance_title * 2)+ Postings__relavance_description DESC,
Postings.premium DESC, // <--- bool (1)
FIELD(Postings.source, "local") DESC,
Postings.cpc DESC
How to sort / order solr data in same way?
Here is solution for our task:
We must:
select fields like:
fl=score,*
boost query fields, like:
bq=source:local^50 (premium:true^100 OR premium:false^0)
and sort by score:
sort=score DESC, created DESC
in solr schema:
<field name="premium" type="boolean" indexed="true" stored="true"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With