-5

I have a 2 "WEEK" vertices on azure cosmosdb graph.

g.V().hasLabel('WEEK').valueMap()

output:


{
    "type":["1 week|1 month|1 wk|one month|one week|one wk"]
},
{
    "type":["11 weeks|11 months|11 wks|eleven months|eleven weeks|eleven wks"]
}

i am trying to search CONTAINS of a STRING in the "type" property and return the vertices.

STRING = "1 week"

g.V().hasLabel('WEEK').has('type',TextP.containing('1 week')).valueMap()

output:


{
    "type":["1 week|1 month|1 wk|one month|one week|one wk"]
},
{
    "type":["11 weeks|11 months|11 wks|eleven months|eleven weeks|eleven wks"]
}

i am getting all the vertices because "11 weeks|11 months|11 wks|eleven months|eleven weeks|eleven wks" also have '1 week' in it.

my requirement is that i have to search for the contains operation but only 1st vertex should be present not the second one.

one idea can be changing the data in the "type" property and change the search string as below

g.V().hasLabel('WEEK').valueMap()

output:


{
    "type":["(1 week)|(1 month)|(1 wk)|(one month)|(one week)|(one wk)"]
},
{
    "type":["(11 weeks)|(11 months)|(11 wks)|(eleven months)|(eleven weeks)|(eleven wks)"]
}

STRING = "(1 week)"

g.V().hasLabel('WEEK').has('type',TextP.containing('(1 week)')).valueMap()

output:


{
    "type":["(1 week)|(1 month)|(1 wk)|(one month)|(one week)|(one wk)"]
}

but this way we need to change the entire data in the "type" property and have to change the STRING as well from "1 week" to "(1 week)" (as "1 week" is received from upstream)

Please let me know any other ideas for the above scenario (doing contains is mandatory)

Thanks in advance.

  • 3
    Don't spam your question with a lot of language tags. Pick only the one you're using. Is it java, python or C#? Also it seems to have nothing to do with azure cosmosdb – Magnetron Aug 05 '20 at 11:54
  • Please, specify which language you're using (looks like python?). Otherwise, I can only suggest to have a look at regular expression – Gsk Aug 05 '20 at 12:13

3 Answers3

0

You could search for items that contain your search-string + have the same amount of characters?

0

You could place a | at the beginning of the data and then look for

 STRING= "|1 week"
f1sh
  • 11,489
  • 3
  • 25
  • 51
0

Your question is kind of confusing, but something like the below should return ONLY LIST[0] being as it's only LIST[2]. It'll only return the string in the first array position which would be LIST[0]

public string[] LIST = { "1 week|1 month|1 wk|one month|one week| one wk","11 weeks|11 months|11 wks|eleven months|eleven weeks|eleven wks"};
public string STRING = "1 Week";
public int LISTLength = LIST.Length;

for(int x = 0; x < LISTLength; x++)
 {
   if (LIST[x] == STRING)
     {
       //Your action here
     }
 }
SkiSharp
  • 171
  • 9