예제 #1
0
        public IEnumerable <String> GetFiles(String query, IIndex index)
        {
            // If query does not have delimiter than all query is one word to search
            if (!query.Contains(WordDelimiter))
            {
                return(index.FindEntry(query));
            }

            var result  = new List <IndexEntry>();
            var state   = ParserState.LookingForDelimiter;
            var builder = new StringBuilder();

            foreach (var character in query)
            {
                switch (state)
                {
                case ParserState.LookingForDelimiter:
                    if (character == WordDelimiter[0])
                    {
                        state = ParserState.ReadingWord;
                    }

                    break;

                case ParserState.ReadingWord:
                    if (character == WordDelimiter[0])
                    {
                        var entry = index.FindEntry(builder.ToString());
                        if (!entry.HasFiles)
                        {
                            return(Enumerable.Empty <String>());
                        }

                        result.Add(entry);
                        state = ParserState.LookingForDelimiter;
                        builder.Clear();
                    }
                    else
                    {
                        builder.Append(character);
                    }

                    break;
                }
            }

            return(result.Cast <IEnumerable <String> >().Aggregate((r1, r2) => r1.Intersect(r2)));
        }
예제 #2
0
        public IEnumerable<String> GetFiles(String query, IIndex index)
        {
            // If query does not have delimiter than all query is one word to search
            if (!query.Contains(WordDelimiter))
                return index.FindEntry(query);

            var result = new List<IndexEntry>();
            var state = ParserState.LookingForDelimiter;
            var builder = new StringBuilder();

            foreach (var character in query)
            {
                switch (state)
                {
                    case ParserState.LookingForDelimiter:
                        if (character == WordDelimiter[0])
                            state = ParserState.ReadingWord;

                        break;

                    case ParserState.ReadingWord:
                        if (character == WordDelimiter[0])
                        {
                            var entry = index.FindEntry(builder.ToString());
                            if (!entry.HasFiles)
                                return Enumerable.Empty<String>();

                            result.Add(entry);
                            state = ParserState.LookingForDelimiter;
                            builder.Clear();
                        }
                        else
                        {
                            builder.Append(character);
                        }

                        break;
                }
            }

            return result.Cast<IEnumerable<String>>().Aggregate((r1, r2) => r1.Intersect(r2));
        }
예제 #3
0
 public IEnumerable <String> GetFiles(String query, IIndex index)
 {
     return(index.FindEntry(query));
 }
예제 #4
0
 public IEnumerable<String> GetFiles(String query, IIndex index)
 {
     return index.FindEntry(query);
 }