Gnus development mailing list
 help / color / mirror / Atom feed
* nnmaildir support for nnir.el
@ 2008-02-03 13:04 Justus-bulk
  2008-02-03 14:16 ` Reiner Steib
  0 siblings, 1 reply; 10+ messages in thread
From: Justus-bulk @ 2008-02-03 13:04 UTC (permalink / raw)
  To: ding

[Repost from my newly-subscribed address]

Hi,

I've hacked up some initial nnmaildir support for nnir.el (gnus
contrib), for the Swish++ and Namazu backends.

During the process, I rolled some redundant code shared by these
backends into a new function, which may be useful for other backends
as well.

Please review and test, and send me your comments. I hope this (or an
improved version) can be committed to CVS.

See below a diff with respect to the latest CVS version (7.22) for
convenient reviewing. For convenient testing, you can download the
full file at http://www.montefiore.ulg.ac.be/~piater/test/nnir.el .

Thanks,
Justus


diff -c /local/home/piater/share/emacs/lisp/nnir-orig.el /local/home/piater/share/emacs/lisp/nnir.el
*** /local/home/piater/share/emacs/lisp/nnir-orig.el	2008-01-04 15:10:46.200002809 +0100
--- /local/home/piater/share/emacs/lisp/nnir.el	2008-02-02 21:05:29.663526101 +0100
***************
*** 661,667 ****
             (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
                 (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
               (concat gname ":")))
!        "native")))
  
  ;; Summary mode commands.
  
--- 663,669 ----
             (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
                 (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
               (concat gname ":")))
!        (format "%s:%s" (car gnus-select-method) (cadr gnus-select-method)))))
  
  ;; Summary mode commands.
  
***************
*** 830,835 ****
--- 832,865 ----
  
  (nnoo-define-skeleton nnir)
  
+ 
+ ;; Helper function currently used by the Swish++ and Namazu backends;
+ ;; perhaps useful for other backends as well
+ (defun nnir-compose-result (dirnam article score prefix server)
+   "Extract the group from dirnam, and create a result vector
+ ready to be added to the list of search results."
+   
+   ;; remove nnir-*-remove-prefix from beginning of dirnam filename
+   (when (string-match (concat "^" prefix) dirnam)
+     (setq dirnam (replace-match "" t t dirnam)))
+ 
+   ;; remove trailing slash and, for nnmaildir, cur/new/tmp
+   (setq dirnam (substring dirnam 0 (if (string= server "nnmaildir:") -5 -1)))
+ 
+   ;; eliminate all ".", "/", "\" from beginning. Always matches.
+   (string-match "^[./\\]*\\(.*\\)$" dirnam)
+   (setq group (substitute ?. ?/ (match-string 1 dirnam))) ;; "/" -> "."
+   (setq group (substitute ?. ?\\ group)) ;; "\\" -> "."
+ 
+   (vector (nnir-group-full-name group server)
+ 	  (if (string= server "nnmaildir:")
+ 	      (nnmaildir-base-name-to-article-number
+ 	       (substring article 0 (string-match ":" article))
+ 	       group nil)
+ 	    (string-to-int article))
+ 	  (string-to-int score)))
+ 
+ 
  ;;; Search Engine Interfaces:
  
  ;; freeWAIS-sf interface.
***************
*** 939,944 ****
--- 969,977 ----
             (groupspec (cdr (assq 'group query)))
             (prefix (nnir-read-server-parm 'nnir-swish++-remove-prefix server))
             (artlist nil)
+ 	   (article-pattern (if (string= server "nnmaildir:")
+ 				":[0-9]+"
+ 			      "^[0-9]+\\(\\.[a-z0-9]+\\)?$"))
             (score nil) (artno nil) (dirnam nil) (group nil) )
  
        (when (equal "" qstring)
***************
*** 986,992 ****
                dirnam (file-name-directory (match-string 2)))
  
          ;; don't match directories
!         (when (string-match "^[0-9]+\\(\\.[a-z0-9]+\\)?$" artno)
            ;; nnml-use-compressed-files might be any string, but probably this
            ;; is sufficient.  Note that we can't only use the value of
            ;; nnml-use-compressed-files because old articles might have been
--- 1019,1025 ----
                dirnam (file-name-directory (match-string 2)))
  
          ;; don't match directories
!         (when (string-match article-pattern artno)
            ;; nnml-use-compressed-files might be any string, but probably this
            ;; is sufficient.  Note that we can't only use the value of
            ;; nnml-use-compressed-files because old articles might have been
***************
*** 996,1019 ****
              ;; maybe limit results to matching groups.
              (when (or (not groupspec)
                        (string-match groupspec dirnam))
! 
!               ;; remove nnir-swish++-remove-prefix from beginning of dirname
!               (when (string-match (concat "^" prefix)
!                                   dirnam)
!                 (setq dirnam (replace-match "" t t dirnam)))
! 
!               (setq dirnam (substring dirnam 0 -1))
!               ;; eliminate all ".", "/", "\" from beginning. Always matches.
!               (string-match "^[./\\]*\\(.*\\)$" dirnam)
!               ;; "/" -> "."
!               (setq group (substitute ?. ?/ (match-string 1 dirnam)))
!               ;; "\\" -> "."
!               (setq group (substitute ?. ?\\ group))
! 
!               (push (vector (nnir-group-full-name group server)
!                             (string-to-int artno)
!                             (string-to-int score))
!                     artlist)))))
  
        (message "Massaging swish++ output...done")
  
--- 1029,1036 ----
              ;; maybe limit results to matching groups.
              (when (or (not groupspec)
                        (string-match groupspec dirnam))
! 	      (push (nnir-compose-result dirnam artno score prefix server)
! 		    artlist)))))
  
        (message "Massaging swish++ output...done")
  
***************
*** 1207,1212 ****
--- 1224,1232 ----
      (error "The Namazu backend cannot search specific groups"))
    (save-excursion
      (let (
+ 	  (article-pattern (if (string= server "nnmaildir:")
+ 				":[0-9]+"
+ 			      "^[0-9]+$"))
            (artlist nil)
            (qstring (cdr (assq 'query query)))
            (prefix (nnir-read-server-parm 'nnir-namazu-remove-prefix server))
***************
*** 1256,1273 ****
                article (file-name-nondirectory (match-string 4)))
  
          ;; make sure article and group is sane
!         (when (and (string-match "^[0-9]+$" article)
                     (not (null group)))
!           (when (string-match (concat "^" prefix) group)
!             (setq group (replace-match "" t t group)))
! 
!           ;; remove trailing slash from groupname
!           (setq group (substring group 0 -1))
! 
!           ;; stuff results into artlist vector
!           (push (vector (nnir-group-full-name (substitute ?. ?/ group) server)
!                         (string-to-int article)
!                         (string-to-int score)) artlist)))
  
        ;; sort artlist by score
        (apply 'vector
--- 1276,1285 ----
                article (file-name-nondirectory (match-string 4)))
  
          ;; make sure article and group is sane
!         (when (and (string-match article-pattern article)
                     (not (null group)))
! 	  (push (nnir-compose-result group article score prefix server)
! 		artlist)))
  
        ;; sort artlist by score
        (apply 'vector

Diff finished.  Sat Feb  2 21:20:46 2008



^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <x8t4pcrw0pb.fsf@tool.montefiore.ulg.ac.be>]

end of thread, other threads:[~2008-04-13 15:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-03 13:04 nnmaildir support for nnir.el Justus-bulk
2008-02-03 14:16 ` Reiner Steib
2008-02-04 17:28   ` Justus-bulk
     [not found]     ` <v9myq060m6.fsf_-_@marauder.physik.uni-ulm.de>
2008-03-21  7:52       ` Justus-bulk
2008-04-13 13:48     ` Reiner Steib
2008-04-13 14:58       ` Justus-bulk
2008-04-13 15:03         ` Reiner Steib
     [not found] <x8t4pcrw0pb.fsf@tool.montefiore.ulg.ac.be>
2008-02-02 20:50 ` Christoph Conrad
2008-02-02 21:21   ` Reiner Steib
2008-02-03 10:16     ` Christoph Conrad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).