pombreda / djapian

Automatically exported from code.google.com/p/djapian
Other
0 stars 0 forks source link

Per-instance "smart" weights for indexer #84

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to have a possibility to index instances of a model with different
weights.

Use-case would be: for a information system storing prices from several
resellers there is a bussiness rule that for a reseller which has more than
1000 in its price list, each position in the price list should have weight
= 2 in order to be on top of the search results.

It should be possible to provide either an attribute or a callable to the
indexer, with weight = 1.0 be the default as it is now.

Original issue reported on code.google.com by esizi...@gmail.com on 23 Sep 2009 at 2:59

GoogleCodeExporter commented 9 years ago

Original comment by daevaorn on 23 Sep 2009 at 6:15

GoogleCodeExporter commented 9 years ago
Please find attached a proof of concept patch for this issue.

Example of usage:

{{{
# models.py
class Client(models.Model):
    weight = models.PositiveSmallIntegerField(_('weight'), max_length=1, default=1)
    ...

class Product(models.Model):
    client = models.ForeignKey(Client, verbose_name=_('client'))
    ....

# index.py
class ClientIndexer(WeightenedIndexer):
    weight = 'weight'
    ...

class ProductIndexer(WeightenedIndexer):
    weight = 'client.weight'
    ...
}}}

Original comment by esizi...@gmail.com on 15 Oct 2009 at 10:55

Attachments:

GoogleCodeExporter commented 9 years ago
I could make some polishing of the patch if your are interested in it enough ro 
push it 
upstream in a near future.

Original comment by esizi...@gmail.com on 15 Feb 2010 at 5:00

GoogleCodeExporter commented 9 years ago
Yep. But I think that it is better to use Field.resolve method to extract 
weight value.

Original comment by daevaorn on 18 Feb 2010 at 9:55

GoogleCodeExporter commented 9 years ago
done in r354

Original comment by daevaorn on 20 Mar 2010 at 6:39