Exemplo n.º 1
0
        public FieldValueFrequencyStatistics <string> GetFieldValueFrequencyStatistics(IEnumerable <string> fieldNames)
        {
            var reader = GetIndexReader();
            var result = new FieldValueFrequencyStatistics <string>(reader.NumDocs());

            foreach (var fieldName in fieldNames)
            {
                var fieldValueFrequencies = new List <FieldValueFrequency>();

                var stats = new TermRangeTermEnum(reader, FieldNameForStatistics(fieldName), null, null, true, true, null);
                if (stats.Term() != null)
                {
                    do
                    {
                        fieldValueFrequencies.Add(new FieldValueFrequency(stats.Term().Text(), stats.DocFreq()));
                    }while (stats.Next());
                }
                if (fieldValueFrequencies.Any())
                {
                    result.Add(fieldName, fieldValueFrequencies);
                }
            }

            reader.Close();

            return(result);
        }
Exemplo n.º 2
0
        public FieldValueFrequencyStatistics <IStatisticsField> GetFieldValueFrequencyStatistics(IPublishedContent content, IEnumerable <string> fieldNames = null)
        {
            if (content == null)
            {
                return(new FieldValueFrequencyStatistics <IStatisticsField>(0));
            }
            var fields = AllValueFields().StatisticsFields();

            if (fieldNames != null)
            {
                fieldNames = fields.StatisticsFieldNames().Intersect(fieldNames, StringComparer.OrdinalIgnoreCase);
            }
            else
            {
                fieldNames = fields.StatisticsFieldNames();
            }
            if (fieldNames.Any() == false)
            {
                return(new FieldValueFrequencyStatistics <IStatisticsField>(0));
            }
            var index = IndexHelper.GetIndex(content.Id) as IStatisticsIndex;

            if (index == null)
            {
                return(new FieldValueFrequencyStatistics <IStatisticsField>(0));
            }
            var statistics = index.GetFieldValueFrequencyStatistics(fieldNames);
            // the statistics are indexed by field.FormSafeName - we need to reindex them by
            // the fields themselves to support the frontend rendering
            var result = new FieldValueFrequencyStatistics <IStatisticsField>(statistics.TotalRows);

            foreach (var fieldValueFrequency in statistics.FieldValueFrequencies)
            {
                var field = fields.FirstOrDefault(f => f.FormSafeName == fieldValueFrequency.Field);
                if (field == null)
                {
                    continue;
                }
                result.Add(field, fieldValueFrequency.Frequencies);
            }
            return(result);
        }
Exemplo n.º 3
0
 public FieldValueFrequencyStatistics<IStatisticsField> GetFieldValueFrequencyStatistics(IPublishedContent content, IEnumerable<string> fieldNames = null)
 {
     if(content == null)
     {
         return new FieldValueFrequencyStatistics<IStatisticsField>(0);
     }
     var fields = AllValueFields().StatisticsFields();
     if(fieldNames != null)
     {
         fieldNames = fields.StatisticsFieldNames().Intersect(fieldNames, StringComparer.OrdinalIgnoreCase);
     }
     else
     {
         fieldNames = fields.StatisticsFieldNames();
     }
     if(fieldNames.Any() == false)
     {
         return new FieldValueFrequencyStatistics<IStatisticsField>(0);
     }
     var index = IndexHelper.GetIndex(content.Id) as IStatisticsIndex;
     if(index == null)
     {
         return new FieldValueFrequencyStatistics<IStatisticsField>(0);
     }
     var statistics = index.GetFieldValueFrequencyStatistics(fieldNames);
     // the statistics are indexed by field.FormSafeName - we need to reindex them by
     // the fields themselves to support the frontend rendering
     var result = new FieldValueFrequencyStatistics<IStatisticsField>(statistics.TotalRows);
     foreach(var fieldValueFrequency in statistics.FieldValueFrequencies)
     {
         var field = fields.FirstOrDefault(f => f.FormSafeName == fieldValueFrequency.Field);
         if(field == null)
         {
             continue;
         }
         result.Add(field, fieldValueFrequency.Frequencies);
     }
     return result;
 }
Exemplo n.º 4
0
        public FieldValueFrequencyStatistics<string> GetFieldValueFrequencyStatistics(IEnumerable<string> fieldNames)
        {
            var reader = GetIndexReader();
            var result = new FieldValueFrequencyStatistics<string>(reader.NumDocs());
            foreach (var fieldName in fieldNames)
            {
                var fieldValueFrequencies = new List<FieldValueFrequency>();

                var stats = new TermRangeTermEnum(reader, FieldNameForStatistics(fieldName), null, null, true, true, null);
                if (stats.Term() != null)
                {
                    do
                    {
                        fieldValueFrequencies.Add(new FieldValueFrequency(stats.Term().Text(), stats.DocFreq()));
                    }
                    while (stats.Next());
                }
                if (fieldValueFrequencies.Any())
                {
                    result.Add(fieldName, fieldValueFrequencies);
                }
            }

            reader.Close();

            return result;
        }