Skip to content

Commit 8a72f43

Browse files
committed
use sort utility for ordering search results
1 parent 26174f5 commit 8a72f43

File tree

6 files changed

+35
-259
lines changed

6 files changed

+35
-259
lines changed

sources/arch.sh

+6-57
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ search() {
112112
"$conf_awk" -F'/' \
113113
"BEGIN {
114114
IGNORECASE=1;
115-
count=0;
116115
OFS=\"\t\";
117116
and_op = \"$conf_and_operator\" == \"true\";
118117
split(\"$query\",kwds,\" \");
@@ -167,35 +166,11 @@ search() {
167166
}
168167
169168
if (accuracy>0) {
170-
matches[count,0] = accuracy;
171-
matches[count,1] = title;
172-
matches[count,2] = path;
173-
matches[count,3] = lang;
174-
count++;
169+
print accuracy, title, lang, \"$name\", path;
175170
}
176171
177-
};
178-
END {
179-
for (i = 0; i < count; i++)
180-
for (j = i; j < count; j++)
181-
if (matches[i,0] < matches[j,0]) {
182-
h = matches[i,0];
183-
t = matches[i,1];
184-
p = matches[i,2];
185-
l = matches[i,3];
186-
matches[i,0] = matches[j,0];
187-
matches[i,1] = matches[j,1];
188-
matches[i,2] = matches[j,2];
189-
matches[i,3] = matches[j,3];
190-
matches[j,0] = h;
191-
matches[j,1] = t;
192-
matches[j,2] = p;
193-
matches[j,3] = l;
194-
};
195-
196-
for (i = 0; i < count; i++)
197-
print matches[i,1], matches[i,3], \"$name\", matches[i,2];
198-
};"
172+
};" | \
173+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
199174
)"
200175

201176
if [ "$conf_quick_search" != 'true' ]; then
@@ -204,7 +179,6 @@ search() {
204179
eval "rg -U -i -c '$rg_query' $paths" | \
205180
"$conf_awk" -F'/' \
206181
"BEGIN {
207-
count = 0;
208182
OFS=\"\t\";
209183
};
210184
{
@@ -231,34 +205,9 @@ search() {
231205
title = title \" (Category)\";
232206
}
233207
234-
matches[count,0] = hits+0;
235-
matches[count,1] = title;
236-
matches[count,2] = path;
237-
matches[count,3] = lang;
238-
239-
count++;
240-
};
241-
END {
242-
for (i = 0; i<count; i++)
243-
for (j = i; j<count; j++)
244-
if (matches[i,0] < matches[j,0]) {
245-
h = matches[i,0];
246-
t = matches[i,1];
247-
p = matches[i,2];
248-
l = matches[i,3];
249-
matches[i,0] = matches[j,0];
250-
matches[i,1] = matches[j,1];
251-
matches[i,2] = matches[j,2];
252-
matches[i,3] = matches[j,3];
253-
matches[j,0] = h;
254-
matches[j,1] = t;
255-
matches[j,2] = p;
256-
matches[j,3] = l;
257-
};
258-
259-
for (i=0; i<count; i++)
260-
print matches[i,1], matches[i,3], \"$name\", matches[i,2];
261-
};"
208+
print hits+0, title, lang, \"$name\", path;
209+
};" | \
210+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
262211
)"
263212

264213
fi

sources/fbsd.sh

+7-56
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ search() {
105105
"$conf_awk" -F '/' \
106106
"BEGIN {
107107
IGNORECASE=1;
108-
count=0;
109108
and_op = \"$conf_and_operator\" == \"true\";
110109
split(\"$query\",kwds,\" \");
111110
};
@@ -154,34 +153,10 @@ search() {
154153
155154
if ((and_op && accuracy>0) || (!and_op && (accuracy > 0 || book ~ /$rg_query/))) {
156155
title = sprintf(\"%s (%s)\",title,book);
157-
matches[count,0] = accuracy;
158-
matches[count,1] = title;
159-
matches[count,2] = path;
160-
matches[count,3] = lang;
161-
count++;
156+
printf(\"%s\t%s\t%s\t$name\t%s\n\",accuracy,title,lang,path);
162157
}
163-
};
164-
END {
165-
for (i = 0; i < count; i++)
166-
for (j = i; j < count; j++)
167-
if (matches[i,0] < matches[j,0]) {
168-
h = matches[i,0];
169-
t = matches[i,1];
170-
p = matches[i,2];
171-
l = matches[i,3];
172-
matches[i,0] = matches[j,0];
173-
matches[i,1] = matches[j,1];
174-
matches[i,2] = matches[j,2];
175-
matches[i,3] = matches[j,3];
176-
matches[j,0] = h;
177-
matches[j,1] = t;
178-
matches[j,2] = p;
179-
matches[j,3] = l;
180-
};
181-
182-
for (i = 0; i < count; i++)
183-
printf(\"%s\t%s\t$name\t%s\n\",matches[i,1],matches[i,3],matches[i,2]);
184-
};"
158+
};" | \
159+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
185160
)"
186161

187162
if [ "$conf_quick_search" != 'true' ]; then
@@ -191,7 +166,6 @@ search() {
191166
"$conf_awk" -F '/' \
192167
"BEGIN {
193168
IGNORECASE=1;
194-
count=0;
195169
};
196170
\$0 !~ /.*:0$/ {
197171
@@ -215,33 +189,10 @@ search() {
215189
book = \$($nf+1) \"/\" \$($nf+2);
216190
217191
title = sprintf(\"%s (%s)\",title,book);
218-
matches[count,0] = hits;
219-
matches[count,1] = title;
220-
matches[count,2] = path;
221-
matches[count,3] = lang;
222-
count++;
223-
};
224-
END {
225-
for (i = 0; i < count; i++)
226-
for (j = i; j < count; j++)
227-
if (matches[i,0] < matches[j,0]) {
228-
h = matches[i,0];
229-
t = matches[i,1];
230-
p = matches[i,2];
231-
l = matches[i,3];
232-
matches[i,0] = matches[j,0];
233-
matches[i,1] = matches[j,1];
234-
matches[i,2] = matches[j,2];
235-
matches[i,3] = matches[j,3];
236-
matches[j,0] = h;
237-
matches[j,1] = t;
238-
matches[j,2] = p;
239-
matches[j,3] = l;
240-
};
241-
242-
for (i = 0; i < count; i++)
243-
printf(\"%s\t%s\t$name\t%s\n\",matches[i,1],matches[i,3],matches[i,2]);
244-
};"
192+
193+
printf(\"%s\t%s\t%s\t$name\t%s\n\",hits,title,lang,path);
194+
};" | \
195+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
245196
)"
246197

247198
fi

sources/gentoo.sh

+8-59
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ search() {
8888
eval "$conf_find $path -type f -name '*.html'" | "$conf_awk" -F '/' \
8989
"BEGIN {
9090
IGNORECASE=1;
91-
count=0;
9291
and_op = \"$conf_and_operator\" == \"true\";
9392
split(\"$query\",kwds,\" \");
9493
};
@@ -148,35 +147,11 @@ search() {
148147
}
149148
150149
if (accuracy>0) {
151-
matches[count,0] = accuracy;
152-
matches[count,1] = title;
153-
matches[count,2] = path;
154-
matches[count,3] = lang;
155-
count++;
150+
printf(\"%s\t%s\t%s\t$name\t%s\n\",accuracy,title,lang,path);
156151
}
157152
}
158-
};
159-
END {
160-
for (i = 0; i < count; i++)
161-
for (j = i; j < count; j++)
162-
if (matches[i,0] < matches[j,0]) {
163-
h = matches[i,0];
164-
t = matches[i,1];
165-
p = matches[i,2];
166-
l = matches[i,3];
167-
matches[i,0] = matches[j,0];
168-
matches[i,1] = matches[j,1];
169-
matches[i,2] = matches[j,2];
170-
matches[i,3] = matches[j,3];
171-
matches[j,0] = h;
172-
matches[j,1] = t;
173-
matches[j,2] = p;
174-
matches[j,3] = l;
175-
};
176-
177-
for (i = 0; i < count; i++)
178-
printf(\"%s\t%s\t$name\t%s\n\",matches[i,1],matches[i,3],matches[i,2]);
179-
};"
153+
};" | \
154+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
180155
)"
181156

182157
if [ "$conf_quick_search" != 'true' ]; then
@@ -186,9 +161,8 @@ search() {
186161
"$conf_awk" -F'/' \
187162
"BEGIN {
188163
IGNORECASE=1;
189-
count=0;
190164
};
191-
ND>0 {
165+
{
192166
hits = \$NF
193167
gsub(/^.*:/,\"\",hits);
194168
@@ -218,36 +192,11 @@ search() {
218192
path = \$0;
219193
220194
if (lang ~ $langs && title !~ $rg_ignore) {
221-
222-
matches[count,0] = hits;
223-
matches[count,1] = title;
224-
matches[count,2] = path;
225-
matches[count,3] = lang;
226-
count++;
195+
printf(\"%s\t%s\t%s\t$name\t%s\n\",hits,title,lang,path);
227196
}
228-
};
229-
END {
230-
for (i = 0; i < count; i++)
231-
for (j = i; j < count; j++)
232-
if (matches[i,0] < matches[j,0]) {
233-
h = matches[i,0];
234-
t = matches[i,1];
235-
p = matches[i,2];
236-
l = matches[i,3];
237-
matches[i,0] = matches[j,0];
238-
matches[i,1] = matches[j,1];
239-
matches[i,2] = matches[j,2];
240-
matches[i,3] = matches[j,3];
241-
matches[j,0] = h;
242-
matches[j,1] = t;
243-
matches[j,2] = p;
244-
matches[j,3] = l;
245-
};
246-
247-
for (i = 0; i<count; i++)
248-
printf(\"%s\t%s\t$name\t%s\n\",matches[i,1],matches[i,3],matches[i,2]);
249-
};"
250-
)"
197+
};" | \
198+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
199+
)"
251200

252201
fi
253202

sources/man.sh

+3-31
Original file line numberDiff line numberDiff line change
@@ -161,39 +161,11 @@ search() {
161161
echo "$results_name" | "$conf_awk" -F '\t' \
162162
"BEGIN {
163163
IGNORECASE=1;
164-
count=0;
165164
};
166165
NF>0 {
167-
matches[count,0] = \$1+0;
168-
matches[count,1] = \$2;
169-
matches[count,2] = \$3;
170-
matches[count,3] = \$4;
171-
matches[count,4] = \$5;
172-
count++;
173-
};
174-
END {
175-
for (i = 0; i < count; i++)
176-
for (j = i; j < count; j++)
177-
if (matches[i,0] < matches[j,0]) {
178-
a = matches[i,0];
179-
t = matches[i,1];
180-
s = matches[i,2];
181-
l = matches[i,3];
182-
p = matches[i,4];
183-
matches[i,0] = matches[j,0];
184-
matches[i,1] = matches[j,1];
185-
matches[i,2] = matches[j,2];
186-
matches[i,3] = matches[j,3];
187-
matches[i,4] = matches[j,4];
188-
matches[j,0] = a;
189-
matches[j,1] = t;
190-
matches[j,2] = s;
191-
matches[j,3] = l;
192-
matches[j,4] = p;
193-
};
194-
for (i = 0; i < count; i++)
195-
printf(\"%s (%s)\t%s\t$name\t%s\n\",matches[i,1],matches[i,2],matches[i,3],matches[i,4]);
196-
};"
166+
printf(\"%s\t%s (%s)\t%s\t$name\t%s\n\",\$1+0,\$2,\$3,\$4,\$5);
167+
};" | \
168+
"$conf_sort" -rV -k1 | cut -d' ' -f2-
197169
)"
198170

199171
# Search by description

0 commit comments

Comments
 (0)