@@ -97,12 +97,9 @@ typedef struct SimpleArray
9797 AnyArrayTypeInfo * info ;
9898} SimpleArray ;
9999
100- typedef enum SimilarityType
101- {
102- AA_Cosine ,
103- AA_Jaccard ,
104- AA_Overlap
105- } SimilarityType ;
100+
101+ float8 RumArraySimilarityThreshold = RUM_SIMILARITY_THRESHOLD_DEFAULT ;
102+ int RumArraySimilarityFunction = RUM_SIMILARITY_FUNCTION_DEFAULT ;
106103
107104
108105PG_FUNCTION_INFO_V1 (rum_anyarray_config );
@@ -117,10 +114,6 @@ PG_FUNCTION_INFO_V1(rum_anyarray_similar);
117114PG_FUNCTION_INFO_V1 (rum_anyarray_distance );
118115
119116
120- static SimilarityType SmlType = AA_Cosine ;
121- static float8 SmlLimit = 0.5 ;
122-
123-
124117static Oid getAMProc (Oid amOid , Oid typid );
125118
126119static AnyArrayTypeInfo * getAnyArrayTypeInfo (MemoryContext ctx , Oid typid );
@@ -139,7 +132,6 @@ static int32 getNumOfIntersect(SimpleArray *sa, SimpleArray *sb);
139132static float8 getSimilarity (SimpleArray * sa , SimpleArray * sb , int32 intersection );
140133
141134
142-
143135/*
144136 * Specifies additional information type for operator class.
145137 */
@@ -390,7 +382,8 @@ rum_anyarray_consistent(PG_FUNCTION_ARGS)
390382
391383 INIT_DUMMY_SIMPLE_ARRAY (& sa , nentries );
392384 INIT_DUMMY_SIMPLE_ARRAY (& sb , nkeys );
393- res = getSimilarity (& sa , & sb , intersection ) >= SmlLimit ;
385+ res = getSimilarity (& sa , & sb , intersection ) >=
386+ RumArraySimilarityThreshold ;
394387 }
395388 else
396389 res = false;
@@ -491,7 +484,7 @@ rum_anyarray_similar(PG_FUNCTION_ARGS)
491484 PG_FREE_IF_COPY (b , 1 );
492485 PG_FREE_IF_COPY (a , 0 );
493486
494- PG_RETURN_BOOL (result >= SmlLimit );
487+ PG_RETURN_BOOL (result >= RumArraySimilarityThreshold );
495488}
496489
497490Datum
@@ -851,19 +844,19 @@ getSimilarity(SimpleArray *sa, SimpleArray *sb, int32 intersection)
851844{
852845 float8 result = 0.0 ;
853846
854- switch (SmlType )
847+ switch (RumArraySimilarityFunction )
855848 {
856- case AA_Cosine :
849+ case SMT_COSINE :
857850 result = ((float8 ) intersection ) /
858851 sqrt (((float8 ) sa -> nelems ) * ((float8 ) sb -> nelems ));
859852 break ;
860- case AA_Jaccard :
853+ case SMT_JACCARD :
861854 result = ((float8 ) intersection ) /
862855 (((float8 ) sa -> nelems ) +
863856 ((float8 ) sb -> nelems ) -
864857 ((float8 ) intersection ));
865858 break ;
866- case AA_Overlap :
859+ case SMT_OVERLAP :
867860 result = intersection ;
868861 break ;
869862 default :
0 commit comments