Keith Nordstrom
Keith Nordstrom

Reputation: 354

Stratio Lucene Index 3.0.9: Purpose of INet mapper

From the docs for the Stratio Lucene Index Plugin, the INet mapper looks interesting but there's not a lot of motivation behind it: ie. https://github.com/Stratio/cassandra-lucene-index/blob/branch-3.0.9/doc/documentation.rst#inet-mapper.

Given that it represents an IP address (typed) and is therefore distinct from being simple a string, what sort of queries can I apply to it? In particular, is it possible to do a ranged query on it?

Upvotes: 0

Views: 37

Answers (1)

Lucene index inet mapper is intended to map CQL inet data type. The only advantage on it is to make parsing more flexible. For example, given the following data:

CREATE TABLE t (
    pk int PRIMARY KEY,
    address inet
) ;

CREATE CUSTOM INDEX i ON t () 
USING 'com.stratio.cassandra.lucene.Index' 
WITH OPTIONS = {
  'refresh_seconds': '1',
  'schema': '{
       fields : {
          address : {type: "inet"},
          address_s : {type: "string", column: "address"}
       }
    }'};

INSERT INTO t(pk, address) VALUES (0, '::FFFF:8:8:8');

All these queries will found the indexed row:

SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "::ffFF:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "::0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "0:0:0:0:ffff:8:8:8"}}');

However, the same queries wouldn't work with a string mapper:

SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "::ffFF:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "::0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "0:0:0:0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"wildcard", field:"address_s", value: "*:8:8:8"}}');

Aside from this, the generated Lucene field is a string field, so there is no special treatment for wildcard or range queries, that should use the expanded format of the IP address and will have a lexicographical behaviour:

SELECT * FROM t WHERE expr(i, '{filter:{type:"wildcard", field:"address", value: "*:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"range", field:"address", lower: "::FFFF:8:8:7"}}');

Upvotes: 1

Related Questions