djorm-ext-pgfulltext icon indicating copy to clipboard operation
djorm-ext-pgfulltext copied to clipboard

Unable to search on parent fields.

Open jaysonsantos opened this issue 13 years ago • 6 comments

ie.:

class Product(models.Model):
    name = models.CharField(u'Name', max_length=100, null=False)
    slug = models.SlugField(u'Slug', max_length=100, null=False, blank=True)
    description = models.TextField(u'Description', null=True)
    search_index = VectorField()

    objects = SearchManager(
        fields=('name', 'description')
    )

class StoreProduct(models.Model):
    price = models.DecimalField(u'Price', max_digits=10, decimal_places=2)
    office = models.ForeignKey('stores.Office')
    product = models.ForeignKey(Product)
    in_stock = models.BooleanField(u'in stock', default=True)

One office can have a lot of products, and in this case i have to find products on store and ideal world would be:

StoreProduct.objects.search('test', fields=['product__name', 'product__description']).filter(in_stock=True)

Is there any way to do that?

jaysonsantos avatar Apr 15 '13 20:04 jaysonsantos

Hi!

Currently, is not possible search on foreignKeys relations, but is possible to implement. I put this feature to my todo list for this package.

Thanks.

niwinz avatar Apr 16 '13 17:04 niwinz

My dirty local fix is:

query = StoreProduct.objects.select_related('product').extra(
            where=['products_product.search_index @@ plainto_tsquery(%s)'],
            params=[form_data['q']])

jaysonsantos avatar Apr 16 '13 17:04 jaysonsantos

So good, this solves the problem. But it would be nice to integrate a solution in the package.

Furthermore, the fields kwarg on search method indicates to a manager not use a vector field. Be careful with this.

niwinz avatar Apr 16 '13 17:04 niwinz

Do you plan on implementing this feature? It would be very cool.

clime avatar Jul 19 '13 23:07 clime

This was difficult to do in django <1.7, but it will be implemented support for django 1.7 using custom lookups.

niwinz avatar Jan 26 '14 12:01 niwinz

@linuxlewis do you think this feature will be added sometime soon? This would be super useful for a bunch of projects I'm collaborating on :)

mkuchen avatar Apr 06 '15 19:04 mkuchen