Build Status

Solr Redis Extensions

This extension is a ParserPlugin that provides a Solr query parser based on data stored in Redis.

RedisQParserPlugin creates a connection with Redis and passes the connection object to RedisQParser responsible for fetching data and building a query.

Quick start

Build with Maven:

mvn install

Put the library (solr-redis-*.jar) in Solr lib directory ($SOLR_HOME/lib).

Configure the query parser plugin in solrconfig.xml. Add the following to the "config" section of solrconfig.xml:

<queryParser name="redis" class="com.sematext.solr.redis.RedisQParserPlugin">
  <str name="host">localhost</str>
  <str name="maxConnections">30</str>
  <str name="retries">2</str>
</queryParser>

Usage

Allowed parameters for the RedisQParserPlugin:

GET specific parameters:

SRANDMEMBER specific parameters:

SDIFF, SINTER and SUNION specific parameters;

ZRANGEBYSCORE and ZREVRANGEBYSCORE specific parameters:

ZRANGE and ZREVRANGE specific parameters:

HGET specific parameters:

HMGET specific parameters:

LRANGE specific parameters:

LINDEX specific parameters:

MGET specific parameters:

SORT specific parameters:

EVAL specific parameters:

EVALSHA specific parameters:

Examples of usage:

Allowed configuration parameter for RedisQParserPlugin (section in solrconfig.xml):

Highlighting

SolrRedis plugin is able to highlight matching parts of documents which are used in redis query. Highlighting used in SolrRedis plugin is fully compatible with default Solr highlighter and supports all parameters passed to Solr highlighter.

Configuration

To use highlighter it has to be configured in solrconfig.xml file. SolrRedis highlighter uses class TaggedqueryHighlighter which is responsible for highlighting document parts matched to Redis query.

<searchComponent class="solr.HighlightComponent" name="highlight">
   <highlighting class="com.sematext.solr.highlighter.TaggedQueryHighlighter"/>
</searchComponent>

Usage

You have to remember that highlighting will work only for string and text fields due to issued in Lucene/Solr (SOLR-2497, LUCENE-3080, SOLR-3050).

curl 'http://localhost:8983/solr/collection1/select?q={!redis command=SMEMBERS key=testKey tag=highlightedField}test_field&hl=true&hl.fl=highlightedField}'

Please note that field used in tag parameter of SolrRedis QParser doesn't have to exist in schema. It is only virtual (tag) field. This is only used to identify matches of which query should be highlighted.

Response

Matching fragments are included in a special section of the response (highlighting section). Client uses the formatting clues (pre and post) also included to determine how to present the snippets to users.

Example of response:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">10</int>
    <lst name="params">
      <str name="q">
        {!redis command=SMEMBERS key=testKey tag=highlightedField}test_field
      </str>
      <str name="hl.fl">highlightedField</str>
      <str name="hl">true</str>
    </lst>
  </lst>
  <result name="response" numFound="1" start="0">
    <doc>
      <str name="id">123</str>
      <str name="test_field">highlighterContent</str>
      <long name="_version_">1487238265204375552</long>
    </doc>
  </result>
  <lst name="highlighting">
    <lst name="123">
      <arr name="highlightedField">
        <str><em>highlighterContent</em></str>
      </arr>
    </lst>
  </lst>
</response>

More complex query examples

curl 'http://localhost:8983/solr/collection1/select?q= \
({!redis command=SMEMBERS key=testKey1 tag=alias1}test_field) OR\
({!redis command=SMEMBERS key=testKey2 tag=alias2}test_field)\
&hl=true&hl.fl=alias1,alias2}

Please note that each Query parser statement ({!redis ....}) should be placed between brackets.

You can also mix SolrRedis highlighting with default Solr highlighting:

curl 'http://localhost:8983/solr/collection1/select?q=
({!redis command=SMEMBERS key=testKey1 tag=alias1}test_field) OR (foo:bar) &hl=true&hl.fl=alias1,foo}

Response will be as below

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">10</int>
    <lst name="params">
      <str name="q">
        {!redis command=SMEMBERS key=testKey1 tag=alias1}test_field OR (foo:bar)
      </str>
      <str name="hl.fl">alias1,foo</str>
      <str name="hl">true</str>
    </lst>
  </lst>
  <result name="response" numFound="2" start="0">
    <doc>
      <str name="id">1</str>
      <str name="test_field">test</str>
      <str name="foo">baz</str>
      <long name="_version_">1487238265204375552</long>
    </doc>
    <doc>
      <str name="id">2</str>
      <str name="test_field">not_test</str>
      <str name="foo">bar</str>
      <long name="_version_">1487238265204375552</long>
    </doc>
  </result>
  <lst name="highlighting">
    <lst name="1">
      <arr name="alias1">
        <str><em>test</em></str>
      </arr>
    </lst>
    <lst name="2">
      <arr name="foo">
        <str><em>bar</em></str>
      </arr>
    </lst>
  </lst>
</response>