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

Don't throw exception when encountering invalid query terms #1541

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

kwahlin
Copy link
Contributor

@kwahlin kwahlin commented Dec 18, 2024

Proceed with the query in the usual way (we won't get any hits though), however mark the invalid parts in search.mapping like this:

{
    "@type": "_Invalid",
    "label": "theInvalidInputString"
}

This can apply to both keys and values. So if we type for example type:Kalle x:y subject:horses we get

"search": {
    "mapping": [
      {
        "and": [
          {
            "property": {
              "@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
              "@type": "ObjectProperty",
              "labelByLang": {
                "en": "type",
                "sv": "typ"
              }
            },
            "equals": {
              "@type": "_Invalid",
              "label": "Kalle"
            },
            "up": {
              "@id": "/find?_i=&_q=x:y+subject:horses&_limit=200"
            }
          },
          {
            property": {
              "@type": "_Invalid",
              "label": "x"
            },
            "equals": "y",
            "up": {
              "@id": "/find?_i=&_q=%22rdf:type%22:Kalle+subject:horses&_limit=200"
            }
          },
          {
            "property": {
              "@id": "https://id.kb.se/vocab/subject",
              "@type": "ObjectProperty",
               ...
            },
            "equals": "horses",
            "up": {
              "@id": "/find?_i=&_q=%22rdf:type%22:Kalle+x:y&_limit=200"
            }
          }
        ],
        "up": {
          "@id": "/find?_i=&_q=*&_limit=200"
        }
      }
    ]
  }

since x is an invalid key and Kalle is and invalid value for the property rdf:type.

Eventually we may need more details about why a certain string is invalid and, consequently, also a more expressive model. Let's see. Stick with the temporary _Invalid type for now.

Copy link
Contributor

@olovy olovy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Perhaps InvalidKey could be aligned with Property so that the don't have to be treated separately in this part of the code?

i.e.

interface Foo { 
    String name();
    Map<String, Object> definition();
}

public class Property implements Foo { ... }

public sealed interface InvalidKey extends Foo { ... }

@olovy
Copy link
Contributor

olovy commented Dec 18, 2024

LGTM!

Perhaps InvalidKey could be aligned with Property so that the don't have to be treated separately in this part of the code?

i.e.

interface Foo { 
    String name();
    Map<String, Object> definition();
}

public class Property implements Foo { ... }

public sealed interface InvalidKey extends Foo { ... }

for example #1543

@kwahlin kwahlin merged commit bb09334 into develop Dec 19, 2024
1 check passed
@kwahlin kwahlin deleted the feature/lws-271-handle-invalid-query-terms branch December 19, 2024 08:26
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

Successfully merging this pull request may close these issues.

2 participants