Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2707

Ability to include or inject text search score

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Linq, LINQ3
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      I am unable to use LINQ and have to resort to huge fluent interfaces like the following, solely because I cannot sort on the text search score.

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      private IAggregateFluent<ProductTypeSearchResult> CreateSearchQuery(string query,
                  IReadOnlyCollection<string> productFamilyIds, int
                      skipCount, int limitCount)
              {
                  var filter = Builders<ProductType>.Filter.Text(query);
                  return _productTypes
                      .Aggregate()
                      .Match(filter)
                      .Match(productType =>
                          !(string.IsNullOrEmpty(productType.ShopUrl) && string.IsNullOrEmpty(productType.TypeUrl)) &&
                          (productFamilyIds == null || productFamilyIds.Count == 0 ||
                           productFamilyIds.Contains(productType.ProductFamilyId))
                      )
                      .AppendStage<ProductType>("{$addFields: {score: {$meta:'textScore'}}}")
                      .Sort(Sort)
                      .Skip(skipCount)
                      .Limit(limitCount)
                      .Lookup<ProductType, Product, SearchAugmentedProductType>(
                          _products,
                          productType => productType.ProductTypeId,
                          product => product.ProductTypeId,
                          searchAugmentedProductType => searchAugmentedProductType.Products)
                      .Lookup<SearchAugmentedProductType, Delivery, Delivery, IEnumerable<Delivery>,
                          SearchAugmentedProductType>(
                          _deliveries,
                          new BsonDocument { { "products", "$products" } },
                          DeliveriesLookupPipeline,
                          searchAugmentedProductType => searchAugmentedProductType.Deliveries)
                      .Project(pt => new ProductTypeSearchResult
                      {
                          Description = pt.ExternalProductTypeDescription,
                          Id = pt.Id,
                          Name = pt.Name,
                          ProductFamilyId = pt.ProductFamilyId,
                          //Testing for == null does not work if the field does not exist. Have to use null coalescing operator.
                          //Driver version 2.8.1
                          IsExternalUrl = string.IsNullOrEmpty(pt.ShopUrl ?? ""),
                          Url = pt.ShopUrl ?? pt.TypeUrl,
                          Score = pt.Score,
                          // ToList() and ToArray() cannot used as there is no equivalent expression in MongoDb.
                          // We must return an IEnumerable<T>
                          Deliveries = pt.Deliveries.Select(d => new DeliverySearchResult
                          {
                              DeliveryId = d.DeliveryId,
                              Language = d.Language,
                              Platform = d.Platform,
                              OperatingSystem = d.OperatingSystem,
                              ReleaseInfo = d.ReleaseInfo
                          })
                      });
              }
      

      If I could modify my WhereText extension (which would also be nice to include with theĀ  method to be something like:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
              public static IMongoQueryable<T> WhereText<T>(this IMongoQueryable<T> query, string search, Func<T, ?> propertyExpression)
              {
                  var filter = Builders<T>.Filter.Text(search);
                  return query.Where(_ => {
                     filter.Inject());
                     filter.InjectScore(propertyExpression);
              }
      

      Where the propertyExpression is likeĀ  p=>p.somePropertyName

      I think that would alleviate the issue. Right now, full text search queries are a major time suck to implement.

            Assignee:
            Unassigned Unassigned
            Reporter:
            rcollette@yahoo.com Richard Collette
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: