Re: Django--Making query use part of the matching name

2018-04-28 Thread 'Anthony Flury' via Django users
What are the rules - you say that a query string of '10FTK' should match 
'10FTH86RSK', but also '10FTK', '10F6TK', '10FTK4'


I think the problem is that the rules aren't 100% clear.

 * For '10FTK' to match '10FTH' you actually only care about the
   first 4 characters ?
 * For '10FTK' to match '10FTK...' implies you care about the first 5
 * For '10FTK' to match '10F6TK...' implies you care about your 5
   characters with an option numeric inserted after char 3 ?

so - should it match '106FTK ...' or '10TFK' or '10F99TK'

I can suggest a few strategies :

 * With English spelling it is not common for a knowledgable to get the
   first letter wrong - so you could find that the user will know they
   want '10...' and that the 'FTK' bit might be mis-remembered - so
   search on the first two characters only.
 * Use the entered code to build a more fuzzy search - so 10FTK becomes
   something like r'10*F.*T.*(K|H)' (for instance starting with the
   characters '10' and looking for FTK or FTH with possible intervening
   options.
 * Typically long code words are difficult to remember - - is it
   possible that '10FTH86RSK' actually represents a concept that can be
   categorized and described in English - for instance rather than try
   to implement a fuzzy search for the code, you actually provide a
   user friendly categorization drill down; so the user works down a
   tree of specific natural language descriptions - which internally
   builds the code '10FTH86RSK'

On Apr 25, 2018, at 5:13 PM, shawn...@gmail.com 
 wrote:



Hello everyone!

Currently I am working on Django.

I defined a 'Search' function in views.py:

def search(request):
 q = request.GET.get("q")
 if q:
 ReactResul = Reactionsmeta.objects.filter(id__contains=q)
 MetaResul = Metabolites.objects.filter(id__contains=q)
 GeneResul = Genes.objects.filter(id__contains=q)

 else:
 # you may want to return Customer.objects.none() instead 
ReactResul= Reactionsmeta.objects.all()
 GeneResul = Genes.objects.all()
 MetaResul = Metabolites.objects.all()
 context =dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
GeneResul)
 return render(request, "Recon/search.html", context)

And now I want to make it more powerful.

If I want to search '10FTH86RSK' but I cannot remember the whole 
name, I can just use part of the string to make query. For example, 
if I type '10FTK', '10FTH86RSK' should be returned as result.
In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned 
as results.


So how could I achieve this function?
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9EC3A76F-EE60-47DC-B4DD-9092D8321EC1%40gmail.com 
.

For more options, visit https://groups.google.com/d/optout.



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e24ffcd-a098-14f7-db47-d235fdb65002%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-26 Thread shawnmhy
But how about my query string? I am using 'q' as the search term

在 2018年4月26日星期四 UTC下午3:19:15,James Farris写道:
>
> Try using filter(id__regex=r'\w’)
>
> I’m not sure if this will give you the exact results your looking for, but 
> worth a shot. 
>
>
> Sent from my mobile device
>
> On Apr 26, 2018, at 2:31 AM, shaw...@gmail.com  wrote:
>
> Thank you for your help! And yes, I think I should use regex. But could 
> you please show me how to use it in my example, since I am new to django..
>
> 在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道:
>>
>> I believe you want to use icontains rather than contains. It’s case 
>> insensitive. 
>>
>> I’m not sure without using regex it’s possible to return the results 
>> based on any character in any order in the search string. 
>>
>> On Apr 25, 2018, at 5:13 PM, shaw...@gmail.com wrote:
>>
>> Hello everyone!
>>
>> Currently I am working on Django.
>>
>> I defined a 'Search' function in views.py:
>>
>> def search(request):
>> q = request.GET.get("q")
>> if q:
>> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
>> MetaResul = Metabolites.objects.filter(id__contains=q)
>> GeneResul = Genes.objects.filter(id__contains=q)
>>
>> else:
>> # you may want to return Customer.objects.none() instead
>> ReactResul= Reactionsmeta.objects.all()
>> GeneResul = Genes.objects.all()
>> MetaResul = Metabolites.objects.all()
>> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
>> GeneResul)
>> return render(request, "Recon/search.html", context)
>>
>>
>> And now I want to make it more powerful.
>>
>> If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
>> can just use part of the string to make query. For example, if I type 
>> '10FTK', '10FTH86RSK' should be returned as result.
>> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
>> results.
>>
>> So how could I achieve this function?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/be5f1894-4618-42c0-9882-6e135e21c6a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-26 Thread James Farris
Try using filter(id__regex=r'\w’)

I’m not sure if this will give you the exact results your looking for, but 
worth a shot. 


Sent from my mobile device

> On Apr 26, 2018, at 2:31 AM, shawn...@gmail.com wrote:
> 
> Thank you for your help! And yes, I think I should use regex. But could you 
> please show me how to use it in my example, since I am new to django..
> 
> 在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道:
>> 
>> I believe you want to use icontains rather than contains. It’s case 
>> insensitive. 
>> 
>> I’m not sure without using regex it’s possible to return the results based 
>> on any character in any order in the search string. 
>> 
>>> On Apr 25, 2018, at 5:13 PM, shaw...@gmail.com wrote:
>>> 
>>> Hello everyone!
>>> 
>>> Currently I am working on Django.
>>> 
>>> I defined a 'Search' function in views.py:
>>> 
>>> def search(request):
>>> q = request.GET.get("q")
>>> if q:
>>> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
>>> MetaResul = Metabolites.objects.filter(id__contains=q)
>>> GeneResul = Genes.objects.filter(id__contains=q)
>>> 
>>> else:
>>> # you may want to return Customer.objects.none() instead
>>> ReactResul= Reactionsmeta.objects.all()
>>> GeneResul = Genes.objects.all()
>>> MetaResul = Metabolites.objects.all()
>>> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
>>> GeneResul)
>>> return render(request, "Recon/search.html", context)
>>> 
>>> And now I want to make it more powerful.
>>> 
>>> If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
>>> can just use part of the string to make query. For example, if I type 
>>> '10FTK', '10FTH86RSK' should be returned as result.
>>> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
>>> results.
>>> 
>>> So how could I achieve this function?
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9F2E0677-FD8C-446B-83DA-8119D6D3705C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-26 Thread shawnmhy
Thank you for your help! And yes, I think I should use regex. But could you 
please show me how to use it in my example, since I am new to django..

在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道:
>
> I believe you want to use icontains rather than contains. It’s case 
> insensitive. 
>
> I’m not sure without using regex it’s possible to return the results based 
> on any character in any order in the search string. 
>
> On Apr 25, 2018, at 5:13 PM, shaw...@gmail.com  wrote:
>
> Hello everyone!
>
> Currently I am working on Django.
>
> I defined a 'Search' function in views.py:
>
> def search(request):
> q = request.GET.get("q")
> if q:
> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
> MetaResul = Metabolites.objects.filter(id__contains=q)
> GeneResul = Genes.objects.filter(id__contains=q)
>
> else:
> # you may want to return Customer.objects.none() instead
> ReactResul= Reactionsmeta.objects.all()
> GeneResul = Genes.objects.all()
> MetaResul = Metabolites.objects.all()
> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
> GeneResul)
> return render(request, "Recon/search.html", context)
>
>
> And now I want to make it more powerful.
>
> If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
> can just use part of the string to make query. For example, if I type 
> '10FTK', '10FTH86RSK' should be returned as result.
> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
> results.
>
> So how could I achieve this function?
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-25 Thread James Farris
I believe you want to use icontains rather than contains. It’s case 
insensitive. 

I’m not sure without using regex it’s possible to return the results based on 
any character in any order in the search string. 

> On Apr 25, 2018, at 5:13 PM, shawn...@gmail.com wrote:
> 
> Hello everyone!
> 
> Currently I am working on Django.
> 
> I defined a 'Search' function in views.py:
> 
> def search(request):
> q = request.GET.get("q")
> if q:
> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
> MetaResul = Metabolites.objects.filter(id__contains=q)
> GeneResul = Genes.objects.filter(id__contains=q)
> 
> else:
> # you may want to return Customer.objects.none() instead
> ReactResul= Reactionsmeta.objects.all()
> GeneResul = Genes.objects.all()
> MetaResul = Metabolites.objects.all()
> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
> GeneResul)
> return render(request, "Recon/search.html", context)
> 
> And now I want to make it more powerful.
> 
> If I want to search '10FTH86RSK' but I cannot remember the whole name, I can 
> just use part of the string to make query. For example, if I type '10FTK', 
> '10FTH86RSK' should be returned as result.
> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
> results.
> 
> So how could I achieve this function?
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9EC3A76F-EE60-47DC-B4DD-9092D8321EC1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django--Making query use part of the matching name

2018-04-25 Thread shawnmhy
Hello everyone!

Currently I am working on Django.

I defined a 'Search' function in views.py:

def search(request):
q = request.GET.get("q")
if q:
ReactResul = Reactionsmeta.objects.filter(id__contains=q)
MetaResul = Metabolites.objects.filter(id__contains=q)
GeneResul = Genes.objects.filter(id__contains=q)

else:
# you may want to return Customer.objects.none() instead
ReactResul= Reactionsmeta.objects.all()
GeneResul = Genes.objects.all()
MetaResul = Metabolites.objects.all()
context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
GeneResul)
return render(request, "Recon/search.html", context)


And now I want to make it more powerful.

If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
can just use part of the string to make query. For example, if I type 
'10FTK', '10FTH86RSK' should be returned as result.
In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
results.

So how could I achieve this function?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.