emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Sparse trees and searching for multiple words
@ 2010-09-19  8:48 Tom
  2010-09-21 17:20 ` Ilya Shlyakhter
  2010-09-22  2:46 ` Matt Lundin
  0 siblings, 2 replies; 4+ messages in thread
From: Tom @ 2010-09-19  8:48 UTC (permalink / raw)
  To: emacs-orgmode

I see sparse trees can be constructed by searching for a regexp, but I
can't find the same ability for multiple searches.

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.

Searching for multiple keywords in a single operation is a pretty basic feature.
 I recommend adding it if currently there is no way to do it in org.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Sparse trees and searching for multiple words
  2010-09-19  8:48 Sparse trees and searching for multiple words Tom
@ 2010-09-21 17:20 ` Ilya Shlyakhter
  2010-09-21 22:14   ` Scot Becker
  2010-09-22  2:46 ` Matt Lundin
  1 sibling, 1 reply; 4+ messages in thread
From: Ilya Shlyakhter @ 2010-09-21 17:20 UTC (permalink / raw)
  To: emacs-orgmode

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: Sparse trees and searching for multiple words
  2010-09-21 17:20 ` Ilya Shlyakhter
@ 2010-09-21 22:14   ` Scot Becker
  0 siblings, 0 replies; 4+ messages in thread
From: Scot Becker @ 2010-09-21 22:14 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: emacs-orgmode

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 <cc@cli.de>
    (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 <ilya_shl@alum.mit.edu> 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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Sparse trees and searching for multiple words
  2010-09-19  8:48 Sparse trees and searching for multiple words Tom
  2010-09-21 17:20 ` Ilya Shlyakhter
@ 2010-09-22  2:46 ` Matt Lundin
  1 sibling, 0 replies; 4+ messages in thread
From: Matt Lundin @ 2010-09-22  2:46 UTC (permalink / raw)
  To: Tom; +Cc: emacs-orgmode

Tom <levelhalom@gmail.com> writes:

> I see sparse trees can be constructed by searching for a regexp, but I
> can't find the same ability for multiple searches.
>
> 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.
>
> Searching for multiple keywords in a single operation is a pretty
>  basic feature. I recommend adding it if currently there is no way to
>  do it in org.

For such searches, I use org-search-view:

C-c a s +cat +dog [RET]

This will pull up the headlines for all entries that contain the
substrings cat and dog in any order.

By default, org-search-view treats the entry as a single substring if
there are no plus or minus signs. E.g.,

C-c a s cat dog [RET]

...will find only those entries that have the precise string "cat dog".

For searches more like Google's (i.e., lazy booleans), you can set the
variable org-agenda-search-view-always-boolean to t. Then, a search such
as:

C-c a s cat dog [RET]

...will find all entries that have the words cat and dog in any order.

,----[ C-h v org-agenda-search-view-always-boolean ]
| When this is non-nil, the string will be split on whitespace, and each
| snippet will be searched individually, and all must match in order to
| select an entry.
`----

If you want to force "cat" and "dog" to match full words only, you can
set the variable org-agenda-search-view-force-full-words to t.

Best,
Matt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-22  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-19  8:48 Sparse trees and searching for multiple words Tom
2010-09-21 17:20 ` Ilya Shlyakhter
2010-09-21 22:14   ` Scot Becker
2010-09-22  2:46 ` Matt Lundin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).