Ejemplo n.º 1
0
        public LuceneSearchResultCollection FieldSearch(QueryInfo[] qis)
        {
            HighResTimer timer        = new HighResTimer(true);
            var          booleanQuery = new BooleanQuery();

            foreach (var qi in qis)
            {
                var q = GetQuery(qi);
                if (q != null)
                {
                    booleanQuery.Add(q, qi.LuceneBooleanClauseOccur);
                }
            }

            IList <Document> hits = null;

            if (booleanQuery.Clauses.Count > 0)
            {
                hits = GetSearchHits(booleanQuery);
            }

            return(hits != null
                    ? new LuceneSearchResultCollection(hits, timer.Elapsed())
                    : null);
        }
Ejemplo n.º 2
0
        public SitecoreSearchResultCollection FieldSearch(QueryInfo[] qis, int maxResults)
        {
            HighResTimer timer         = new HighResTimer(true);
            var          combinedQuery = new CombinedQuery();

            foreach (var qi in qis)
            {
                var q = GetQuery(qi);
                if (q != null)
                {
                    combinedQuery.Add(q, qi.SitecoreSearchQueryOccurance);
                }
            }

            SearchResultCollection results = null;

            if (combinedQuery.Clauses.Count > 0)
            {
                results = GetSearchHits(combinedQuery, maxResults);
            }

            return(results != null
                    ? new SitecoreSearchResultCollection(results, timer.Elapsed())
                    : null);
        }
Ejemplo n.º 3
0
        public string Execute([NotNull] string path, [NotNull] string databaseName, [NotNull] string expression, [NotNull] string mode)
        {
            Assert.ArgumentNotNull(path, nameof(path));
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(expression, nameof(expression));
            Assert.ArgumentNotNull(mode, nameof(mode));

            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                return("Database not found");
            }

            var currentItem = database.GetItem(path);

            if (currentItem == null)
            {
                return("Item not found");
            }

            try
            {
                IEnumerable <Item> items;

                var timer = new HighResTimer(true);

                if (mode == "real")
                {
                    items = EvaluateRealXPath(currentItem, expression);
                }
                else
                {
                    items = EvaluateSitecoreXPath(currentItem, expression);
                }

                var elapsed = timer.Elapsed();

                if (items == null)
                {
                    return(string.Empty);
                }

                return(FormatItems(items, elapsed));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 4
0
        //----------------------------------------------------------------------------------
        /// <summary>
        /// Search the index for a document where the field has the searchstring
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="searchString">The search string.</param>
        /// <param name="queryType">Type of the query.</param>
        /// <returns></returns>
        /// <remark>Created 07/01/2009 14:19 by jm</remark>
        //----------------------------------------------------------------------------------
        public SearchResultCollection FieldSearch(string fieldName, string searchString, string queryType)
        {
            if (String.IsNullOrEmpty(searchString) ||
                String.IsNullOrEmpty(fieldName) ||
                Index == null)
            {
                return null;
            }

            HighResTimer timer = new HighResTimer(true);
            Hits hits = GetSearchHits(fieldName, searchString, queryType);

            return hits != null
                    ? new SearchResultCollection(hits, timer.Elapsed())
                    : null;
        }
Ejemplo n.º 5
0
        public SitecoreSearchResultCollection FieldSearch(QueryInfo[] qis, int maxResults)
        {
            HighResTimer timer = new HighResTimer(true);
            var combinedQuery = new CombinedQuery();
            foreach (var qi in qis)
            {
                var q = GetQuery(qi);
                if (q != null)
                    combinedQuery.Add(q, qi.SitecoreSearchQueryOccurance);
            }

            SearchResultCollection results = null;

            if (combinedQuery.Clauses.Count > 0)
                results = GetSearchHits(combinedQuery, maxResults);

            return results != null
                    ? new SitecoreSearchResultCollection(results, timer.Elapsed())
                    : null;
        }