public void ConstructView()
        {
            _queryResult = _queryBuilder.ExecuteQuery();

            this.TotalRecordsFound = _queryResult.NumFound;

            // add facets
            // here we loop through all of our known facets and pull out what had results
            // this allows us to keep the facets in the order we want
            foreach (var facet in Global.BaseballGameFacetNames.OrderBy(d => d.Item3))
            {
                string key = facet.Item2;
                if (_queryResult.FacetFields.ContainsKey(key))
                {
                    List<Tuple<string, int>> facetValues = new List<Tuple<string, int>>();

                    foreach (var v in _queryResult.FacetFields[key])
                    {
                        facetValues.Add(new Tuple<string, int>(v.Key, v.Value));
                    }

                    this.Facets.Add(key, facetValues);
                }
            }

            // set results
            this.GameResults = _queryResult.ToList();
        }
Ejemplo n.º 2
0
 private string GetSpellCheckingResult(ISolrQueryResults <Product> products)
 {
     return(string.Join(" ", products.SpellChecking
                        .Select(c => c.Suggestions.FirstOrDefault())
                        .Where(c => !string.IsNullOrEmpty(c))
                        .ToArray()));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 真正的检索方法,需要派生类进行实现
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="solr">Solr检索器对象</param>
        /// <returns>检索结果</returns>
        protected virtual Result GetSearchResult(SearchCondition condition, ISolrOperations <Record> solr)
        {
            QueryOptions queryOptions = BuildQueryOptions(condition);
            ISolrQuery   query        = new SolrQuery(condition.KeyWord);

            ISolrQueryResults <Record> result = solr.Query(query, queryOptions);

            return(TransformSolrQueryResult(result, condition));
        }
Ejemplo n.º 4
0
        public static void GetAll()
        {
            try {
                var solr = ServiceLocator.Current.GetInstance <ISolrOperations <NewsRepository> >();
                ISolrQueryResults <NewsRepository> list = null;
                list = solr.Query(SolrQuery.All);

                foreach (NewsRepository news in list)
                {
                    HttpContext.Current.Response.Write(string.Format("{0}: {1} <br />", news.NewsID, news.NewsTitle));
                }
            }
            catch (SolrConnectionException se) {
                throw se;
            }
        }
        /// <summary> Perform an in-document search for pages with matching full-text </summary>
        /// <param name="BibID"> Bibliographic identifier (BibID) for the item to search </param>
        /// <param name="VID"> Volume identifier for the item to search </param>
        /// <param name="Search_Terms"> Terms to search for within the page text </param>
        /// <param name="ResultsPerPage"> Number of results to display per a "page" of results </param>
        /// <param name="ResultsPage"> Which page of results to return ( one-based, so the first page is page number of one )</param>
        /// <param name="Sort_By_Score"> Flag indicates whether to sort the results by relevancy score, rather than the default page order </param>
        /// <returns> Page search result object with all relevant result information </returns>
        public static Solr_Page_Results Search(string BibID, string VID, List <string> Search_Terms, int ResultsPerPage, int ResultsPage, bool Sort_By_Score)
        {
            // Ensure page is not erroneously set to zero or negative
            if (ResultsPage <= 0)
            {
                ResultsPage = 1;
            }

            // Create the solr worker to query the page index
            var solrWorker = Solr_Operations_Cache <Solr_Page_Result> .GetSolrOperations(SobekCM_Library_Settings.Page_Solr_Index_URL);

            // Create the query options
            QueryOptions options = new QueryOptions
            {
                Rows      = ResultsPerPage,
                Start     = (ResultsPage - 1) * ResultsPerPage,
                Fields    = new [] { "pageid", "pagename", "pageorder", "score", "thumbnail" },
                Highlight = new HighlightingParameters {
                    Fields = new[] { "pagetext" },
                },
                ExtraParams = new Dictionary <string, string> {
                    { "hl.useFastVectorHighlighter", "true" }
                }
            };

            // If this is not the default Solr sort (by score) request sort by the page order
            if (!Sort_By_Score)
            {
                options.OrderBy = new[] { new SortOrder("pageorder", Order.ASC) }
            }
            ;

            // Build the query string
            StringBuilder queryStringBuilder = new StringBuilder("(bibid:" + BibID + ")AND(vid:" + VID + ")AND(");
            bool          first_value        = true;

            foreach (string searchTerm in Search_Terms)
            {
                if (searchTerm.Length > 1)
                {
                    // Skip any AND NOT for now
                    if (searchTerm[0] != '-')
                    {
                        // Find the joiner
                        if (first_value)
                        {
                            if (searchTerm.IndexOf(" ") > 0)
                            {
                                if ((searchTerm[0] == '+') || (searchTerm[0] == '=') || (searchTerm[0] == '-'))
                                {
                                    queryStringBuilder.Append("(pagetext:\"" + searchTerm.Substring(1).Replace(":", "") + "\")");
                                }
                                else
                                {
                                    queryStringBuilder.Append("(pagetext:\"" + searchTerm.Replace(":", "") + "\")");
                                }
                            }
                            else
                            {
                                if ((searchTerm[0] == '+') || (searchTerm[0] == '=') || (searchTerm[0] == '-'))
                                {
                                    queryStringBuilder.Append("(pagetext:" + searchTerm.Substring(1).Replace(":", "") + ")");
                                }
                                else
                                {
                                    queryStringBuilder.Append("(pagetext:" + searchTerm.Replace(":", "") + ")");
                                }
                            }
                            first_value = false;
                        }
                        else
                        {
                            if ((searchTerm[0] == '+') || (searchTerm[0] == '=') || (searchTerm[0] == '-'))
                            {
                                queryStringBuilder.Append(searchTerm[0] == '=' ? " OR " : " AND ");

                                if (searchTerm.IndexOf(" ") > 0)
                                {
                                    queryStringBuilder.Append("(pagetext:\"" + searchTerm.Substring(1).Replace(":", "") + "\")");
                                }
                                else
                                {
                                    queryStringBuilder.Append("(pagetext:" + searchTerm.Substring(1).Replace(":", "") + ")");
                                }
                            }
                            else
                            {
                                if (searchTerm.IndexOf(" ") > 0)
                                {
                                    queryStringBuilder.Append(" AND (pagetext:\"" + searchTerm.Replace(":", "") + "\")");
                                }
                                else
                                {
                                    queryStringBuilder.Append(" AND (pagetext:" + searchTerm.Replace(":", "") + ")");
                                }
                            }
                        }
                    }
                }
            }
            queryStringBuilder.Append(")");


            // Perform this search
            ISolrQueryResults <Solr_Page_Result> results = solrWorker.Query(queryStringBuilder.ToString(), options);

            // Create the results object to pass back out
            var searchResults = new Solr_Page_Results
            {
                QueryTime     = results.Header.QTime,
                TotalResults  = results.NumFound,
                Query         = queryStringBuilder.ToString(),
                Sort_By_Score = Sort_By_Score,
                Page_Number   = ResultsPage
            };

            // Pass all the results into the List and add the highlighted text to each result as well
            foreach (Solr_Page_Result thisResult in results)
            {
                // Add the highlight snipper
                if ((results.Highlights.ContainsKey(thisResult.PageID)) && (results.Highlights[thisResult.PageID].Count > 0) && (results.Highlights[thisResult.PageID].ElementAt(0).Value.Count > 0))
                {
                    thisResult.Snippet = results.Highlights[thisResult.PageID].ElementAt(0).Value.ElementAt(0);
                }

                // Add this results
                searchResults.Add_Result(thisResult);
            }

            return(searchResults);
        }
    }
Ejemplo n.º 6
0
 private string GetSpellCheckingResult(ISolrQueryResults<Product> products)
 {
     return string.Join(" ", products.SpellChecking
                                 .Select(c => c.Suggestions.FirstOrDefault())
                                 .Where(c => !string.IsNullOrEmpty(c))
                                 .ToArray());
 }
Ejemplo n.º 7
0
        /// <summary> Perform an search for documents with matching parameters </summary>
        /// <param name="AggregationCode"> Aggregation code within which to search </param>
        /// <param name="QueryString"> Quert string for the actual search to perform aggainst the Solr/Lucene engine </param>
        /// <param name="resultsPerPage"> Number of results to display per a "page" of results </param>
        /// <param name="Page_Number"> Which page of results to return ( one-based, so the first page is page number of one )</param>
        /// <param name="Sort"> Sort to apply before returning the results of the search </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="Complete_Result_Set_Info"> [OUT] Information about the entire set of results </param>
        /// <param name="Paged_Results"> [OUT] List of search results for the requested page of results </param>
        /// <returns> Page search result object with all relevant result information </returns>
        public static bool Search(string AggregationCode, string QueryString, int resultsPerPage, int Page_Number, ushort Sort, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("Solr_Documents_Searcher.Search", String.Empty);
            }

            // Set output initially to null
            Paged_Results            = new List <iSearch_Title_Result>();
            Complete_Result_Set_Info = null;

            try
            {
                // Ensure page is not erroneously set to zero or negative
                if (Page_Number <= 0)
                {
                    Page_Number = 1;
                }

                // Create the solr worker to query the document index
                var solrWorker = Solr_Operations_Cache <Solr_Document_Result> .GetSolrOperations(SobekCM_Library_Settings.Document_Solr_Index_URL);

                // Create the query options
                QueryOptions options = new QueryOptions
                {
                    Rows      = resultsPerPage,
                    Start     = (Page_Number - 1) * resultsPerPage,
                    Fields    = new[] { "did", "score", "url", "aleph", "donor", "edition", "format", "holdinglocation", "sourceinstitution", "maintitle", "materialtype", "oclc", "pubdate_display", "author_display", "publisher_display", "mainthumbnail" },
                    Highlight = new HighlightingParameters {
                        Fields = new[] { "fulltext" },
                    },
                    ExtraParams = new Dictionary <string, string> {
                        { "hl.useFastVectorHighlighter", "true" }
                    }
                };

                // Set the sort value
                if (Sort != 0)
                {
                    options.OrderBy.Clear();
                    switch (Sort)
                    {
                    case 1:
                        options.OrderBy.Add(new SortOrder("maintitle_sort"));
                        break;

                    case 2:
                        options.OrderBy.Add(new SortOrder("bibid", Order.ASC));
                        break;

                    case 3:
                        options.OrderBy.Add(new SortOrder("bibid", Order.DESC));
                        break;

                    case 10:
                        options.OrderBy.Add(new SortOrder("pubdate", Order.ASC));
                        break;

                    case 11:
                        options.OrderBy.Add(new SortOrder("pubdate", Order.DESC));
                        break;
                    }
                }

                // If there was an aggregation code included, put that at the beginning of the search
                if ((AggregationCode.Length > 0) && (AggregationCode.ToUpper() != "ALL"))
                {
                    QueryString = "(aggregation_code:" + AggregationCode.ToUpper() + ")AND(" + QueryString + ")";
                }

                // Perform this search
                ISolrQueryResults <Solr_Document_Result> results = solrWorker.Query(QueryString, options);

                // Create the search statistcs
                Complete_Result_Set_Info = new Search_Results_Statistics
                {
                    Total_Titles = results.NumFound,
                    Total_Items  = results.NumFound,
                    QueryTime    = results.Header.QTime
                };

                // Pass all the results into the List and add the highlighted text to each result as well
                foreach (Solr_Document_Result thisResult in results)
                {
                    // Add the highlight snipper
                    if ((results.Highlights.ContainsKey(thisResult.DID)) && (results.Highlights[thisResult.DID].Count > 0) && (results.Highlights[thisResult.DID].ElementAt(0).Value.Count > 0))
                    {
                        thisResult.Snippet = results.Highlights[thisResult.DID].ElementAt(0).Value.ElementAt(0);
                    }

                    // Add this results
                    Paged_Results.Add(thisResult);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
 private static SearchResult CreateSearchResultFromSolrResult(ISolrQueryResults<SearchResultItem> solrResult)
 {
     return new SearchResult
         {
             Items = solrResult,
             NumFound = solrResult.NumFound,
             Categories = solrResult.FacetFields["CategoryName"].Select(
                 x => new KeyValuePair<string, int>(x.Key, x.Value)),
             LessThanFifty = solrResult.FacetQueries["ListPrice:[0 TO 50]"],
             FiftyToOneHundred = solrResult.FacetQueries["ListPrice:[50 TO 100]"],
             OneHundredToFiveHundred = solrResult.FacetQueries["ListPrice:[100 TO 500]"],
             OverFiveHundred = solrResult.FacetQueries["ListPrice:[500 TO *]"]
         };
 }
Ejemplo n.º 9
0
        public static IEnumerable<SuperSearchable> Parse(ISolrQueryResults<Searchable> searchables)
        {
            var groupedSearchables = searchables.GroupBy(searchable => searchable.SolrCollapseId);

            var superSearchables = new List<SuperSearchable>();
            foreach (var gSearch in groupedSearchables)
            {
                superSearchables.Add( new SuperSearchable() { Searchables = gSearch });
            }

            if (searchables.Highlights.Count > 0)
            {
                foreach (SuperSearchable sSearchable in superSearchables)
                {
                    var ssId = sSearchable.Searchables.First().SolrCollapseId;
                    sSearchable.SolrHightlights = searchables.Highlights
                        .Where(highlight => highlight.Key.SolrCollapseId == ssId)
                        .Select(doc => doc);
                }
            }

            if (searchables.Collapsing.FieldResults != null)
            {
                foreach (SuperSearchable sSearchable in superSearchables)
                {
                    var collapseField = searchables.Collapsing.FieldResults
                        .Where(fr => fr.FieldValue == sSearchable.Searchables.First().SolrCollapseId);

                    if (collapseField.Count() > 0)
                    sSearchable.CollapseCount = collapseField.First().CollapseCount;
                }
            }
            return superSearchables;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 转换Solr返回的检索文档,需要派生类进行实现
 /// </summary>
 /// <param name="solrQueryResult">Solr检索返回的文档结果</param>
 /// <param name="condition">查询条件</param>
 /// <returns>对外返回查询结果数据</returns>
 protected abstract Result TransformSolrQueryResult(ISolrQueryResults <Record> solrQueryResult, SearchCondition condition);