Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Related entity' entity relationship text field needs to display exact matches only #18

Open
philgooch opened this issue Dec 20, 2012 · 2 comments

Comments

@philgooch
Copy link

When there are a large number of entities in EATS, adding a new entity relationship is quite unwieldy, as typing text into the Related Entity field displays a large number of approximate matches. Can this just display exact matches as the user types?

@ajenhl
Copy link
Owner

ajenhl commented Dec 20, 2012

Another tricky one, as the inexact matching is often going to be useful. Perhaps some way of toggling between the two behaviours?

To make the change in your specific case, modify eats_topic_map.py so that lookup_entities takes a new Boolean argument specifying whether an exact match is wanted, and have lookups.py's get_query method pass in True. In lookup_entities, pass the Boolean through to _create_lookup_query and use it to vary between the existing istartswith query term and iexact.

So, something like:

def _create_lookup_query (self, name, is_exact):
    query = None
    name_forms = create_name_forms(unicode(name))
    for name_form in name_forms:
        if query is None:
            if is_exact:
                query = Q(indexed_names__form__iexact=name_form)
            else:
                query = Q(indexed_names__form__istartswith=name_form)
        else:
            if is_exact:
                query = query | Q(indexed_names__form__iexact=name_form)
            else:
                query = query | Q(indexed_names__form__istartswith=name_form)
    return query

@philgooch
Copy link
Author

Thanks Jamie, this looks like it will do the trick. Will give this a try. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants