Beispiel #1
0
        // In C# because SQL's SUM returns NULL on an empty list, so we need the ?? operator, which doesn't exist in F#. At least not one that LINQ to Entities can parse
        public static IOrderedQueryable <RevisionEntity> Search(
            this IQueryable <RevisionEntity> revisions,
            string searchTerm,
            string plain,
            string wildcard,
            SearchOrder searchOrder
            )
        {
            const NpgsqlTsRankingNormalization normalization =
                NpgsqlTsRankingNormalization.DivideBy1PlusLogLength
                | NpgsqlTsRankingNormalization.DivideByMeanHarmonicDistanceBetweenExtents;

            IQueryable <RevisionEntity> where (IQueryable <RevisionEntity> query) =>
            string.IsNullOrWhiteSpace(searchTerm)
        ? query
        : query.Where(x => x.Tsv.Matches(Functions.WebSearchToTsQuery(plain).And(Functions.ToTsQuery(wildcard))));

            IOrderedQueryable <RevisionEntity> order(IQueryable <RevisionEntity> query) =>
            searchOrder == SearchOrder.Popularity
        ? query.OrderByDescending(x => x.Example.Users)
        : query.OrderByDescending(x =>
                                  x.Tsv.RankCoverDensity(Functions.WebSearchToTsQuery(plain).And(Functions.ToTsQuery(wildcard)), normalization));

            return(revisions
                   .Apply(where)
                   .Apply(order));
        }
 /// <summary>
 /// Calculates the rank of <paramref name="vector" /> for <paramref name="query" /> using the cover density
 /// method while normalizing the result according to the behaviors specified by <paramref name="normalization" />
 /// and using custom weighting for word instances depending on their labels (D, C, B or A).
 /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING
 /// </summary>
 public static float RankCoverDensity(
     [NotNull] this NpgsqlTsVector vector,
     [NotNull] float[] weights,
     [NotNull] NpgsqlTsQuery query,
     NpgsqlTsRankingNormalization normalization)
 => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(RankCoverDensity)));
 /// <summary>
 /// Calculates the rank of <paramref name="vector" /> for <paramref name="query" /> using the cover density
 /// method while normalizing the result according to the behaviors specified by <paramref name="normalization" />
 /// and using custom weighting for word instances depending on their labels (D, C, B or A).
 /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING
 /// </summary>
 public static float RankCoverDensity(
     this NpgsqlTsVector vector,
     float[] weights,
     NpgsqlTsQuery query,
     NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException();
 /// <summary>
 /// Calculates the rank of <paramref name="vector" /> for <paramref name="query" /> while normalizing
 /// the result according to the behaviors specified by <paramref name="normalization" />
 /// and using custom weighting for word instances depending on their labels (D, C, B or A).
 /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING
 /// </summary>
 public static float Rank(
     this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query, NpgsqlTsRankingNormalization normalization)
 => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Rank)));
 /// <summary>
 /// Calculates the rank of <paramref name="vector" /> for <paramref name="query" /> while normalizing
 /// the result according to the behaviors specified by <paramref name="normalization" />.
 /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING
 /// </summary>
 public static float Rank(
     this NpgsqlTsVector vector,
     NpgsqlTsQuery query,
     NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException();