This is called elevation
in search.
In solr, QueryElevationComponent
might be what you need,
Brief usage step:
- Config the component in
solrconfig.xml
.
- Add a
elevate.xml
, and define the top rows, usually by specify the doc ids.
- When query, use param
enableElevation
/ forceElevation
/ .. to specify whether enable elevation. And yes, it works well with parser DisMax
or eDisMax
.
Refer:
@Update
I updated the above refer link with a better one, check that.
The doc id is the id
field of the doc.
What's more important are:
- The
queryFieldType
attribute of <searchComponent>
, it specify the field type, thus decide the analyzer used, for English text, you might need text_en
, don't use the default string
, which won't analyze the query input.
- Use request-handler
/elevate
instead of /select
, when query.
- Add the param
enableElevation=true&forceElevation=true
, so that to enable elevate sorts.
- the additional field "[elevated]" indicate whether a record is elevated, it has boolean value,
could add the field in 'fl' param,
e.g
fl=*,[elevated]
About params:
enableElevation
, whether enable elevation, it don't override sort, means when sort
param is specified, whether elevated docs are still on top depends on forceElevation
param.
forceElevation
, whether force elevation, it will override sort, means when sort
param is specified, will still put elevated docs at top, then sort other docs.
Here is my example:
solrconfig.xml: (add before </config>
)
<!-- elevation -->
<searchComponent name="elevator" class="org.apache.solr.handler.component.QueryElevationComponent" >
<str name="queryFieldType">text_en</str>
<str name="config-file">elevate.xml</str>
</searchComponent>
<requestHandler name="/elevate" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr>
</requestHandler>
elevate.xml: (e.g put it in solr-5.4.1/server/solr/dummy/conf/
)
<?xml version="1.0" encoding="UTF-8" ?>
<elevate>
<query text="Eric">
<doc id="1" />
<doc id="2" />
<doc id="3" />
</query>
</elevate>
This file is load once on startup, after change, need reload the core, e.g via solr admin.
query example: