<commit_before>%% Copyright (c) 2012-2015 <NAME> <<EMAIL>>
%%
%% Licensed 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.

-module(elastic_http).
-behaviour(gen_server).
-export([
	 start_link/2,
	 index/5,
	 index/4
	]).
-export([
	 init/1,
	 code_change/3,
	 handle_call/3,
	 handle_cast/2,
	 handle_info/2,
	 terminate/2
	]).

start_link(Host, Port) ->
    gen_server:start_link(?MODULE, [Host, Port], []).

-spec index(pid(), iodata(), iodata(), iodata(), iodata()) -> iodata().
index(Elastic, Index, Type, Id, Document) ->
    gen_server:call(Elastic, {index, Index, Type, Id, Document}).

-spec index(pid(), iodata(), iodata(), iodata()) -> iodata().
index(Elastic, Index, Type, Document) ->
    gen_server:call(Elastic, {index, Index, Type, Document}).

init([Host, Port]) ->
    self() ! open,
    {ok, #{host => Host, port => list_to_integer(Port)}}.

handle_call({index, Index, Type, Id, Document}, Reply, #{gun := Gun} = S) ->
    Stream = gun:put(Gun, [Index, "/", Type, "/", Id], [], Document),
    {noreply, maps:put(Stream, Reply, S)};

handle_call({index, Index, Type, Document}, Reply, #{gun := Gun} = S) ->
    Stream = gun:post(Gun, [Index, "/", Type, "/"], [], Document),
    {noreply, maps:put(Stream, Reply, S)}.

handle_cast(stop, S) ->
    {stop, normal, S}.<commit_msg>wait forever on http call to indexer.<commit_after>%% Copyright (c) 2012-2015 <NAME> <<EMAIL>>
%%
%% Licensed 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.

-module(elastic_http).
-behaviour(gen_server).
-export([
	 start_link/2,
	 index/5,
	 index/4
	]).
-export([
	 init/1,
	 code_change/3,
	 handle_call/3,
	 handle_cast/2,
	 handle_info/2,
	 terminate/2
	]).

start_link(Host, Port) ->
    gen_server:start_link(?MODULE, [Host, Port], []).

-spec index(pid(), iodata(), iodata(), iodata(), iodata()) -> iodata().
index(Elastic, Index, Type, Id, Document) ->
    gen_server:call(Elastic, {index, Index, Type, Id, Document}, infinity).

-spec index(pid(), iodata(), iodata(), iodata()) -> iodata().
index(Elastic, Index, Type, Document) ->
    gen_server:call(Elastic, {index, Index, Type, Document}, infinty).

init([Host, Port]) ->
    self() ! open,
    {ok, #{host => Host, port => list_to_integer(Port)}}.

handle_call({index, Index, Type, Id, Document}, Reply, #{gun := Gun} = S) ->
    Stream = gun:put(Gun, [Index, "/", Type, "/", Id], [], Document),
    {noreply, maps:put(Stream, Reply, S)};

handle_call({index, Index, Type, Document}, Reply, #{gun := Gun} = S) ->
    Stream = gun:post(Gun, [Index, "/", Type, "/"], [], Document),
    {noreply, maps:put(Stream, Reply, S)}.

handle_cast(stop, S) ->
    {stop, normal, S}.
{'fraction_non_alphanumeric': 0.17962911707722115, 'fraction_numerical': 0.011624688624411846, 'mean_word_length': 4.177650429799427, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, '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': '3178038', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1152, 'n_words': 377}