-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSearch.ecl
73 lines (59 loc) · 2.81 KB
/
Search.ecl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
IMPORT Std;
#WORKUNIT('name', 'fuzzy_business_name_match');
//-----------------------------------------------------------------------------
// This code is intended to be compiled and published under Roxie
//-----------------------------------------------------------------------------
IMPORT $.^.^ AS Root;
IMPORT $.^ AS Home;
//-----------------------------------------------------------------------------
UTF8 businessName := '' : STORED('business_name', FORMAT(SEQUENCE(100)));
INTEGER1 minScore := 0 : STORED('min_score', FORMAT(SEQUENCE(200)));
BOOLEAN onlyDirect := FALSE : STORED('only_direct_matches', FORMAT(SEQUENCE(300)));
INTEGER2 pageNum := 1 : STORED('page_num', FORMAT(SEQUENCE(400)));
INTEGER2 pageSize := 100 : STORED('page_size', FORMAT(SEQUENCE(500)));
clampedMinScore := MIN(MAX(minScore, 0), 100);
clampedPageNum := MAX(pageNum, 1);
clampedPageSize := MAX(pageSize, 1);
params := DATASET
(
[
{'business_name', businessName},
{'only_direct_matches', IF(onlyDirect, u8'true', u8'false')},
{'min_score', (UTF8)clampedMinScore},
{'page_num', (UTF8)clampedPageNum},
{'page_size', (UTF8)clampedPageSize}
],
{STRING parameter, UTF8 value}
);
OUTPUT(params, NAMED('echo'));
UNSIGNED1 AdaptedDistance(UTF8 s) := FUNCTION
textLen := LENGTH(s);
RETURN MAP
(
textLen < 3 => 0,
textLen < 21 => 1,
0
);
END;
WordsOnStopList(STRING stopwordIndexPath, UTF8 queryStr) := FUNCTION
RETURN JOIN
(
Root.Files.StopwordDS(stopwordIndexPath),
Root.FuzzyNameMatch.MakeWordDS(Home.CleanBusinessName(queryStr)),
LEFT.word = RIGHT.word,
TRANSFORM(LEFT)
);
END;
OUTPUT(WordsOnStopList(Home.Constants.STOPWORD_PATH, businessName), NAMED('query_words_on_index_stoplist'));
rawResults := Root.FuzzyNameMatch.BestMatches(businessName,
Home.Constants.NAME_INDEX_PATH,
Home.Constants.NAME_ID_INDEX_PATH,
Home.Constants.ENTITY_ID_INDEX_PATH,
CleanNameFunction := Home.CleanBusinessName,
AdaptedDistanceFunction := AdaptedDistance,
stopwordPath := Home.Constants.STOPWORD_PATH);
rawResults2 := rawResults(score >= clampedMinScore AND (NOT(onlyDirect) OR is_match));
OUTPUT(COUNT(rawResults2), NAMED('total_found'));
sortedResults := TOPN(rawResults2, (clampedPageNum * clampedPageSize), -score, entity_guid, -is_match);
firstRec := (clampedPageNum -1) * clampedPageSize + 1;
OUTPUT(CHOOSEN(sortedResults, clampedPageSize, firstRec), NAMED('matches'), ALL);