Using anyofterms with + characters leads to unexpected results

I have a collection that has base64-encoded identifiers.

If I have a query such as:

{
    query(func: anyofterms(_node_id, "ZolFpqy28/CkH3w4Ne7XOA==")) {
        _node_id
    }
}

The result set is expected:

{
  "data": {
    "query": [
      {
        "_node_id": "ZolFpqy28/CkH3w4Ne7XOA==",
      }
    ]
  },
}

But if the search term has a + in it, such as:

{
    query(func: anyofterms(_node_id, "mC+\\Sqd0ez6+fsk4r1pQkSw==")) {
        _node_id
    }
}

The result set includes any term that has “mc” in it, such as:

{
  "data": {
    "query": [
      {
        "_node_id": "sE8Y6v93l+SG/mC/vailRw=="
      },
      {
        "_node_id": "MC/6bDfKY+kdAPwDeNd6gA=="
      },
      {
        "_node_id": "mC+zvUKVjBdu7naczA7cmQ=="
      },
      {
        "_node_id": "29N/mC/N6+gKmqK3XGT5SQ=="
      },
      {
        "_node_id": "mC/+EV+P0rlj6FDeKiiR7g=="
      },
      {
        "_node_id": "mc/J9cXDQhzq4pJ162z+JA=="
      },
      {
        "_node_id": "P+Mc+CVDyKmB6q0MVuwNqA=="
      },

I’m using Dgraph 20.07.

So, I guess this leads to an interesting question, what’s the best way then to search for lots of terms that have these sorts of characters in them? Do I need to chain together eq filters with OR combinators?

Ah I think this may be bleve that is showing itself. What happens if you do allofterms ?

If I use allofterms it finds the correct entry. I was kind of hoping to use anyofterms(field, "a b c") to search for multiple results in a more compact form than eq(field, "a") OR eq(field, "b") OR eq(field, "c") form, but if I have to use allofterms it’ll probably just be easier to use combined eq’s.

Hmm, this is a bit tricky.

allofterms and anyofterms are used for fulltext search. Whereas eq is for exact matches. The semantics are different and you cannot use one to replace a conjuncted/disjuncted expression.

1 Like