Esempio n. 1
0
 public BlogReadService(
     DataContext dataContext,
     IKeywordProcessor keywordProcessor,
     SearchSettings searchSettings
     )
 {
     _dataContext      = dataContext;
     _keywordProcessor = keywordProcessor;
     _searchSettings   = searchSettings;
 }
        /// <summary>
        ///     <para>
        ///         Find items of type <see cref="T" /> which have matching keywords for the text passed
        ///     </para>
        ///     <para>Text is processed by the passed processor, which should be the same one that builds the keywords for the elements</para>
        ///     <para>
        ///         The search is ranked by Tf-idf <seealso cref="http://en.wikipedia.org/wiki/Tf%E2%80%93idf" />
        ///     </para>
        /// </summary>
        /// <typeparam name="T">Entity Type</typeparam>
        /// <param name="source">
        ///     Queryable source of <see cref="T" />
        /// </param>
        /// <param name="text">Text to find</param>
        /// <param name="keywordProcessor">Processes the text into keywords to search on</param>
        /// <returns>Matching ranked elements</returns>
        public static IQueryable <T> Match <T>(
            this IQueryable <T> source,
            string text,
            IKeywordProcessor keywordProcessor)
            where T : IndexedEntity
        {
            Contract.Requires(source != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(text));
            Contract.Requires(keywordProcessor != null);

            var keywords = keywordProcessor.Process(text, true);

            return
                (from e in source
                 let rank =
                     (
                         from ek in e.Keywords
                         where keywords.Any(k => ek.Keyword.Value.StartsWith(k))
                         select ek.Frequency / (decimal)ek.Keyword.Frequency
                     ).Sum()
                     where rank > 0
                     orderby rank descending
                     select e);
        }
Esempio n. 3
0
 public KeywordsBuilder(IKeywordProcessor processor)
 {
     _processor = processor;
     _items     = new HashSet <Func <T, IEnumerable <string> > >();
 }
Esempio n. 4
0
 public KeywordsBuilderProvider(
     IKeywordProcessor processor)
 {
     _processor = processor;
 }
Esempio n. 5
0
 public PCF_Dictionary(IKeywordProcessor keywordProcessor)
 {
     _keywordProcessor       = keywordProcessor;
     _topLevelDictionary     = CreateTopLevelDictionary();
     _elementLevelDictionary = CreateElementLevelDictionary();
 }