Encapsulating search result per application

35 views
Skip to first unread message

Ilya

unread,
Mar 30, 2016, 12:22:05 PM3/30/16
to django-watson discussion group
Hello 
I have implemented the search on 2 models in one of my apps Customers (Company and Contacts)

so when users search on search page from result of this app only the see results from those 2 models.


Now in the same project  I created another app named vendors and this app has the logic as the Customers however the models have different name V_Company and V_Contact

so since in my apps I have registered the new tables I have defined for this app only :

apps.py
from django.apps import AppConfig
from watson import search as watson


class YourAppConfig(AppConfig):
    name
= "vendor"
   
def ready(self):
        V_Contacts
= self.get_model("V_Contacts")
        watson
.register(V_Contacts)
        V_Company
= self.get_model("V_Company")
        watson
.register(V_Company)



and my _init_.py
default_app_config = 'vendor.apps.YourAppConfig'


My search template  form haven't changed 

    <h1>Vendor Search</h1>
   
<br>
   
<div class="row">
       
<div class="col-sm-4 col-md-4">
           
<form action="search">
               
<span class="glyphicon glyphicon-search"></span> <input name="q" value="{{request.GET.q}}">


               
<input type="submit" class="btn btn-primary btn-primary" value="Search">
           
</form>
       
</div>
   
</div>


And the views are copy paste fro your code 

I was expecting that search output will be only for the models I have registered in this app but it looks like it provides all the search results also from the models registered in different app and not searching at all in models registered in this app.

Is it expected behavior or I am not configuring something correctly?


Dave Hall

unread,
Mar 31, 2016, 6:11:48 AM3/31/16
to django-watson discussion group
You can segregate search results by creating separate "search engines".


Unfortunately, there's no easy way to tell watson to use different search engines in different views. You can get around this by subclassing the SearchView:


Apologies that this isn't better documented. I've been meaning to improve the watson docs for a while.

--
You received this message because you are subscribed to the Google Groups "django-watson discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-watso...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-watson.
For more options, visit https://groups.google.com/d/optout.

Ilya

unread,
Mar 31, 2016, 10:28:51 AM3/31/16
to django-watson discussion group
Thank you ,
Sorry I am real novice 

so to summarize I should create  watson.py inside the watson folder where I will register models as you showed in example .
as well should i remove registration from apps.py 

from django.apps import AppConfig
from watson import search as watson

class YourAppConfig(AppConfig):
    name = "customer"
    def ready(self):
        Contacts = self.get_model("Contacts")
        watson.register(Contacts)
        Company = self.get_model("Company")
        watson.register(Company)


Is it the case?
It is not working for me , so I am wondering if I understood your correctly.
Did I got it correctly or not?


Dave Hall

unread,
Mar 31, 2016, 10:54:28 AM3/31/16
to django-watson discussion group

Ilya

unread,
Apr 9, 2016, 12:35:21 PM4/9/16
to django-watson discussion group
Thank you Dave, I will try it out 

Ilya

unread,
Apr 28, 2016, 10:04:47 AM4/28/16
to django-watson discussion group
Thank you again Dave It worked.

Since had to use CBV instead of FBV had to do some changes .
Reply all
Reply to author
Forward
0 new messages