<commit_before>//Proximity flag

var tape = require('tape');
var Carmen = require('..');
var index = require('../lib/index');
var mem = require('../lib/api-mem');
var addFeature = require('../lib/util/addfeature');

var conf = {
    country: new mem({maxzoom: 1}, function() {}),
    province: new mem({maxzoom: 6}, function() {})
};
var c = new Carmen(conf);

tape('index country', function(t) {
    var country = {
        _id:1,
        _text:'country',
        _zxy:['1/0/0'],
        _center:[-100,60]
    };
    addFeature(conf.country, country, t.end);
});
tape('index country', function(t) {
    var country = {
        _id:2,
        _text:'country',
        _zxy:['1/0/1'],
        _center:[-60,-20]
    };
    addFeature(conf.country, country, t.end);
});

//Across layers
tape('index province', function(t) {
    var province = {
        _id:1,
        _text:'province',
        _zxy:['6/17/24'],
        _center:[-80,40]
    };
    addFeature(conf.province, province, t.end);
});
tape('index province', function(t) {
    var country = {
        _id:3,
        _text:'province',
        _zxy:['1/1/0'],
        _center:[145,70]
    };
    addFeature(conf.country, country, t.end);
});

tape('forward country - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, proximity: [-60,-20] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.2', 'found country.2');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, proximity: [-100,60] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - multi layer - limit', function(t) {
    c.geocode('province', { limit_verify: 1, }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - single layer', function(t) {
    c.geocode('country', { }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer', function(t) {
    c.geocode('country', { proximity: [-60,-20] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.2', 'found country.2');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer', function(t) {
    c.geocode('country', { proximity: [-100,60] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - multi layer', function(t) {
    c.geocode('province', { }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

//If two results are returned prox will only sort if the relev and idx are the same
tape('forward country - repect layer presidence', function(t) {
    c.geocode('province', { proximity: [-80,40] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('index.teardown', function(assert) {
    index.teardown();
    assert.end();
});

<commit_msg>Add better test for multiple subq + proximity. [ci skip]<commit_after>//Proximity flag

var tape = require('tape');
var Carmen = require('..');
var index = require('../lib/index');
var mem = require('../lib/api-mem');
var addFeature = require('../lib/util/addfeature');

var conf = {
    country: new mem({maxzoom: 1}, function() {}),
    province: new mem({maxzoom: 6}, function() {})
};
var c = new Carmen(conf);

tape('index country', function(t) {
    var country = {
        _id:1,
        _text:'country',
        _zxy:['1/0/0'],
        _center:[-100,60]
    };
    addFeature(conf.country, country, t.end);
});
tape('index country', function(t) {
    var country = {
        _id:2,
        _text:'country',
        _zxy:['1/0/1'],
        _center:[-60,-20]
    };
    addFeature(conf.country, country, t.end);
});

//Across layers
tape('index province', function(t) {
    var province = {
        _id:1,
        _text:'province',
        _zxy:['6/17/24'],
        _center:[-80,40]
    };
    addFeature(conf.province, province, t.end);
});
tape('index province', function(t) {
    var country = {
        _id:3,
        _text:'province',
        _zxy:['1/1/0'],
        _center:[145,70]
    };
    addFeature(conf.country, country, t.end);
});
tape('index province', function(t) {
    var province = {
        _id:2,
        _text:'fakeprov',
        _zxy:['6/14/18'],
        _center:[-100,60]
    };
    addFeature(conf.province, province, t.end);
});
tape('index province', function(t) {
    var province = {
        _id:3,
        _text:'fakeprov',
        _zxy:['6/21/35'],
        _center:[-60,-20]
    };
    addFeature(conf.province, province, t.end);
});


tape('forward country - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, proximity: [-60,-20] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.2', 'found country.2');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer - limit', function(t) {
    c.geocode('country', { limit_verify: 1, proximity: [-100,60] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - multi layer - limit', function(t) {
    c.geocode('province', { limit_verify: 1, }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - single layer', function(t) {
    c.geocode('country', { }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer', function(t) {
    c.geocode('country', { proximity: [-60,-20] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.2', 'found country.2');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - proximity - single layer', function(t) {
    c.geocode('country', { proximity: [-100,60] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'country', 'found country');
        t.equals(res.features[0].id, 'country.1', 'found country.1');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

tape('forward country - multi layer', function(t) {
    c.geocode('province', { }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

//If two results are returned prox will only sort if the relev and idx are the same
tape('forward country - repect layer presidence', function(t) {
    c.geocode('province', { proximity: [-80,40] }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'province', 'found province');
        t.equals(res.features[0].id, 'country.3', 'found country.3');
        t.equals(res.features[0].relevance, 0.99);
        t.end();
    });
});

// Test proximity with multi-part query
tape('forward province - multilayer', function(t) {
    c.geocode('fakeprov country', { proximity: [-100,60], limit_verify:1 }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'fakeprov, country', 'found province');
        t.equals(res.features[0].id, 'province.2', 'found province.2');
        t.equals(res.features[0].relevance, 1);
        t.end();
    });
});

// Test proximity with multi-part query
tape('forward province - multilayer', function(t) {
    c.geocode('fakeprov country', { proximity: [-60,-20], limit_verify:1 }, function (err, res) {
        t.ifError(err);
        t.equals(res.features[0].place_name, 'fakeprov, country', 'found province');
        t.equals(res.features[0].id, 'province.3', 'found province.3');
        t.equals(res.features[0].relevance, 1);
        t.end();
    });
});

tape('index.teardown', function(assert) {
    index.teardown();
    assert.end();
});


{'fraction_non_alphanumeric': 0.19952881478796666, 'fraction_numerical': 0.028633562885103298, 'mean_word_length': 2.816390041493776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6870173', 'n_tokens_mistral': 3951, 'n_tokens_neox': 3793, 'n_words': 732}