/*
* Copyright 2000-2013 Enonic AS
* http://www.enonic.com/license
*/
package com.enonic.cms.core.search.query;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Test;
import com.enonic.cms.core.content.index.ContentIndexQuery;
public class QueryTranslator_notLikeTest
extends QueryTranslatorTestBase
{
@Test
public void testNotLike_characters()
throws Exception
{
String expected_search_result = "{\n" +
" \"from\" : 0,\n" +
" \"size\" : 1000,\n" +
" \"query\" : {\n" +
" \"filtered\" : {\n" +
" \"query\" : {\n" +
" \"bool\" : {\n" +
" \"must\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"must_not\" : {\n" +
" \"wildcard\" : {\n" +
" \"title\" : {\n" +
" \"wildcard\" : \"boat*\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
ContentIndexQuery query = createContentQuery( "title NOT LIKE \"Boat*\"" );
SearchSourceBuilder builder = getQueryTranslator().build( query );
compareStringsIgnoreFormatting( expected_search_result, builder.toString() );
}
@Test
public void testNotLike_special_characters()
throws Exception
{
String expected_search_result = "{\n" +
" \"from\" : 0,\n" +
" \"size\" : 1000,\n" +
" \"query\" : {\n" +
" \"filtered\" : {\n" +
" \"query\" : {\n" +
" \"bool\" : {\n" +
" \"must\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"must_not\" : {\n" +
" \"wildcard\" : {\n" +
" \"title\" : {\n" +
" \"wildcard\" : \"*$&*\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
ContentIndexQuery query = createContentQuery( "title NOT LIKE \"*$&*\"" );
SearchSourceBuilder builder = getQueryTranslator().build( query );
compareStringsIgnoreFormatting( expected_search_result, builder.toString() );
}
@Test
public void testNotLike_backslash()
throws Exception
{
String expected_search_result = "{\n" +
" \"from\" : 0,\n" +
" \"size\" : 1000,\n" +
" \"query\" : {\n" +
" \"filtered\" : {\n" +
" \"query\" : {\n" +
" \"bool\" : {\n" +
" \"must\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"must_not\" : {\n" +
" \"wildcard\" : {\n" +
" \"title\" : {\n" +
" \"wildcard\" : \"*\\\\*\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
ContentIndexQuery query = createContentQuery( "title NOT LIKE \"*\\\\*\"" );
SearchSourceBuilder builder = getQueryTranslator().build( query );
compareStringsIgnoreFormatting( expected_search_result, builder.toString() );
}
}