11 static double smlar_limit = 0.6;
14 * Smlar table stores table-wide statistic
16 static char * smlar_table = "";
18 static bool smlar_use_malloc = false;
21 * State of GUC initialization
23 static bool smlar_guc_inited = false;
26 SmlarTableAssign(const char *newval, void *extra)
31 static bool smlar_logadd = false;
34 SmlarLogAssign(bool newval, void *extra)
39 static int smlar_smltype = ST_COSINE;
41 static const struct config_enum_entry SmlarTypeOptions[] = {
42 {"cosine", ST_COSINE, false},
43 {"tfidf", ST_TFIDF, false},
44 {"overlap", ST_OVERLAP, false},
48 static int smlar_tf_method = TF_N;
49 static const struct config_enum_entry SmlarTFOptions[] = {
51 {"log", TF_LOG, false},
52 {"const", TF_CONST, false},
62 DefineCustomRealVariable(
64 "Lower threshold of array's similarity",
65 "Array's with similarity lower than threshold are not similar by % operation",
77 DefineCustomStringVariable(
79 "Name of table stored set-wide statistic",
80 "Named table stores global frequencies of array's elements",
90 DefineCustomEnumVariable(
92 "Type of similarity formula",
93 "Type of similarity formula: cosine(default), tfidf, overlap",
104 DefineCustomBoolVariable(
105 "smlar.persistent_cache",
106 "Usage of persistent cache of global stat",
107 "Cache of global stat is stored in transaction-independent memory",
117 DefineCustomBoolVariable(
118 "smlar.idf_plus_one",
119 "Calculate idf by log(1+d/df)",
120 "Calculate idf by log(1+d/df)",
130 DefineCustomEnumVariable(
132 "Method of TF caclulation",
133 "TF method: n => number of entries, log => 1+log(n), const => constant value",
144 smlar_guc_inited = true;
150 if (!smlar_guc_inited)
153 return (smlar_logadd) ? 1.0 : 0.0;
159 if (!smlar_guc_inited)
162 return smlar_tf_method;
168 if (!smlar_guc_inited)
177 if (!smlar_guc_inited)
186 if (!smlar_guc_inited)
189 return smlar_smltype;
193 GetSmlarUsePersistent(void)
195 if (!smlar_guc_inited)
198 return smlar_use_malloc;
201 PG_FUNCTION_INFO_V1(set_smlar_limit);
202 Datum set_smlar_limit(PG_FUNCTION_ARGS);
204 set_smlar_limit(PG_FUNCTION_ARGS)
206 float4 nlimit = PG_GETARG_FLOAT4(0);
212 sprintf(buf,"%f", nlimit);
213 set_config_option("smlar.threshold", buf,
214 PGC_USERSET, PGC_S_SESSION ,GUC_ACTION_SET, true, 0
215 #if PG_VERSION_NUM >= 90500
219 PG_RETURN_FLOAT4((float4)GetSmlarLimit());
222 PG_FUNCTION_INFO_V1(show_smlar_limit);
223 Datum show_smlar_limit(PG_FUNCTION_ARGS);
225 show_smlar_limit(PG_FUNCTION_ARGS)
227 PG_RETURN_FLOAT4((float4)GetSmlarLimit());