<commit_before>// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/attribute/attribute.h>
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/searchlib/attribute/attributevector.hpp>
#include <vespa/searchlib/attribute/attrvector.h>
#include <vespa/searchlib/attribute/iattributemanager.h>
#include <vespa/searchlib/attribute/multinumericattribute.h>
#include <vespa/searchlib/attribute/multinumericpostattribute.hpp>
#include <vespa/searchlib/attribute/singlenumericattribute.h>
#include <vespa/searchlib/common/geo_location.h>
#include <vespa/searchlib/common/location.h>
#include <vespa/searchlib/common/locationiterators.h>
#include <vespa/vespalib/gtest/gtest.h>

#include <vespa/log/log.h>
LOG_SETUP("location_iterator_test");

using namespace search;
using namespace search::attribute;
using namespace search::common;
using namespace search::fef;

AttributeVector::SP make_attribute(CollectionType collection, bool fast_search = false) {
    Config cfg(BasicType::INT64, collection);
    cfg.setFastSearch(fast_search);
    return AttributeFactory::createAttribute("my_attribute", cfg);
}

void add_docs(AttributeVector::SP attr_ptr, size_t limit = 1000) {
    AttributeVector::DocId docid;
    attr_ptr->addReservedDoc();
    for (size_t i = 1; i < limit; ++i) {
        attr_ptr->addDoc(docid);
    }
    attr_ptr->commit();
    ASSERT_EQ((limit - 1), docid);
}

using Position = std::pair<int32_t, int32_t>;
using Positions = std::vector<Position>;

constexpr double pi = 3.14159265358979323846;
// microdegrees -> degrees -> radians -> km (using Earth mean radius)
constexpr double udeg_to_km = 1.0e-6 * (pi / 180.0) * 6371.0088;

class SingleIteratorTest : public ::testing::Test {
private:
    AttributeVector::SP   _attr;
    IntegerAttribute *    _api;
    TermFieldMatchData    _tfmd;
    std::vector<Position> _positions;

    void set_doc(IntegerAttribute *ia, uint32_t docid, const Position &p) {
	ia->clearDoc(docid);
	int64_t value = vespalib::geo::ZCurve::encode(p.first, p.second);
	LOG(debug, "single: value for docid %u is %zd", docid, value);
	ia->update(docid, value);
	ia->commit();
        if (docid >= _positions.size()) {
            _positions.resize(1+docid);
        }
        _positions[docid] = p;
    }

    void populate_single(IntegerAttribute *ia) {
	Position invalid(0, 0x80000000);
	set_doc(ia, 1, Position(10000, 15000));
	set_doc(ia, 3, invalid);
	set_doc(ia, 5, Position(20000, -25000));
	set_doc(ia, 7, Position(-30000, 35000));
    }

public:
    SingleIteratorTest()
      : _attr(make_attribute(CollectionType::SINGLE, true)),
        _api(dynamic_cast<IntegerAttribute *>(_attr.get()))<commit_msg>Fix format string in location iterator unit test.<commit_after>// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/attribute/attribute.h>
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/searchlib/attribute/attributevector.hpp>
#include <vespa/searchlib/attribute/attrvector.h>
#include <vespa/searchlib/attribute/iattributemanager.h>
#include <vespa/searchlib/attribute/multinumericattribute.h>
#include <vespa/searchlib/attribute/multinumericpostattribute.hpp>
#include <vespa/searchlib/attribute/singlenumericattribute.h>
#include <vespa/searchlib/common/geo_location.h>
#include <vespa/searchlib/common/location.h>
#include <vespa/searchlib/common/locationiterators.h>
#include <vespa/vespalib/gtest/gtest.h>

#include <vespa/log/log.h>
LOG_SETUP("location_iterator_test");

using namespace search;
using namespace search::attribute;
using namespace search::common;
using namespace search::fef;

AttributeVector::SP make_attribute(CollectionType collection, bool fast_search = false) {
    Config cfg(BasicType::INT64, collection);
    cfg.setFastSearch(fast_search);
    return AttributeFactory::createAttribute("my_attribute", cfg);
}

void add_docs(AttributeVector::SP attr_ptr, size_t limit = 1000) {
    AttributeVector::DocId docid;
    attr_ptr->addReservedDoc();
    for (size_t i = 1; i < limit; ++i) {
        attr_ptr->addDoc(docid);
    }
    attr_ptr->commit();
    ASSERT_EQ((limit - 1), docid);
}

using Position = std::pair<int32_t, int32_t>;
using Positions = std::vector<Position>;

constexpr double pi = 3.14159265358979323846;
// microdegrees -> degrees -> radians -> km (using Earth mean radius)
constexpr double udeg_to_km = 1.0e-6 * (pi / 180.0) * 6371.0088;

class SingleIteratorTest : public ::testing::Test {
private:
    AttributeVector::SP   _attr;
    IntegerAttribute *    _api;
    TermFieldMatchData    _tfmd;
    std::vector<Position> _positions;

    void set_doc(IntegerAttribute *ia, uint32_t docid, const Position &p) {
	ia->clearDoc(docid);
	int64_t value = vespalib::geo::ZCurve::encode(p.first, p.second);
	LOG(debug, "single: value for docid %u is %" PRId64, docid, value);
	ia->update(docid, value);
	ia->commit();
        if (docid >= _positions.size()) {
            _positions.resize(1+docid);
        }
        _positions[docid] = p;
    }

    void populate_single(IntegerAttribute *ia) {
	Position invalid(0, 0x80000000);
	set_doc(ia, 1, Position(10000, 15000));
	set_doc(ia, 3, invalid);
	set_doc(ia, 5, Position(20000, -25000));
	set_doc(ia, 7, Position(-30000, 35000));
    }

public:
    SingleIteratorTest()
      : _attr(make_attribute(CollectionType::SINGLE, true)),
        _api(dynamic_cast<IntegerAttribute *>(_attr.get()))
{'fraction_non_alphanumeric': 0.13191194314439245, 'fraction_numerical': 0.03466805338880222, 'mean_word_length': 4.9730848861283645, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2016734', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1914, 'n_words': 394}