Exemple #1
0
        private static Searchers PrepareSearchers(string pattern, FuseOptions <T> options)
        {
            var tokenSearchers = new List <Bitap <T> >();

            if (options.tokenize)
            {
                var tokens = options.tokenSeparator.Split(pattern);

                for (var i = 0; i < tokens.Length; i++)
                {
                    tokenSearchers.Add(new Bitap <T>(tokens[i], options));
                }
            }

            var fullSearcher = new Bitap <T>(pattern, options);

            return(new Searchers
            {
                tokenSearchers = tokenSearchers,
                fullSearcher = fullSearcher
            });
        }
Exemple #2
0
        private static SearchResult InternalSearch(List <T> list, List <Bitap <T> > tokenSearchers, Bitap <T> fullSearcher, FuseOptions <T> options)
        {
            var resultMap = new Dictionary <int, AnalyzeResult>();
            var results   = new List <AnalyzeResult>();
            var output    = new AnalyzeOutput
            {
                resultMap      = resultMap,
                results        = results,
                tokenSearchers = tokenSearchers,
                fullSearcher   = fullSearcher
            };

            if (list[0] is string)
            {
                for (var i = 0; i < list.Count; i++)
                {
                    Analyze(new AnalyzeOpts
                    {
                        key    = "",
                        value  = (list[i] as string),
                        record = i,
                        index  = i
                    }, output, options);
                }

                return(new SearchResult
                {
                    weights = null,
                    results = results
                });
            }

            var weights = new Dictionary <string, float>();

            for (var i = 0; i < list.Count; i++)
            {
                var item = list[i];

                for (var j = 0; j < options.keys.Count; j++)
                {
                    var key    = options.keys[j];
                    var weight = (1f - key.weight);

                    if (weight == 0f)
                    {
                        weight = 1f;
                    }

                    weights[key.getter.Method.Name] = weight;

                    Analyze(new AnalyzeOpts
                    {
                        key    = key.getter.Method.Name,
                        value  = key.getter.Invoke(item),
                        record = item,
                        index  = i
                    }, output, options);
                }
            }

            return(new SearchResult
            {
                weights = weights,
                results = results
            });
        }
Exemple #3
0
        private SearchResult InternalSearch(List <Bitap <T> > tokenSearchers, Bitap <T> fullSearcher)
        {
            var resultMap = new Dictionary <int, AnalyzeResult>();
            var results   = new List <AnalyzeResult>();
            var output    = new AnalyzeOutput
            {
                resultMap      = resultMap,
                results        = results,
                tokenSearchers = tokenSearchers,
                fullSearcher   = fullSearcher
            };

            if (_list[0] is string)
            {
                for (var i = 0; i < _list.Count; i++)
                {
                    Analyze(new AnalyzeOpts
                    {
                        key    = "",
                        value  = (_list[i] as string),
                        record = i,
                        index  = i
                    }, output);
                }

                return(new SearchResult
                {
                    weights = null,
                    results = results
                });
            }

            var weights = new Dictionary <string, float>();

            for (var i = 0; i < _list.Count; i++)
            {
                var item = _list[i];

                for (var j = 0; j < _options.keys.Count; j++)
                {
                    var key    = _options.keys[j];
                    var weight = (1f - key.weight);

                    if (weight == 0f)
                    {
                        weight = 1f;
                    }

                    weights[key.name] = weight;

                    Analyze(new AnalyzeOpts
                    {
                        key    = key.name,
                        value  = _options.getFn(item, key.name),
                        record = item,
                        index  = i
                    }, output);
                }
            }

            return(new SearchResult
            {
                weights = weights,
                results = results
            });
        }