<commit_before>var ApiService = require("services/ApiService");
var NotificationService = require("services/NotificationService");
var ResourceService = require("services/ResourceService");
var UrlService = require("services/UrlService");

module.exports = (function($)
{
    var searchParams =
        {
            searchString: "",
            itemsPerPage: App.config.defaultItemsPerPage,
            orderBy     : App.config.defaultSorting,
            page        : 1,
            facets      : "",
            categoryId  : null,
            template    : ""
        };

    // var urlParams =
    //     {
    //         query: "Sofa",
    //         categoryId: 1,
    //         items: 20,
    //         orderBy: "itemName_ASC",
    //         page: 1,
    //         facets: "1,2,3"
    //     };

    return {
        getItemList       : getItemList,
        updateSearchString: updateSearchString,
        setSearchString   : setSearchString,
        setItemsPerPage   : setItemsPerPage,
        setOrderBy        : setOrderBy,
        setPage           : setPage,
        setSearchParams   : setSearchParams,
        setFacets         : setFacets,
        setCategoryId     : setCategoryId
    };

    function getItemList()
    {
        if (searchParams.categoryId || searchParams.searchString.length >= 3)
        {
            if (ResourceService.getResource("itemList").val())
            {
                ResourceService.getResource("itemList").val().total = 0;
            }

            var url = searchParams.categoryId ? "/rest/io/category" : "/rest/io/item/search";

            searchParams.template = searchParams.categoryId ? "Ceres::Category.Item.CategoryItem" : "Ceres::ItemList.ItemListView";

            _setIsLoading(true);

            ApiService.get(url, searchParams)
                .done(function(response)
                {
                    _setIsLoading(false);

                    ResourceService.getResource("itemList").set(response);
                    ResourceService.getResource("facets").set(response.facets);
                })
                .fail(function(response)
                {
                    _setIsLoading(false);

                    NotificationService.error("Error while searching").closeAfter(5000);
                });
        }
    }

    function _setIsLoading(isLoading)
    {
        ResourceService.getResource("itemSearch").set(searchParams);
        ResourceService.getResource("isLoading").set(isLoading);
    }

    /**
     * ?searchString=searchString&itemsPerPage=itemsPerPage&orderBy=orderBy&orderByKey=orderByKey&page=page
     * @param urlParams
     */
    function setSearchParams(urlParams)
    {
        var queryParams = UrlService.getUrlParams(urlParams);

        for (var key in queryParams)
        {
            searchParams[key] = queryParams[key];
        }
    }

    function updateSearchString(searchString)
    {
        searchParams.searchString = searchString;

        searchString = (searchString.length > 0) ? searchString : null;
        UrlService.setUrlParam("query", searchString);
    }

    function setSearchString(searchString)
    {
        searchParams.searchString = searchString;
        searchParams.page = 1;

        setPage(1);
        setFacets("");

        ResourceService.getResource("facets").set({});
        ResourceService.getResource("facetParams").set([]);

        searchString = (searchString.length > 0) ? searchString : null;
        UrlService.setUrlParam("query", searchString);
    }

    function setItemsPerPage(itemsPerPage)
    {
        searchParams.itemsPerPage = itemsPerPage;

        itemsPerPage = (itemsPerPage !== App.config.defaultItemsPerPage) ? itemsPerPage : null;
        UrlService.setUrlParam("items", itemsPerPage);
    }

    function setOrderBy(orderBy)
    {
        searchParams.orderBy = orderBy;

        orderBy = (orderBy !== App.config.defaultSorting) ? orderBy : null;
        UrlService.setUrlParam("orderBy", orderBy);
    }

    function setPage(page)
    {
        searchParams.page = page;

        page = (page > 1) ? page : null;
        UrlService.setUrlParam("page", page);
    }

    function setFacets(facets)
    {
        searchParams.facets = facets.toString();

        facets = (facets.toString().length > 0) ? facets.toString() : null;

        setPage(1);

        UrlService.setUrlParam("facets", facets);
    }

    function setCategoryId(categoryId)
    {
        searchParams.categoryId = categoryId;
    }

    // function _updateUrlParams()
    // {
    //     var params = {};
    //
    //     if (searchParams.searchString.length > 0)
    //     {
    //         params.query = searchParams.searchString;
    //     }
    //
    //     if (searchParams.itemsPerPage !== App.config.defaultItemsPerPage)
    //     {
    //         params.items = searchParams.itemsPerPage;
    //     }
    //
    //     if (searchParams.orderBy !== App.config.defaultSorting)
    //     {
    //         params.orderBy = searchParams.orderBy;
    //     }
    //
    //     if (searchParams.page > 1)
    //     {
    //         params.page = searchParams.page;
    //     }
    //
    //     if (searchParams.facets.length > 0)
    //     {
    //         params.facets = searchParams.facets;
    //     }
    //
    //     UrlService.setUrlParams(params);
    // }<commit_msg>filter_in_search: - removed commented code<commit_after>var ApiService = require("services/ApiService");
var NotificationService = require("services/NotificationService");
var ResourceService = require("services/ResourceService");
var UrlService = require("services/UrlService");

module.exports = (function($)
{
    var searchParams =
        {
            searchString: "",
            itemsPerPage: App.config.defaultItemsPerPage,
            orderBy     : App.config.defaultSorting,
            page        : 1,
            facets      : "",
            categoryId  : null,
            template    : ""
        };

    return {
        getItemList       : getItemList,
        updateSearchString: updateSearchString,
        setSearchString   : setSearchString,
        setItemsPerPage   : setItemsPerPage,
        setOrderBy        : setOrderBy,
        setPage           : setPage,
        setSearchParams   : setSearchParams,
        setFacets         : setFacets,
        setCategoryId     : setCategoryId
    };

    function getItemList()
    {
        if (searchParams.categoryId || searchParams.searchString.length >= 3)
        {
            if (ResourceService.getResource("itemList").val())
            {
                ResourceService.getResource("itemList").val().total = 0;
            }

            var url = searchParams.categoryId ? "/rest/io/category" : "/rest/io/item/search";

            searchParams.template = searchParams.categoryId ? "Ceres::Category.Item.CategoryItem" : "Ceres::ItemList.ItemListView";

            _setIsLoading(true);

            ApiService.get(url, searchParams)
                .done(function(response)
                {
                    _setIsLoading(false);

                    ResourceService.getResource("itemList").set(response);
                    ResourceService.getResource("facets").set(response.facets);
                })
                .fail(function(response)
                {
                    _setIsLoading(false);

                    NotificationService.error("Error while searching").closeAfter(5000);
                });
        }
    }

    function _setIsLoading(isLoading)
    {
        ResourceService.getResource("itemSearch").set(searchParams);
        ResourceService.getResource("isLoading").set(isLoading);
    }

    /**
     * ?searchString=searchString&itemsPerPage=itemsPerPage&orderBy=orderBy&orderByKey=orderByKey&page=page
     * @param urlParams
     */
    function setSearchParams(urlParams)
    {
        var queryParams = UrlService.getUrlParams(urlParams);

        for (var key in queryParams)
        {
            searchParams[key] = queryParams[key];
        }
    }

    function updateSearchString(searchString)
    {
        searchParams.searchString = searchString;

        searchString = (searchString.length > 0) ? searchString : null;
        UrlService.setUrlParam("query", searchString);
    }

    function setSearchString(searchString)
    {
        searchParams.searchString = searchString;
        searchParams.page = 1;

        setPage(1);
        setFacets("");

        ResourceService.getResource("facets").set({});
        ResourceService.getResource("facetParams").set([]);

        searchString = (searchString.length > 0) ? searchString : null;
        UrlService.setUrlParam("query", searchString);
    }

    function setItemsPerPage(itemsPerPage)
    {
        searchParams.itemsPerPage = itemsPerPage;

        itemsPerPage = (itemsPerPage !== App.config.defaultItemsPerPage) ? itemsPerPage : null;
        UrlService.setUrlParam("items", itemsPerPage);
    }

    function setOrderBy(orderBy)
    {
        searchParams.orderBy = orderBy;

        orderBy = (orderBy !== App.config.defaultSorting) ? orderBy : null;
        UrlService.setUrlParam("orderBy", orderBy);
    }

    function setPage(page)
    {
        searchParams.page = page;

        page = (page > 1) ? page : null;
        UrlService.setUrlParam("page", page);
    }

    function setFacets(facets)
    {
        searchParams.facets = facets.toString();

        facets = (facets.toString().length > 0) ? facets.toString() : null;

        setPage(1);

        UrlService.setUrlParam("facets", facets);
    }

    function setCategoryId(categoryId)
    {
        searchParams.categoryId = categoryId;
    }
    
{'fraction_non_alphanumeric': 0.11334986567472619, 'fraction_numerical': 0.0039264310808018186, 'mean_word_length': 1.9891908585546634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '2487720', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2604, 'n_words': 393}