dsp-api icon indicating copy to clipboard operation
dsp-api copied to clipboard

Gravsearch filter match string with spaces

Open gfoo opened this issue 5 years ago • 11 comments

Is there a way to force Lucene (behind the scene) to match a string with spaces? In my example I try to match a title : la révolution vaudoise to the property bibliographicNoticeHasTitle.

So I tried to escape the double quote to enforce a string with spaces:

?bibliographicNoticeHasTitle knora-api:valueAsString ?bibliographicNoticeHasTitle_Value .
    FILTER knora-api:match(?bibliographicNoticeHasTitle_Value, "\"la révolution vaudoise\"")
}

but I get this error:

{
"knora-api:error":"org.knora.webapi.TriplestoreResponseException: Triplestore responded with HTTP code 400: MALFORMED QUERY: Lexical error at line 15, column 104.  Encountered: \" \" (32), after : \"Les\"",
"@context":
  { "knora-api":"http://api.knora.org/ontology/knora-api/v2#"}
}

gfoo avatar Dec 17 '19 15:12 gfoo

do I have to split the string and add an AND between words ? la AND révolution AND vaudoise

gfoo avatar Dec 17 '19 15:12 gfoo

maybe it is the escape sequence for the quotes: https://www.w3.org/TR/sparql11-query/#grammarEscapes

tobiasschweizer avatar Dec 17 '19 15:12 tobiasschweizer

the error you see is a syntactical problem

tobiasschweizer avatar Dec 17 '19 15:12 tobiasschweizer

I tried that: FILTER knora-api:match(?bibliographicNoticeHasTitle_Value, '\"la révolution vaudoise\"') and still have :

{
    "knora-api:error": "org.knora.webapi.TriplestoreResponseException: Triplestore responded with HTTP code 400: MALFORMED QUERY: Lexical error at line 14, column 103.  Encountered: \" \" (32), after : \"la\"",
    "@context": {
        "knora-api": "http://api.knora.org/ontology/knora-api/v2#"
    }
}

gfoo avatar Dec 17 '19 15:12 gfoo

and without the quotes?

'la révolution vaudoise'

tobiasschweizer avatar Dec 17 '19 16:12 tobiasschweizer

it works but it retrieves results like a OR between words

gfoo avatar Dec 17 '19 16:12 gfoo

I will try tomorrow to inspect the sparql query genrated.

gfoo avatar Dec 17 '19 16:12 gfoo

'+la +révolution +vaudoise'?

tobiasschweizer avatar Dec 17 '19 16:12 tobiasschweizer

From UI interface point of view I should add a check box match all words or match any words to add or not an AND operator between words...

gfoo avatar Dec 17 '19 16:12 gfoo

'+la +révolution +vaudoise'?

it works, I think it is like to add an AND

gfoo avatar Dec 17 '19 16:12 gfoo

yes, see https://lucene.apache.org/core/7_7_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Boolean_operators

What you tried to do first is a phrase search and I believe it lead to a syntactical error bevause of the quotes

tobiasschweizer avatar Dec 17 '19 16:12 tobiasschweizer