public void AddElementUnitTest()
        {
            Assert.Inconclusive("TODO");

            var target = new FulltextSearchResult(); // TODO: Initialize to an appropriate value
            FulltextSearchResultElement element = null; // TODO: Initialize to an appropriate value
            target.AddElement(element);
        }
        public void ElementsUnitTest()
        {
            Assert.Inconclusive("TODO");

            var target = new FulltextSearchResult(); // TODO: Initialize to an appropriate value
            List<FulltextSearchResultElement> expected = null; // TODO: Initialize to an appropriate value
            List<FulltextSearchResultElement> actual;
            target.Elements = expected;
            actual = target.Elements;
            Assert.AreEqual(expected, actual);
        }
 /// <summary>
 /// Creates a new FulltextSearchResultREST instance
 /// </summary>
 public FulltextSearchResultREST(FulltextSearchResult toBeTransferredResult)
 {
     if (toBeTransferredResult != null)
     {
         MaximumScore = toBeTransferredResult.MaximumScore;
         Elements = new List<FulltextSearchResultElementREST>(toBeTransferredResult.Elements.Count);
         for (int i = 0; i < toBeTransferredResult.Elements.Count; i++)
         {
             Elements.Add(new FulltextSearchResultElementREST(toBeTransferredResult.Elements[i]));
         }
     }
 }
Exemplo n.º 4
0
        public bool TryQuery(out FulltextSearchResult result, string query)
        {
            var regexpression = new Regex(query, RegexOptions.IgnoreCase);
            var foundSth      = false;

            result = null;

            if (ReadResource())
            {
                try
                {
                    var        matchingGraphElements = new Dictionary <AGraphElement, NestedHighLightAndCounter>();
                    var        currentScore          = 0;
                    var        maximumScore          = 0;
                    const char whitespace            = ' ';

                    foreach (var aKV in _idx)
                    {
                        var matches = regexpression.Matches(aKV.Key);

                        if (matches.Count > 0)
                        {
                            if (!foundSth)
                            {
                                result   = new FulltextSearchResult();
                                foundSth = true;
                            }

                            var localHighlights        = new HashSet <String>();
                            var countOfLocalHighlights = 0;
                            foreach (Match match in matches)
                            {
                                var currentPosition = -1;
                                var lastPosition    = -1;

                                for (var i = 0; i < match.Index; i++)
                                {
                                    if (aKV.Key[i] == whitespace)
                                    {
                                        currentPosition = i;
                                    }

                                    if (currentPosition > lastPosition)
                                    {
                                        lastPosition = currentPosition;
                                    }
                                }

                                var firstWhitespacePrev = lastPosition;

                                lastPosition = -1;

                                for (var i = match.Index + match.Length; i < aKV.Key.Length; i++)
                                {
                                    if (aKV.Key[i] == whitespace)
                                    {
                                        lastPosition = i;
                                        break;
                                    }
                                }

                                var firstWhitespaceAfter = lastPosition;

                                if (firstWhitespacePrev == -1 && firstWhitespaceAfter == -1)
                                {
                                    localHighlights.Add(aKV.Key);
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                if (firstWhitespacePrev == -1)
                                {
                                    localHighlights.Add(aKV.Key.Substring(0, firstWhitespaceAfter));
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                if (firstWhitespaceAfter == -1)
                                {
                                    localHighlights.Add(aKV.Key.Substring(firstWhitespacePrev + 1));
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                localHighlights.Add(aKV.Key.Substring(firstWhitespacePrev + 1, firstWhitespaceAfter - firstWhitespacePrev - 1));
                                countOfLocalHighlights++;
                            }

                            for (var i = 0; i < aKV.Value.Count; i++)
                            {
                                NestedHighLightAndCounter globalHighlights;
                                if (matchingGraphElements.TryGetValue(aKV.Value[i], out globalHighlights))
                                {
                                    globalHighlights.Highlights.UnionWith(localHighlights);
                                    currentScore = globalHighlights.NumberOfHighlights + countOfLocalHighlights;
                                }
                                else
                                {
                                    matchingGraphElements.Add(aKV.Value[i],
                                                              new NestedHighLightAndCounter
                                    {
                                        Highlights         = new HashSet <string>(localHighlights),
                                        NumberOfHighlights = countOfLocalHighlights
                                    });
                                    currentScore = countOfLocalHighlights;
                                }

                                maximumScore = currentScore > maximumScore
                                                                                ? currentScore
                                                                                : maximumScore;
                            }
                        }
                    }

                    if (foundSth)
                    {
                        //create the result
                        result = new FulltextSearchResult
                        {
                            MaximumScore = maximumScore,
                            Elements     = matchingGraphElements
                                           .Select(aKV => new FulltextSearchResultElement(aKV.Key, aKV.Value.NumberOfHighlights, aKV.Value.Highlights))
                                           .ToList()
                        };
                    }

                    return(foundSth);
                }
                finally
                {
                    FinishReadResource();
                }
            }

            throw new CollisionException();
        }
Exemplo n.º 5
0
        public bool TryQuery(out FulltextSearchResult result, string query)
        {
            var regexpression = new Regex(query, RegexOptions.IgnoreCase);
            var foundSth = false;
            result = null;

            if (ReadResource())
            {
                try
                {
                    var matchingGraphElements = new Dictionary<AGraphElement, NestedHighLightAndCounter>();
                    var currentScore = 0;
                    var maximumScore = 0;
                    const char whitespace = ' ';

                    foreach (var aKV in _idx)
                    {
                        var matches = regexpression.Matches(aKV.Key);

                        if (matches.Count > 0)
                        {
                            if (!foundSth)
                            {
                                result = new FulltextSearchResult();
                                foundSth = true;
                            }

                            var localHighlights = new HashSet<String>();
                            var countOfLocalHighlights = 0;
                            foreach (Match match in matches)
                            {
                                var currentPosition = -1;
                                var lastPosition = -1;

                                for (var i = 0; i < match.Index; i++)
                                {
                                    if (aKV.Key[i] == whitespace)
                                    {
                                        currentPosition = i;
                                    }

                                    if (currentPosition > lastPosition)
                                    {
                                        lastPosition = currentPosition;
                                    }
                                }

                                var firstWhitespacePrev = lastPosition;

                                lastPosition = -1;

                                for (var i = match.Index + match.Length; i < aKV.Key.Length; i++)
                                {
                                    if (aKV.Key[i] == whitespace)
                                    {
                                        lastPosition = i;
                                        break;
                                    }
                                }

                                var firstWhitespaceAfter = lastPosition;

                                if (firstWhitespacePrev == -1 && firstWhitespaceAfter == -1)
                                {
                                    localHighlights.Add(aKV.Key);
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                if (firstWhitespacePrev == -1)
                                {
                                    localHighlights.Add(aKV.Key.Substring(0, firstWhitespaceAfter));
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                if (firstWhitespaceAfter == -1)
                                {
                                    localHighlights.Add(aKV.Key.Substring(firstWhitespacePrev + 1));
                                    countOfLocalHighlights++;
                                    continue;
                                }

                                localHighlights.Add(aKV.Key.Substring(firstWhitespacePrev + 1, firstWhitespaceAfter - firstWhitespacePrev - 1));
                                countOfLocalHighlights++;
                            }

                            for (var i = 0; i < aKV.Value.Count; i++)
                            {
                                NestedHighLightAndCounter globalHighlights;
                                if (matchingGraphElements.TryGetValue(aKV.Value[i], out globalHighlights))
                                {
                                    globalHighlights.Highlights.UnionWith(localHighlights);
                                    currentScore = globalHighlights.NumberOfHighlights + countOfLocalHighlights;
                                }
                                else
                                {
                                    matchingGraphElements.Add(aKV.Value[i],
                                                              new NestedHighLightAndCounter
                                                                  {
                                                                      Highlights = new HashSet<string>(localHighlights),
                                                                      NumberOfHighlights = countOfLocalHighlights
                                                                  });
                                    currentScore = countOfLocalHighlights;
                                }

                                maximumScore = currentScore > maximumScore
                                        ? currentScore
                                        : maximumScore;
                            }
                        }
                    }

                    if (foundSth)
                    {
                        //create the result
                        result = new FulltextSearchResult
                        {
                            MaximumScore = maximumScore,
                            Elements = matchingGraphElements
                                .Select(aKV => new FulltextSearchResultElement(aKV.Key, aKV.Value.NumberOfHighlights, aKV.Value.Highlights))
                                .ToList()
                        };
                    }

                    return foundSth;
                }
                finally
                {
                    FinishReadResource();
                }
            }

            throw new CollisionException(this);
        }
Exemplo n.º 6
0
        public bool FulltextIndexScan(out FulltextSearchResult result, String indexId, string searchQuery)
        {
            IIndex index;
            if (!IndexFactory.TryGetIndex(out index, indexId))
            {
                result = null;
                return false;
            }

            var fulltextIndex = index as IFulltextIndex;
            if (fulltextIndex != null)
            {
                return fulltextIndex.TryQuery(out result, searchQuery);
            }

            result = null;
            return false;
        }
        public void MaximumScoreUnitTest()
        {
            Assert.Inconclusive("TODO");

            var target = new FulltextSearchResult(); // TODO: Initialize to an appropriate value
            double expected = 0F; // TODO: Initialize to an appropriate value
            double actual;
            target.MaximumScore = expected;
            actual = target.MaximumScore;
            Assert.AreEqual(expected, actual);
        }
        public void FulltextSearchResultConstructorUnitTest()
        {
            Assert.Inconclusive("TODO");

            var target = new FulltextSearchResult();
        }