From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scot Becker Subject: Re: Re: Sparse trees and searching for multiple words Date: Tue, 21 Sep 2010 23:14:11 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from [140.186.70.92] (port=55199 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OyB6h-0003d1-FZ for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 18:14:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OyB6f-0006Xc-2k for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 18:14:35 -0400 Received: from mail-bw0-f41.google.com ([209.85.214.41]:43731) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OyB6e-0006Wy-TW for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 18:14:33 -0400 Received: by bwz10 with SMTP id 10so51648bwz.0 for ; Tue, 21 Sep 2010 15:14:31 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Ilya Shlyakhter Cc: emacs-orgmode@gnu.org Tom, I agree that a flexible multi-term search would be a great addition to org-mode and Emacs in general. I'd say that Google has spoiled us, but like all who are spoiled I believe my inflated desires to be perfectly reasonable! I'm keeping more and more notes in org-mode, and the more I keep, the more this comes up. I had a look at the page Ilya suggested, and got the 'first alternative' to work with org-occur (code below), but I also followed the links there and it looks like Drew Adams has done some significant work in this regard with his 'icicles' library. See his discussion on search here: http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview For example, using M-x icicles-search you can specify both a 'search context' (for example sentences, paragraphs, or any other span of text that you can define with a regexp.... perhaps org-mode outline nodes?), then from there you can drill down with one search term after another. This amounts to a progressive AND search, like what you're asking for. And as I remember, icicles does have a pretty good set of commands for tweaking searches in progress. Not Google Instant, but if it works, it could be pretty good. I'm not sure if you could somehow do org-sparse trees with something like this. On a first attempt a year ago, I wasn't able to swallow the icicles pill whole. I went back to ido in the end---partly because I couldn't manage the complexity. But `icicles-search' really motivates me to refresh my configuration and see if it is useful, at least for this kind of thing. For a simpler and less flexible solution, here is the code from the 'String Permutations' page, with the top-level function rewritten to call org-occur. It works reasonably well for the kind of searches you are asking about, but the search terms do have to be on the same line. This is less of a problem if, like me, you are using visual-line-mode and your paragraphs don't have newlines breaking them up. (defun scb/search-words-any-order (keywords) "Search for a comma-separated list of terms in any order." (interactive "sKeywords: (comma-separated) ") (org-occur (my-csv-string-to-regexp keywords))) (defun my-csv-string-to-regexp (str) "Translate comma separated values into regexp. A,B,C turns into \\(A.*B.*C\\|A.*C.*B\\|B.*A.*C\\|B.*C.*A\\|C.*A.*B\\|C.*B.*A\\)" (let* ((l (perms (split-string str ",\\s-*")))) (mapconcat (function (lambda (n) (mapconcat 'identity n ".*"))) l "\\|"))) ;; thanks to Christoph Conrad (require 'cl) (defun perms (l) (if (null l) (list '()) (mapcan #'(lambda( a ) (mapcan #'(lambda( p ) (list (cons a p))) (perms (remove* a l :count 1)))) l))) Scot On Tue, Sep 21, 2010 at 6:20 PM, Ilya Shlyakhter wrote: >> For example, I'd like to see entries which contains the words 'cat' and >> 'dog' in any order. Or 'apple', 'orange', 'melon', 'plum' and 'pear' >> in any order. > > Maybe this will help: http://www.emacswiki.org/emacs/StringPermutations > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode >