0

以下は私のMongodbデータ構造です。顧客ID、プロトフォリオ、メタタグに応じてアイテムを検索できるC#のクエリが必要です。

              {
          "_id" : ObjectId("512aed363ca67cd8a6f2f3e2"),
          "ReferenceNumber" : "MongoDb",
         "Title" : "Shashi",
         "CreatedUserId" : "users/1027",
         "Content" : "s",
         "CustomerId" : "customers/257",
         "StatusDefinitionId" : "sd",
         "ItemMetadata" : [{
         "MetadataId" : "MetadataDefinitions/839",
         "MetadataName" : "DropDown",
         "MetadataValue" : "DropDown1"
          }, {
         "MetadataId" : "MetadataDefinitions/838",
         "MetadataName" : "Number1",
         "MetadataValue" : "123"
          }],
         "Portfolios" : [{
         "_id" : "portfolios/225",
         "IsDefault" : true
         }]
         }

そして、私は以下のクエリを使用して、customeris、protofolio、metadatagsに応じてデータを検索し、これを渡します。Search( "123&"、 "portfolios / 225"、null、null、null、null、item); アイテムにはcustomeridがあります

             public ItemDetails Search(string metaDataTags, string portfolios, string statusDefinitions, int? numberOfItemsRequired, int? limit, int? offset, Item item)
    {

        ItemDetails searchedItemDetails = null;

        // Extract the tags from the metaDataTags into an array.
        var tags = new string[0];
        var portfolioIds = new string[0];
        var statusDefinitionsIds = new string[0];

        // The metatag search data sample format: "subject=physics&grade=tough&marks=150"
        if (!string.IsNullOrEmpty(metaDataTags))
        {
            // Split the string into tags array based on & separator.
            tags = metaDataTags.ToLower().Split('&');

        }

        if (!string.IsNullOrEmpty(portfolios))
        {
            // Split the string into tags array based on , separator.
            portfolioIds = portfolios.ToLower().Split(',');
        }

        if (!string.IsNullOrEmpty(statusDefinitions))
        {
            // Split the string into tags array based on & separator.
            statusDefinitionsIds = statusDefinitions.Split(',');
        }

        tags = tags.Where(x => !string.IsNullOrEmpty(x))
                   .Select(x => Regex.Replace(Regex.Replace(x, @"\s+$", string.Empty), @"^\s+", string.Empty))

                   .ToArray();

        var portFolioData = new BsonArray(portfolioIds);

        var Metatags = new BsonArray(tags);


        var query = Query.And(Query.EQ("CustomerId", item.CustomerId), Query.In("Portfolios._id", portFolioData), Query.In("ItemMetadata.MetadataValue", Metatags));

        var itemsForCustommer = _items.Find(query);

     //  searchedItemDetails.Items = itemsForCustommer.ToList();
        return searchedItemDetails;
    }
}
4

0 に答える 0