In order to use these directions, you must have access to the your Apache Solr installation including solrconfig.xml and elevate.xml.
By default, Apache Solr does not use the QueryElevationComponent (which enables the administrator to manipulate query results) in the default request handler. This page is a guide on how to use QueryElevationComponent to artificially promote nodes based on a search query.
Part 1: Making Apache Solr’s request handler use elevate.xml by default.
Determine what is Apache Solr’s default request handler. Within the Apache Solr Search Integration module's solrconfig.xml, the default handler is called "partitioned" and occurs at or around lines 458-504. If you are not using this module’s solrconfig.xml, you can determine the default request handler at http://wiki.apache.org/solr/SolrRequestHandler
You need to modify this default request handler to include the QueryElevationComponent component. To modify the Apache Solr Search Integration module's solrconfig.xml, add <str>elevator</str>
into <arr name="last-components">
at the end (at or about line 503). The end result should look like this:
<requestHandler name="partitioned" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="defType">dismax</str>
<str name="echoParams">explicit</str>
<bool name="omitHeader">true</bool>
<float name="tie">0.01</float>
<str name="qf">
body^40.0 title^5.0 name^3.0 taxonomy_names^2.0 tags_h1^5.0 tags_h2_h3^3.0 tags_h4_h5_h6^2.0 tags_inline^1.0
</str>
<str name="pf">
body^2.0
</str>
<int name="ps">15</int>
<!-- Abort any searches longer than 4 seconds -->
<!-- <int name="timeAllowed">4000</int> -->
<str name="mm">
2<-35%
</str>
<str name="q.alt">*:*</str>
<!-- example highlighter config, enable per-query with hl=true -->
<str name="hl">true</str>
<str name="hl.fl">body</str>
<int name="hl.snippets">3</int>
<str name="hl.mergeContiguous">true</str>
<!-- instructs Solr to return the field itself if no query terms are
found -->
<str name="f.body.hl.alternateField">body</str>
<str name="f.body.hl.maxAlternateFieldLength">256</str>
<!-- JS: I wasn't getting good results here... I'm turning off for now
because I was getting periods (.) by themselves at the beginning of
snippets and don't feel like debugging anymore. Without the regex is
faster too -->
<!--<str name="f.body.hl.fragmenter">regex</str>--> <!-- defined below -->
<!-- By default, don't spell check -->
<str name="spellcheck">false</str>
<!-- Defaults for the spell checker when used -->
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.extendedResults">false</str>
<!-- The number of suggestions to return -->
<str name="spellcheck.count">1</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
<str>elevator</str>
</arr>
</requestHandler>
Part 2: Modify elevate.xml to have your search query return a specific node.
Make sure elevate.xml is located in the conf directory of your Apache Solr installation. If it is not, you can create one from http://wiki.apache.org/solr/QueryElevationComponent
Determine the ID node that you want to manipulate. You can do this by searching the Apache Solr server directly at http://localhost:8983/solr/admin/, where ‘localhost’ is the URL or your Solr server, and 8983 is the port.
Search using a query that you know will find the appropriate node. The search will return an XML document. Find your node in the results, and look for the <str name="id">
subelement. The value of this will be something like 9c3ec5/node/3564, where the first six characters are a hash of your specific site, and the last section is the node ID.
Take this value and plug it into the elevate.xml as follows:
<elevate>
<query text="foo bar">
<doc id="9c3ec5/node/3564" />
</query>
</elevate>
For more information on the QueryElevationComponent and elevate.xml see http://wiki.apache.org/solr/QueryElevationComponent
Part 3: Restart Apache Solr
This is important as it reads in the solrconfig.xml and elevate.xml on startup.
All Done!
In the above example, the next time you search for "foo bar", the first item in the result should be the document you specified (node 3564).
Good Luck!
Please note that this guide was created using Apache Solr version 1.4.1
Comments
Thank you for the
Thank you for the documentation, really handy for manipulating search results.
How to elevate on drupal side?
So, it works when I perform the search in the query tab on the server interface, but when searching for "foo" in drupal 8 search view it doesn't return any data. What am I missing here? Best bets module does the job but just for Datasources "Content" but not "Solr Document".
Using solr search API module.
Would appreciate any help.