MultiDocumentQuery help

Joshua Raymond asked on October 7, 2020 14:55

Hello Everyone, I'm running into an issue that I hope someone can provide some direction on. I'm using a multidocumentquery to retrieve a bunch of documents. These documents have topics that are using a multi select field, text/value format. When selecting multiple topics for the document they're saved to the database as a string that separates the values with a | character. Right now I'm using a WhereContains condition to retrieve documents that have a particular topic, however that's prone to failure due to the way the data is saves to the database (topic1|topicc2|topic3). Is there a way to use a where condition that will split the values first before doing the lookup? Below is an example of the code I'm using now.

where.WhereContains("Topics", "topic1");

Correct Answer

Dmitry Bastron answered on October 7, 2020 17:19

Hi Joshua,

I would have probably used the following query to exclude errors:

query.WhereEquals("Topics", "topic1")
    .Or()
    .WhereStartsWith("Topics", "topic1|")
    .Or()
    .WhereEndsWith("Topics", "|topic1")
    .Or()
    .WhereContains("Topics", "|topic1|")

You can also implement this as MultiDocumentQuery extension method.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.