Skip to content

Allow to search keys #19

Closed

Description

@CharlesNepote

We will probably have thousands of properties and we need to make them easy to find.

For the end-user, the best option would be to enter a keyword related to the property he wants to add.

Example: searching how to enter the color of the cap:

  • the user enter "c", then "o", then "l"
  • the UI should provide a list containing properties (or descriptions) containing "co" then "col"

The GET /keys is currently returning all the keys with stats:

  • the stats are not useful for our current concern
  • returning ALL the keys might be costly when there are thousands of properties

Currently, Open Food Facts website is already using tags autocompletion with a library (tagify) that takes simple JSON arrays in input ["tag1","tag2","free_tag"] (see the explanation here).

Suggestion 1

Create a GET /keys&term=col which returns a simple JSON array: ["color","color_of_the_cap","multicolor"].

Suggestion 2

Create another API route to return only the useful data:

  • rename GET /keys into /key_stats
  • create GET /keys&term=col which returns a simple JSON array: ["color","color_of_the_cap","multicolor"].

Part of

Activity

  1. stephanegigandet commented on May 12, 2021

    @stephanegigandet

    Well the current /keys is very similar to what you get on the web site with facets /labels
    I do think the stats are very useful, even for end users, to know how popular a key is.

    My preference would be to keep /keys as is, and add parameters to filter them ?term=color (word search), and ?autocomplete=col (makes it clear that is searches on starts of words and not full words). But keep the output the same (with counts).

  2. CharlesNepote commented on May 12, 2021

    @CharlesNepote
    MemberAuthor

    I don't say we should avoid stats! I also do think stats are useful, but not for an autocompletion service.

    To synthetize you suggestion @stephanegigandet :

    Suggestion 3

    Keep GET /keys results as is but add a &term= (full word search) and &autocomplete= (start of the word) to refine the results.

    About &autocomplete=

    Currently, Open Food Facts is returning all words containing the term, and not just the words beginning by the searched term. I'm in favor of chosing words containing the searched term as many of the properties will use expressions. Eg:

    • all properties containing a date: recalled_product:date, launch:date, seen_on_tv:date, etc.
    • multicolor, color_of_the_cap (monochrome should be also found thanks to its description (not implemented yet))

    KISS for the backend devs or for the frontend devs?

    Suggestions 1 and 2 makes life quite easier for frontend devs: JSON arrays are far easier to use (and it's ready to use in OFF website).

    Suggestion 3 probably makes life easier for backend devs but makes frontend devs' work harder.

    IMHO, the API should always try to make frontend devs' work easier.

  3. stephanegigandet commented on May 12, 2021

    @stephanegigandet

    Currently, Open Food Facts is returning all words containing the term, and not just the words beginning by the searched term. I'm in favor of chosing words containing the searched term as many of the properties will use expressions. Eg:

    You need both &term= for word search, and &autocomplete= for autocomplete / suggest as you type search.

    What you described here is suggest as you type:

    the user enter "c", then "o", then "l"
    the UI should provide a list containing properties (or descriptions) containing "co" then "col"

    And here it's regular word search:

    For the end-user, the best option would be to enter a keyword related to the property he wants to add.

    The user types a keyword and hits enter. (then the keyword can match in the property name, but potentially also its metadata, description etc.)

  4. stephanegigandet commented on May 12, 2021

    @stephanegigandet

    Suggestion 3 probably makes life easier for backend devs but makes frontend devs' work harder.

    Not much I think, and it's useful to have stats/metadata available even for suggest as you type results, or search results, so that you can display it to users:

    Search properties: col (user typing)
    Properties:

    • Color (1532 products)
    • Collectible (120 products)
    • Bottle cap color (32 products)

    I'd argue that it's even simpler for devs if you get the same format of results when you list all keys, or keys containing a specific term, or keys starting with characters. Frontend code can be only one function that covers all use cases.

  5. Ajay-Nair commented on Apr 8, 2022

    @Ajay-Nair

    @stephanegigandet So if I understand you correctly, you want to do as follows:
    Idea 1: As the user types each letter, the frontend does the &autocomplete query (which does prefix search, else we may have too many hits). When the user enters a space after a word is complete, then do &term query. This &term query does full word search.

    For eg: So as I type 'c' it shows ['Color (1532 products)', 'Collectible (120 products)']. If we did full word search with 'c', we will return all items with 'c' in it, thus we only do prefix search for &term queries. As I complete 'color ', it shows ['Color (1532 products)', 'Bottle cap color (32 products)']. The problem here being two different behaviours for the same input field.

    Idea 2: Both &term query and &autocomplete query does full word search. But we only give results after second character is typed.

    I will think and come back on handling multi-word queries (May have to use some sort of inverted search/search engine, though it may be an overkill).

  6. changed the title [-]Key search[/-] [+]Allow to perform a Key search[/+] on Nov 29, 2022
  7. changed the title [-]Allow to perform a Key search[/-] [+]Allow to search keys[/+] on Nov 29, 2022
  8. CharlesNepote commented on Mar 14, 2025

    @CharlesNepote
    MemberAuthor

    @stephanegigandet as a first step:

    1. I suggest to start with: /keys&term= which is searching for property name containing the term
    2. I suggest not to implement /keys&autocomplete= which is a bit redundant with term; in the vast majority of the cases, the term searched by people will be inside the property not at the beginning of the property
    3. We could later implement /keys&search= which would allow to search in the properties' documentation (but it's harder to implement)

    Ok?

  9. stephanegigandet commented on Mar 14, 2025

    @stephanegigandet

    Instead of ?term=, on the OFF website we use filter: e.g. https://fr.openfoodfacts.org/facets/labels?filter=bio returns a list of labels that have "bio" anyhwhere in them. ?term=word would be more appropriate to search for full words.

  10. CharlesNepote commented on Mar 14, 2025

    @CharlesNepote
    MemberAuthor

    @stephanegigandet Yes we should try to be coherent. But unfortunately we already use ?q= to filter thing https://api.folksonomy.openfoodfacts.org/docs#/default/get_unique_values_values__k__get

    Should we use q or filter for both?

  11. stephanegigandet commented on Mar 17, 2025

    @stephanegigandet

    "q: Filter values by a query string" -> is that the same filter you want for keys (i.e. match anywhere in the string without needing word boundaries)? if yes, then use q= for keys as well..

  12. CharlesNepote commented on Mar 17, 2025

    @CharlesNepote
    MemberAuthor

    Fine, so let's use q= as well.

  13. kirtanchandak commented on Mar 17, 2025

    @kirtanchandak
    Member

    working on this

  14. moved this from Todo to In Progress in 🏷️ Folksonomy Engineon Mar 17, 2025
  15. CharlesNepote commented on Mar 21, 2025

    @CharlesNepote
    MemberAuthor

    Thanks a lot @kirtanchandak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions