-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patharcher.el
1223 lines (1090 loc) · 27.5 KB
/
archer.el
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; Buffers
(defvar archer-scratch-buffer "*Archer scratch*"
"Process buffer for the TCP connection to Archer")
(defvar archer-dump-buffer "*Archer*"
"Buffer in which matching files are displayed")
(defvar archer-hit-buffer "*Archer hits*"
"Buffer in which hit list is displayed")
(defvar archer-fields-buffer "*Archer fields*"
"Buffer for displaying list of fields available for query")
;;; Keymaps
(defvar archer-hit-map nil "Keymap for archer-hit-buffer")
(defvar archer-dump-map nil "Keymap for archer-dump-buffer")
;;; Parameters
(defvar archer-max-hits 20
"Maximum number of hits to show (setting to 0 removes limit);
use archer-set-max-hits to set")
(defvar archer-summary-fields nil
"Summary fields to use in displaying hits in hit buffer;
use archer-insert-summary-field and archer-delete-summary-field
to add and remove fields")
;;; Miscellaneous global variables
(defvar archer-server nil
"Name of Archer server host")
(defvar archer-port nil
"TCP port of Archer server")
(defvar archer-process-name "Archer"
"Process name for TCP connection")
(defvar archer-process nil
"Emacs process for TCP connection")
(defvar archer-last-query nil
"Last query issued by user")
(defvar archer-hits nil
"List of hits from last query")
(defvar archer-hit-count nil
"Number of matching documents")
(defvar archer-matcher-positions nil
"List of markers to matching terms in document in dump buffer")
(defvar archer-matcher-shown nil
"Index of current matching term")
(defvar archer-prefix-length nil
"Length of prefix common to all file names (currently not used)")
(defvar archer-available-summary-fields nil
"List of summary fields used by serer")
;;; The archer highlight face
(copy-face 'default 'archer-highlight-face)
(set-face-foreground 'archer-highlight-face "red")
;;; ---------------- Stopword list --------------------
(defvar archer-stopwords-list
'(
"a"
"able"
"about"
"above"
"according"
"accordingly"
"across"
"actually"
"after"
"afterwards"
"again"
"against"
"all"
"allow"
"allows"
"almost"
"alone"
"along"
"already"
"also"
"although"
"always"
"am"
"among"
"amongst"
"an"
"and"
"another"
"any"
"anybody"
"anyhow"
"anyone"
"anything"
"anyway"
"anyways"
"anywhere"
"apart"
"appear"
"appreciate"
"appropriate"
"are"
"around"
"as"
"aside"
"ask"
"asking"
"associated"
"at"
"available"
"away"
"awfully"
"b"
"be"
"became"
"because"
"become"
"becomes"
"becoming"
"been"
"before"
"beforehand"
"behind"
"being"
"believe"
"below"
"beside"
"besides"
"best"
"better"
"between"
"beyond"
"both"
"brief"
"but"
"by"
"c"
"came"
"can"
"cannot"
"cant"
"cause"
"causes"
"certain"
"certainly"
"changes"
"clearly"
"co"
"com"
"come"
"comes"
"concerning"
"consequently"
"consider"
"considering"
"contain"
"containing"
"contains"
"corresponding"
"could"
"course"
"currently"
"d"
"definitely"
"described"
"despite"
"did"
"different"
"do"
"does"
"doing"
"done"
"down"
"downwards"
"during"
"e"
"each"
"edu"
"eg"
"eight"
"either"
"else"
"elsewhere"
"enough"
"entirely"
"especially"
"et"
"etc"
"even"
"ever"
"every"
"everybody"
"everyone"
"everything"
"everywhere"
"ex"
"exactly"
"example"
"except"
"f"
"far"
"few"
"fifth"
"first"
"five"
"followed"
"following"
"follows"
"for"
"former"
"formerly"
"forth"
"four"
"from"
"further"
"furthermore"
"g"
"get"
"gets"
"getting"
"given"
"gives"
"go"
"goes"
"going"
"gone"
"got"
"gotten"
"greetings"
"h"
"had"
"happens"
"hardly"
"has"
"have"
"having"
"he"
"hello"
"help"
"hence"
"her"
"here"
"hereafter"
"hereby"
"herein"
"hereupon"
"hers"
"herself"
"hi"
"him"
"himself"
"his"
"hither"
"hopefully"
"how"
"howbeit"
"however"
"i"
"ie"
"if"
"ignored"
"immediate"
"in"
"inasmuch"
"inc"
"indeed"
"indicate"
"indicated"
"indicates"
"inner"
"insofar"
"instead"
"into"
"inward"
"is"
"it"
"its"
"itself"
"j"
"just"
"k"
"keep"
"keeps"
"kept"
"know"
"knows"
"known"
"l"
"last"
"lately"
"later"
"latter"
"latterly"
"least"
"less"
"lest"
"let"
"like"
"liked"
"likely"
"little"
"look"
"looking"
"looks"
"ltd"
"m"
"mainly"
"many"
"may"
"maybe"
"me"
"mean"
"meanwhile"
"merely"
"might"
"more"
"moreover"
"most"
"mostly"
"much"
"must"
"my"
"myself"
"n"
"name"
"namely"
"nd"
"near"
"nearly"
"necessary"
"need"
"needs"
"neither"
"never"
"nevertheless"
"new"
"next"
"nine"
"no"
"nobody"
"non"
"none"
"noone"
"nor"
"normally"
"not"
"nothing"
"novel"
"now"
"nowhere"
"o"
"obviously"
"of"
"off"
"often"
"oh"
"ok"
"okay"
"old"
"on"
"once"
"one"
"ones"
"only"
"onto"
"or"
"other"
"others"
"otherwise"
"ought"
"our"
"ours"
"ourselves"
"out"
"outside"
"over"
"overall"
"own"
"p"
"particular"
"particularly"
"per"
"perhaps"
"placed"
"please"
"plus"
"possible"
"presumably"
"probably"
"provides"
"q"
"que"
"quite"
"qv"
"r"
"rather"
"rd"
"re"
"really"
"reasonably"
"regarding"
"regardless"
"regards"
"relatively"
"respectively"
"right"
"s"
"said"
"same"
"saw"
"say"
"saying"
"says"
"second"
"secondly"
"see"
"seeing"
"seem"
"seemed"
"seeming"
"seems"
"seen"
"self"
"selves"
"sensible"
"sent"
"serious"
"seriously"
"seven"
"several"
"shall"
"she"
"should"
"since"
"six"
"so"
"some"
"somebody"
"somehow"
"someone"
"something"
"sometime"
"sometimes"
"somewhat"
"somewhere"
"soon"
"sorry"
"specified"
"specify"
"specifying"
"still"
"sub"
"such"
"sup"
"sure"
"t"
"take"
"taken"
"tell"
"tends"
"th"
"than"
"thank"
"thanks"
"thanx"
"that"
"thats"
"the"
"their"
"theirs"
"them"
"themselves"
"then"
"thence"
"there"
"thereafter"
"thereby"
"therefore"
"therein"
"theres"
"thereupon"
"these"
"they"
"think"
"third"
"this"
"thorough"
"thoroughly"
"those"
"though"
"three"
"through"
"throughout"
"thru"
"thus"
"to"
"together"
"too"
"took"
"toward"
"towards"
"tried"
"tries"
"truly"
"try"
"trying"
"twice"
"two"
"u"
"un"
"under"
"unfortunately"
"unless"
"unlikely"
"until"
"unto"
"up"
"upon"
"us"
"use"
"used"
"useful"
"uses"
"using"
"usually"
"uucp"
"v"
"value"
"various"
"very"
"via"
"viz"
"vs"
"w"
"want"
"wants"
"was"
"way"
"we"
"welcome"
"well"
"went"
"were"
"what"
"whatever"
"when"
"whence"
"whenever"
"where"
"whereafter"
"whereas"
"whereby"
"wherein"
"whereupon"
"wherever"
"whether"
"which"
"while"
"whither"
"who"
"whoever"
"whole"
"whom"
"whose"
"why"
"will"
"willing"
"wish"
"with"
"within"
"without"
"wonder"
"would"
"would"
"x"
"y"
"yes"
"yet"
"you"
"your"
"yours"
"yourself"
"yourselves"
"z"
"zero"
))
(defvar archer-stopwords
(make-vector (- (expt 2 (ceiling (log (length archer-stopwords-list) 2))) 1)
0))
(while archer-stopwords-list
(intern (car archer-stopwords-list) archer-stopwords)
(setq archer-stopwords-list (cdr archer-stopwords-list)))
(defun archer-stopword (word)
(intern-soft word archer-stopwords))
;;; -------------- Commands ------------------
(defun archer-contact (host port)
"Establish a connection with the Archer server at HOST on PORT."
(interactive "sHost: \nnPort: ")
(archer-disconnect)
(setq archer-process
(open-network-stream archer-process-name
archer-scratch-buffer host port))
(cond ((and (archer-contacted) (archer-connection-allowed))
(message "Archer contacted")
(setq archer-server host)
(setq archer-port port)
(setq archer-prefix-length nil)
(setq archer-available-summary-fields nil)
(archer-send
(if (= archer-max-hits 0) "hits"
(format "hits 0 %d" (- archer-max-hits 1))))
t)
(t (message "Failed to contact archer server")
(setq archer-server nil)
(setq archer-port nil)
(setq archer-process nil)
nil)))
(defun archer-query (query)
"Send QUERY to current Archer server. Prompts for a host and port
if not current connection exists."
(interactive "sQuery: ")
(setq archer-last-query query)
(when (archer-send-query query)
(set-buffer (get-buffer archer-scratch-buffer))
(goto-char (point-min))
(setq archer-hit-count (archer-read-hit-count))
(let ((hits ())
(hit nil))
(setq hit (archer-parse-hit))
(while hit
(setq hits (cons hit hits))
(setq hit (archer-parse-hit)))
(setq archer-hits
(reverse
(mapcar (lambda (h) (cons (cdr (assq 'id h)) h)) hits)))
(cond (archer-hits
(archer-show-hits)
(message "%d hits" archer-hit-count))
(t (message "No hits"))))))
(defun archer-requery ()
"Allows user to edit and re-send last query."
(interactive)
(let ((q (read-from-minibuffer "Query: " archer-last-query)))
(when (> (length q) 0)
(archer-query q))))
(defun archer-delete-summary-field ()
"Delete a summary field currently used in displaying hits."
(interactive)
(if archer-summary-fields
(let* ((collection
(mapcar (lambda (f) (cons f t)) archer-summary-fields))
(field (completing-read "Delete field: " collection nil t)))
(setq archer-summary-fields (delete field archer-summary-fields))
(archer-show-hits))
(message "No summary fields activated")))
(defun archer-insert-summary-field ()
"Add a summary field to use in displaying hits."
(interactive)
(let ((collection
(mapcar
(lambda (f) (cons f t))
(archer-set-difference
archer-available-summary-fields archer-summary-fields))))
(if collection
(let ((field (completing-read "Add field: " collection nil t)))
(when (assoc field collection)
(setq archer-summary-fields
(nconc archer-summary-fields (list field)))
(archer-show-hits)))
(message "No summary fields available"))))
(defun archer-set-max-hits (number)
"Set the number of hits to show in hit buffer."
(interactive "nMax hits (0 = show all): ")
(setq archer-max-hits number)
(when (archer-contacted)
(archer-send (if (= number 0) "hits" (format "hits 0 %d" (- number 1)))))
(when archer-last-query (archer-query archer-last-query)))
(defun archer-next-dump ()
"Display the next matching document in the Archer dump buffer."
(interactive)
(set-buffer (get-buffer archer-hit-buffer))
(archer-next-hit)
(archer-find-hit)
(set-buffer (get-buffer archer-dump-buffer)))
(defun archer-next-matcher ()
"Go to the next term matching the query in the Archer dump buffer."
(interactive)
(when archer-matcher-positions
(goto-char (archer-move-matcher-shown 1))))
(defun archer-previous-matcher ()
"Go to the previous term matching the query in the Archer dump buffer."
(interactive)
(when archer-matcher-positions
(goto-char (archer-move-matcher-shown -1))))
(defun archer-pop-to-hit-buffer ()
"Pop to the Archer hit buffer."
(interactive)
(pop-to-buffer (get-buffer archer-hit-buffer)))
(defun archer-pop-to-dump-buffer ()
"Pop to the Archer dump buffer."
(interactive)
(pop-to-buffer (get-buffer archer-dump-buffer)))
(defun archer-next-hit ()
"Go down one line in the Archer hit buffer."
(interactive)
(let ((next-line-add-newlines nil)
(goal-column 8))
(next-line 1)))
(defun archer-previous-hit ()
"Go up one line in the Archer hit buffer."
(interactive)
(let ((goal-column 8))
(previous-line 1)))
(defun archer-find-hit ()
"Display the document at the current line in the Archer hit buffer."
(interactive)
(end-of-line)
(let ((p (point)))
(beginning-of-line)
(let ((result (re-search-forward "\\([0-9]+\\)" p t)))
(if result
(let ((id (match-string 1)))
(archer-dump id))
(message "Can't find message id")))))
(defun archer-show-fields ()
"Display a list of fields available for use in queries."
(interactive)
(archer-send "fields")
(let ((fields
(with-current-buffer archer-scratch-buffer
(goto-char (point-min))
(archer-xml-strings "field"))))
(if (not fields) (message "No fields defined")
(let ((buf (current-buffer)))
(pop-to-buffer (get-buffer-create archer-fields-buffer))
(erase-buffer)
(while fields
(insert (car fields) "\n")
(setq fields (cdr fields)))
(pop-to-buffer buf)))))
(defun archer-query-region (from to)
"Use region as query"
(interactive "r")
(let ((str (buffer-substring from to))
(termobarray (make-vector 1023 0)))
(with-current-buffer (get-buffer-create archer-scratch-buffer)
(erase-buffer)
(insert str)
(downcase-region (point-min) (point-max))
(goto-char (point-min))
(perform-replace "[^a-zA-Z0-9]+" " " nil t nil)
(goto-char (point-min))
(while (re-search-forward "[a-z]+" nil t)
(let ((word (match-string 0)))
(unless (archer-stopword word)
(let* ((sym (intern word termobarray))
(count (get sym 'count)))
(put sym 'count (if count (+ count 1) 1))))))
(erase-buffer)
(let ((found nil))
(mapatoms (lambda (s)
(insert (format "(%d)%s " (get s 'count) s))
(setq found t))
termobarray)
(if found (archer-query (buffer-string))
(message "Nothing in region worth sending"))))))
;;; --------------- Archer connection management --------------
(defun archer-contacted ()
"Do we have an open connection to an Archer server?"
(let ((status (process-status archer-process-name)))
(not (memq status '(nil closed)))))
(defun archer-disconnect ()
"Disconnect from an open Archer connection."
(when (archer-contacted)
(delete-process archer-process)
(with-current-buffer (get-buffer archer-scratch-buffer) (erase-buffer))))
(defun archer-connection-allowed ()
"Will the Archer server let us talk to it? If Archer requires
a password, get one from the user and send it."
(archer-wait)
(with-current-buffer (get-buffer archer-scratch-buffer)
(goto-char (point-min))
(or (not (archer-xml-region "archer-password")) (archer-password))))
(defun archer-password ()
"Get a password from the user and send it. Does Archer like it?"
(let ((pass (archer-read-password)))
(if (= (length pass) 0) nil
(archer-send pass)
(archer-contacted))))
(defun archer-read-password ()
"Prompt the user for a password (wantonly plagiarized from ange-ftp)."
(let ((pass nil)
(c 0)
(echo-keystrokes 0)
(cursor-in-echo-area t))
(while (progn (message "Password: %s" (make-string (length pass) ?*))
(setq c (read-char))
(and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
(cond ((= c ?\C-u)
(setq pass ""))
((and (/= c ?\b) (/= c ?\177))
(setq pass (concat pass (char-to-string c))))
((> (length pass) 0)
(setq pass (substring pass 0 -1)))))
(message "")
(message nil)
pass))
;;; ------------------ Talking to Archer ----------------------
(defun archer-send-query (query)
"Send QUERY to the current Archer process."
(archer-send (concat "nquery " query)))
(defun archer-prepare-for-send ()
"Get ready to send something to Archer."
(with-current-buffer (get-buffer-create archer-scratch-buffer)
(erase-buffer)))
(defun archer-send (string)
"Send STRING to Archer. Return t if Archer's still with us, else nil."
(let ((ok t))
(unless (archer-contacted)
(setq ok (call-interactively 'archer-contact)))
(cond (ok
(archer-prepare-for-send)
(process-send-string archer-process (concat string "\n"))
(archer-wait)
t)
(t
(message "No server contacted")
nil))))
(defun archer-wait ()
"Wait for Archer to stop talking."
(with-current-buffer archer-scratch-buffer
(goto-char (point-min))
(while (not (search-forward "\n.\n" nil t))
(beginning-of-line 0)
(accept-process-output archer-process 0 100))))
;;; ------------------- Understanding Archer ------------------
; ((id . "id")
; (name . "name")
; (score . "score")
; (terms ("term" "term"))
; (annotations (name . value) ...)
(defun archer-parse-hit ()
"Parse and return a single Archer hit, advancing point past it.
Return nil if no hits are visible from current point."
(let ((region (archer-xml-region "hit")))
(and region
(let ((hit ()))
(goto-char (car region))
(let* ((a (archer-xml-region "annotation" (cdr region)))
(stop (if a (car a) (cdr region))))
(mapcar (lambda (tag)
(let ((strings
(archer-xml-strings (symbol-name tag) stop)))
(when strings
(setq hit (cons (cons tag (car strings)) hit)))))
'(id name score))
(let ((terms (archer-xml-strings "term" stop)))
(when terms (setq hit (cons (cons 'terms terms) hit))))
(when a
(goto-char (car a))
(let ((names (archer-xml-strings "name" (cdr region)))
(values (archer-xml-strings "value" (cdr region)))
(annotations ()))
(while names
(setq annotations
(cons (cons (car names) (car values)) annotations))
(setq names (cdr names))
(setq values (cdr values)))
(when annotations
(setq hit (cons (cons 'annotations annotations) hit))
(unless archer-available-summary-fields
(setq archer-available-summary-fields
(mapcar 'car annotations)))))))
hit))))
(defun archer-read-hit-count ()
"Read the number of matching documents from the Archer scratch buffer."
(let ((region (archer-xml-region "count")))
(unless region (error "Can't read count of matching documents"))
(string-to-number (buffer-substring (car region) (cdr region)))))
(defun archer-xml-strings (tag &optional limit)
"Return as a list all strings in fields delimited by TAG up to
optional LIMIT."
(save-excursion
(let ((result ())
(region (archer-xml-region tag limit)))
(while region
(setq result
(cons (buffer-substring (car region) (cdr region)) result))
(goto-char (cdr region))
(setq region (archer-xml-region tag limit)))
result)))
(defun archer-xml-region (&optional tag limit)
"Return the next xml region (in the form of (from-point . to-point))
visible from the current point. If TAG is specified, concentrate on
the indicated xml field. Only search up to LIMIT, if specified."
(save-excursion
(let ((regexp
(if tag (concat "<\\(" tag "\\)>") "<\\([a-zA-Z]+\\)>")))
(let ((from (re-search-forward regexp limit t)))
(and from
(let* ((tag (match-string 1))
(pat (concat "</" tag ">"))
(to (search-forward pat limit t)))
(and to (cons from (- to (length pat))))))))))
(defun archer-matching-text ()
"Return a list of regions corresponding to matching terms."
(archer-xml-region "match"))
;;; ----------------- Displaying results ----------------------
(defun archer-show-hits ()
"Show matching documents, one per line, in the hits buffer."
(switch-to-buffer (get-buffer-create archer-hit-buffer))
(erase-buffer)
(mapcar 'archer-insert-hit archer-hits)
(use-local-map archer-hit-map)
(goto-char (point-min)))
(defun archer-insert-hit (hit)
"Insert a representation of HIT at point in the hits buffer."
(let* ((id (cdr (assq 'id hit)))
(idlen (length id))