public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: Jean Delvare <jdelvare@suse.de>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Michal Marek <mmarek@suse.cz>,
	Roland Eggner <edvx1@systemanalysen.net>,
	Wang YanQing <udknight@gmail.com>
Subject: Re: [PATCH] kconfig: sort found symbols by relevance
Date: Mon, 6 May 2013 20:17:54 +0200	[thread overview]
Message-ID: <20130506181754.GE3958@free.fr> (raw)
In-Reply-To: <1367854112.4569.137.camel@chaos.site>

Jean, All,

On Mon, May 06, 2013 at 05:28:32PM +0200, Jean Delvare wrote:
> Le Monday 06 May 2013 à 15:02 +0200, Yann E. MORIN a écrit :
> > From: "Yann E. MORIN" <yann.morin.1998@free.fr>
> > 
> > When searching for symbols, return the symbols sorted by relevance.
> > 
> > Relevance is the ratio of the length of the matched string and the
> > length of the symbol name. Symbols of equal relevance are sorted
> > alphabetically.
> > 
> > Reported-by: Jean Delvare <jdelvare@suse.de>
> > Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> > Cc: Jean Delvare <jdelvare@suse.de>
> > Cc: Michal Marek <mmarek@suse.cz>
> > Cc: Roland Eggner <edvx1@systemanalysen.net>
> > Cc: Wang YanQing <udknight@gmail.com>
> > ---
> >  scripts/kconfig/symbol.c | 66 +++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 57 insertions(+), 9 deletions(-)
> 
> I did not look at the code, only tested it, and it does what I asked for
> originally: exact match is listed first. So thank you :)
> 
> However I am not sure if your implementation is what we want. Your
> definition of "relevance" is somewhat arbitrary and may not be
> immediately to others. For example, my own definition of "relevance" was
> that symbols which start with the subject string are more relevant than
> the symbols which have the string in the middle. Others would possibly
> have other definitions.

Yes, I understand. That was mostly a proposal. I'm open for discussion! :-)

> So in the end you have somewhat complex code for a sort order which may
> surprise or confuse the user. It may put close to each other options
> which are completely unrelated, and suboptions very far from their
> parent.

The notion of "sub-options" is very fuzzy: as symbols are stored in an
hash-based array, it is not possible to now how they relate to each other
order-wise, once the parsing of the Kconfig is done. So we can't expect
the search results to reflect the 'proximity' of symbol declarations.

> I am wondering if it might not be better to go for a more simple
> strategy: exact match on top and then sort alphabetically. Or even just
> sort alphabetically - now that I know regexps are supported, it is easy
> to get the exact match when I need it.

Also, to prefer exact match requires we check how much of the symbol
name was matched (hence my initial 'relevance' heuristic).

However, here is a proposal for another heuristic that seems to work
relatively well for me (but is a very little bit more complex, I'm
afraid), that tries hard to get the most relevant symbols first:

Compare matched symbols as thus:
  - first, symbols with a prompt,   [1]
  - then, smallest offset,          [2]
  - then, shortest match,           [3]
  - then, highest relevance,        [4]
  - finally, alphabetical sort      [5]

When searching for 'P.*CI' :

[1] Symbols of interest are probably those with a prompt, as they can be
    changed, while symbols with no prompt are only for info. Thus:
        PCIEASPM comes before PCI_ATS

[2] Symbols that match earlier in the name are to be preferred over
    symbols which match later. Thus:
        PCI_MSI comes before WDTPCI

[3] The shortest match is (IMHO) more interesting than a longer one.
    Thus:
        PCI comes before PCMCIA

[4] The relevance is the ratio of the length of the match against the
    length of the symbol. The more of a symbol name we match, the more
    instersting that symbol is. Thus:
        PCIEAER comes before PCIEASPM

[5] As fallback, sort symbols alphabetically (no example, it's explicit
    enough, I guess :-) )

Of course 'P.*CI' is really a torture-test search, real searches will
probably be more precise in the first place. This heuristic seems to
also work well with real searches. YMMV, of course...

What do you (and others!) think about this? I'll post the patch shortly
for testing.

> Thanks for your work anyway,

Cheers! :-)

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  reply	other threads:[~2013-05-06 18:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-06  7:50 Wish: exact matches displayed first Jean Delvare
2013-05-06 10:00 ` Yann E. MORIN
2013-05-06 12:54   ` Yann E. MORIN
2013-05-06 13:04     ` Thomas Petazzoni
2013-05-06 13:53       ` Yann E. MORIN
2013-05-06 14:19         ` Jean Delvare
2013-05-06 14:27           ` Yann E. MORIN
2013-05-06 14:36             ` Jean Delvare
2013-05-06 14:10     ` Jean Delvare
2013-05-06 13:02 ` [PATCH] kconfig: sort found symbols by relevance Yann E. MORIN
2013-05-06 15:28   ` Jean Delvare
2013-05-06 18:17     ` Yann E. MORIN [this message]
2013-05-07  1:35     ` Wang YanQing
2013-05-06 18:20 ` Yann E. MORIN
2013-05-06 19:36   ` Yann E. MORIN
2013-05-06 21:15 ` [PATCH v3] " Yann E. MORIN
2013-05-09 15:27   ` Wang YanQing
2013-05-09 16:12     ` Yann E. MORIN
2013-05-10  0:51       ` Wang YanQing
2013-05-10 10:12         ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130506181754.GE3958@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=edvx1@systemanalysen.net \
    --cc=jdelvare@suse.de \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=udknight@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox