0

I have a product search index with a field "productOptions", that contains serialized JSON, meaning it may contain either an empty array for products with no options, or an array with options for products with product options:

  • []
  • [{ optionId: "", ... }]

When I try the query +productOptions: "[]" in Luke (using the StandardAnalyzer) I don't get any matches. I was under the impression that StandardAnalyzer will search not analyzed fields as long as there is an exact match - so I don't understand why I'm not getting any hits. However, if I switch over to KeywordAnalyzer I do get hits, but can't use KeywordAnalyzer since I'm querying product options as part of a more complex search query that requires StandardAnalyzer.

How can I write a query that finds all products with no options (i.e. productOptions == [])?

Note: I have no control over the indexing process, so I can't control the values being indexed.

William
  • 733
  • 4
  • 10
  • 22
  • Okay, you couldn’t control indexing, but do you have understanding of what kind of analyzer is used during indexing? – Mysterion Jan 08 '19 at 11:12
  • @Mysterion since the entire indexing process happens in a third party plugin which in turn uses Umbraco Examine I can't be 100% sure, but from what I've seen in the source code it should be the StandardAnalyzer. – William Jan 09 '19 at 12:12

1 Answers1

0

The problem here is the following, StandardAnalyzer effectively removes [] and leave this field with just empty string.

This makes searching later the same string [] - impossible to find anything.

One of the possibilities to achieve finding those “empty” strings is to search for -field_name:[* TO *], which means the following:

field_name:[* TO *] is a hacky workaround to search for any documents which contains anything but empty in this field and - is effectively negating this condition and ultimately asking for all documents which contains empty data in the field_name

Mysterion
  • 9,050
  • 3
  • 30
  • 52
  • Hmm, I get you're saying, but this returns no hits at all in Luke... when I look at the document in Luke I can see that it still has the value []. Does StandardAnalyzer remove the [] when indexing or when querying? – William Jan 13 '19 at 21:24
  • Luke could only show stored values (which means original, not analyzed) – Mysterion Jan 13 '19 at 21:29