Пример #1
0
        internal static List <(string FilePath, DateTime LastWriteTimeUtc)> GetAllIndexedCodeSource(string luceneIndex)
        {
            try
            {
                readWriteLock.TryEnterReadLock(Constants.ReadWriteLockTimeOutMilliseconds);

                var query  = new MatchAllDocsQuery();
                var filter = new FieldValueFilter(nameof(CodeSource.FilePath));

                return(SearchDocuments(luceneIndex, query, int.MaxValue, filter).Select(u => (u.Get(nameof(CodeSource.FilePath)), new DateTime(long.Parse(u.Get(nameof(CodeSource.LastWriteTimeUtc)))))).ToList());
            }
            finally
            {
                readWriteLock.ExitReadLock();
            }
        }
Пример #2
0
 private static NameValueCollection FilterCore(FieldValueFilter filter, NameValueCollection form, params string[] keys)
 {
     Validator.ThrowIfNull(form, nameof(form));
     Validator.ThrowIfNull(keys, nameof(keys));
     return(Infrastructure.SanitizeFieldValuePairs(form, filter, keys));
 }
Пример #3
0
 private static NameValueCollection FilterCore(FieldValueFilter filter, string form, params string[] keys)
 {
     Validator.ThrowIfNull(form, nameof(form));
     Validator.ThrowIfNull(keys, nameof(keys));
     return(FilterCore(filter, FormConverter.FromString(form), keys));
 }
Пример #4
0
 private static NameValueCollection FilterCore(FieldValueFilter filter, string query, params string[] keys)
 {
     Validator.ThrowIfNull(query, nameof(query));
     Validator.ThrowIfNull(keys, nameof(keys));
     return(FilterCore(filter, QueryStringConverter.FromString(query), keys));
 }
Пример #5
0
        /// <summary>
        /// Sanitizes the query string, header or form-data from the specified arguments.
        /// </summary>
        /// <param name="fieldValuePairs">The query string, header or form-data to sanitize.</param>
        /// <param name="sanitizing">The sanitizing action to perform on the <paramref name="fieldValuePairs"/>.</param>
        /// <param name="keys">The keys to use in the sanitizing process.</param>
        /// <returns>A sanitized <see cref="NameValueCollection"/> equivalent of <paramref name="fieldValuePairs"/>.</returns>
        internal static NameValueCollection SanitizeFieldValuePairs(NameValueCollection fieldValuePairs, FieldValueFilter sanitizing, IEnumerable <string> keys)
        {
            if (fieldValuePairs == null)
            {
                throw new ArgumentNullException(nameof(fieldValuePairs));
            }
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            NameValueCollection modifiedFieldValuePairs = new NameValueCollection(fieldValuePairs);

            switch (sanitizing)
            {
            case FieldValueFilter.RemoveDublets:
                foreach (string key in keys)
                {
                    string[] values         = modifiedFieldValuePairs[key].Split(',');
                    int      zeroBasedIndex = values.Length - 1;
                    if (zeroBasedIndex >= 0)
                    {
                        modifiedFieldValuePairs[key] = values[zeroBasedIndex];
                    }
                }
                break;

            case FieldValueFilter.Remove:
                foreach (string key in keys)
                {
                    modifiedFieldValuePairs.Remove(key);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sanitizing));
            }
            return(modifiedFieldValuePairs);
        }
Пример #6
0
        static Document[] SearchDocuments(string luceneIndex, Query query, int maxResult, FieldValueFilter fieldValueFilter = null)
        {
            Document[]    documents     = null;
            IndexSearcher indexSearcher = null;

            try
            {
                indexSearcher = CreateOrGetIndexSearcher(luceneIndex);

                if (fieldValueFilter != null)
                {
                    documents = indexSearcher.Search(query, fieldValueFilter, maxResult).ScoreDocs.Select(hit => indexSearcher.Doc(hit.Doc)).ToArray();
                }
                else
                {
                    documents = indexSearcher.Search(query, maxResult).ScoreDocs.Select(hit => indexSearcher.Doc(hit.Doc)).ToArray();
                }
            }
            finally
            {
                indexSearcher.IndexReader.DecRef();
            }

            return(documents ?? Array.Empty <Document>());
        }
Пример #7
0
 private static NameValueCollection FilterCore(FieldValueFilter filter, string headers, params string[] keys)
 {
     Validator.ThrowIfNull(headers, nameof(headers));
     Validator.ThrowIfNull(keys, nameof(keys));
     return(FilterCore(filter, HeadersConverter.FromString(headers), keys));
 }