<commit_before>/*
 * Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Indoqa licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.indoqa.solr.spatial.corridor.direction;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import com.indoqa.solr.spatial.corridor.EmbeddedSolrInfrastructureRule;

public class TestDirection {

    private static final String SOLR_FIELD_ID = "id";

    private static final String DOCUMENT_ID_1 = "route-hietzing-stadtlau";
    private static final String DOCUMENT_ID_2 = "route-wien-marchegg";

    @ClassRule
    public static EmbeddedSolrInfrastructureRule infrastructureRule = new EmbeddedSolrInfrastructureRule();

    @Test
    public void exactMatchBackwards() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_2, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchForwards() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.43768 48.20753)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchBackwardsBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1} inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "false");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_2, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchBidirectionalBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1} inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "true");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(2, response.getResults().getNumFound());
    }

    @Test
    public void exactMatchForwardsBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1}inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "false");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void notEnoughPoints() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.41654 48.19311)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(2, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
        assertEquals(DOCUMENT_ID_2, response.getResults().get(1).getFieldValue(SOLR_FIELD_ID));
    }

    @Test<commit_msg>added test for boolean defaults<commit_after>/*
 * Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Indoqa licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.indoqa.solr.spatial.corridor.direction;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import com.indoqa.solr.spatial.corridor.EmbeddedSolrInfrastructureRule;

public class TestDirection {

    private static final String SOLR_FIELD_ID = "id";

    private static final String DOCUMENT_ID_1 = "route-hietzing-stadtlau";
    private static final String DOCUMENT_ID_2 = "route-wien-marchegg";

    @ClassRule
    public static EmbeddedSolrInfrastructureRule infrastructureRule = new EmbeddedSolrInfrastructureRule();

    @Test
    public void exactMatchBackwards() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_2, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchForwards() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.43768 48.20753)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchBackwardsBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1} inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "false");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_2, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void exactMatchBidirectionalBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1} inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "true");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(2, response.getResults().getNumFound());
    }

    @Test
    public void exactMatchForwardsBoolean() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1}inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.43768 48.20753)");
        query.add("corridor.maxAngleDifference", "90");
        query.add("corridor.bidirectional", "false");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(1, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
    public void booleanWithDefaults() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=1}inPointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.44175 48.2103)");
        query.add("corridor.point", "POINT(16.43768 48.20753)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(0, response.getResults().getNumFound());
    }

    @Test
    public void notEnoughPoints() throws SolrServerException, IOException {
        SolrQuery query = new SolrQuery("{!frange l=0 u=90}pointsDirection(geo, geoHash)");
        query.setRows(Integer.MAX_VALUE);
        query.add("corridor.point", "POINT(16.41654 48.19311)");

        QueryResponse response = infrastructureRule.getSolrClient().query(query);
        assertEquals(2, response.getResults().getNumFound());
        assertEquals(DOCUMENT_ID_1, response.getResults().get(0).getFieldValue(SOLR_FIELD_ID));
        assertEquals(DOCUMENT_ID_2, response.getResults().get(1).getFieldValue(SOLR_FIELD_ID));
    }

    @Test
{'fraction_non_alphanumeric': 0.12291527685123416, 'fraction_numerical': 0.03860907271514343, 'mean_word_length': 4.169396551724138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5938578', 'n_tokens_mistral': 3879, 'n_tokens_neox': 3547, 'n_words': 730}