0

I want to compare a 'term' to the values of a dictionary, specifically, the substrings of the values. This is necessary because the formatting of the values varies across different modules. For instance: module1='Doe', module2='Jane Doe'. The term to compare in this case would be 'Doe'. How should I go about solving this issue? Thanks!

search.html

{% if tickets %}
Tickets found:
<table class="table">
    <thead>
    <tr>
        <th>ID</th>
        <th>Company</th>
        <th>Summary</th>
    </tr>
    </thead>
    <tbody>
    {% for ticket in tickets %}
    <tr>
        <td> {{ ticket.id }} </td>
        <td> {{ ticket.company.name }} </td>
        <td> {{ ticket.summary }} </td>
    </tr>
    {% endfor %}
    {% endif %}
    </tbody>
</table>

views.py

def search_bar(request):
term = request.GET.get('term')

if term:
    results = objCW.search_companies(term) + objCW.search_contacts(term)
    tickets = objCW.search_tickets_by_company(term) + objCW.search_tickets_by_contact(term)
    context = {'results': results, 'tickets': tickets}
    return render(request, 'website/search.html', context)
else:
    context = {'': ''}
    return render(request, 'website/search.html', context)
t0bi
  • 76
  • 10
  • Do you want to find the longest common substring? e.g. https://stackoverflow.com/questions/18715688/find-common-substring-between-two-strings?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Attersson Jun 05 '18 at 18:37
  • Or perhaps do you require additional rules? Such as the common part must be exactly 1 full word in both strings – Attersson Jun 05 '18 at 18:38
  • @Attersson I really only need to return values where 'term' matches values or substring of values. This is for a search box. – t0bi Jun 05 '18 at 18:40
  • Where 'term' is already known right? – Attersson Jun 05 '18 at 18:41
  • @Attersson right, 'term' is a user input (search). – t0bi Jun 05 '18 at 18:44

0 Answers0