Example #1
0
        /// <summary> Return the list of all items within a single aggregation (or ALL aggregations) </summary>
        /// <param name="SearchOptions"> Options related to this search, like the page, results per page, facets, fields, etc.. </param>
        /// <param name="UserMembership"> User-specific membership information, related to a search, which can be used to determine which items this user can discover</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 All_Browse(Search_Options_Info SearchOptions, Search_User_Membership_Info UserMembership, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results)
        {
            // Get the query string value
            string queryString = String.Empty;

            // Exclude hidden, if not an admin (later we will deal with user/groups and IP restrictions)
            if ((UserMembership == null) || (!UserMembership.LoggedIn) || (!UserMembership.Admin))
            {
                queryString = "(hidden:0) AND (discover_ips:0)";
            }

            // If there was an aggregation code included, put that at the beginning of the search
            if ((!String.IsNullOrEmpty(SearchOptions.AggregationCode)) && (SearchOptions.AggregationCode.ToUpper() != "ALL"))
            {
                if (!String.IsNullOrEmpty(queryString))
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ") AND " + queryString;
                }
                else
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ")";
                }
            }

            // Set output initially to null
            return(Run_Query(queryString, SearchOptions, UserMembership, Tracer, out Complete_Result_Set_Info, out Paged_Results));
        }
Example #2
0
        /// <summary> Return the list of newly added items within a single aggregation (or ALL aggregations) </summary>
        /// <param name="SearchOptions"> Options related to this search, like the page, results per page, facets, fields, etc.. </param>
        /// <param name="UserMembership"> User-specific membership information, related to a search, which can be used to determine which items this user can discover</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 New_Browse(Search_Options_Info SearchOptions, Search_User_Membership_Info UserMembership, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results)
        {
            // Computer the datetime for this
            DateTime two_weeks_ago = DateTime.Now.Subtract(new TimeSpan(14, 0, 0, 0));
            string   date_string   = two_weeks_ago.Year + "-" + two_weeks_ago.Month.ToString().PadLeft(2, '0') + "-" + two_weeks_ago.Day.ToString().PadLeft(2, '0') + "T00:00:00Z";

            // Get the query string value
            string queryString = null;

            // Exclude hidden, if not an admin (later we will deal with user/groups and IP restrictions)
            if ((UserMembership == null) || (!UserMembership.LoggedIn) || (!UserMembership.Admin))
            {
                queryString = "(hidden:0) AND (discover_ips:0) AND ( made_public_date:[" + date_string + " TO *] )";
            }
            else
            {
                queryString = "( made_public_date:[" + date_string + " TO *] )";
            }

            // If there was an aggregation code included, put that at the beginning of the search
            if ((!String.IsNullOrEmpty(SearchOptions.AggregationCode)) && (SearchOptions.AggregationCode.ToUpper() != "ALL"))
            {
                if (!String.IsNullOrEmpty(queryString))
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ") AND " + queryString;
                }
                else
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ")";
                }
            }

            // Set output initially to null
            return(Run_Query(queryString, SearchOptions, UserMembership, Tracer, out Complete_Result_Set_Info, out Paged_Results));
        }
Example #3
0
        /// <summary> Perform an search for documents with matching parameters </summary>
        /// <param name="Terms"> List of the search terms which define this search </param>
        /// <param name="Web_Fields"> List of the web fields associate with the search terms </param>
        /// <param name="StartDate"> Starting date, if this search includes a limitation by time </param>
        /// <param name="EndDate"> Ending date, if this search includes a limitation by time </param>
        /// <param name="SearchOptions"> Options related to this search, like the page, results per page, facets, fields, etc.. </param>
        /// <param name="UserMembership"> User-specific membership information, related to a search, which can be used to determine which items this user can discover</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(List <string> Terms, List <string> Web_Fields, Nullable <DateTime> StartDate, Nullable <DateTime> EndDate, Search_Options_Info SearchOptions, Search_User_Membership_Info UserMembership, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("v5_Solr_Documents_Searcher.Search", String.Empty);
            }

            // Get the query string
            string queryString = Create_Query_String(Terms, Web_Fields, StartDate, EndDate, Tracer);

            // Exclude hidden, if not an admin (later we will deal with user/groups and IP restrictions)
            if ((UserMembership == null) || (!UserMembership.LoggedIn) || (!UserMembership.Admin))
            {
                queryString = "(hidden:0) AND (discover_ips:0) AND (" + queryString + ")";
            }

            // If there was an aggregation code included, put that at the beginning of the search
            if ((!String.IsNullOrEmpty(SearchOptions.AggregationCode)) && (SearchOptions.AggregationCode.ToUpper() != "ALL"))
            {
                if (!String.IsNullOrEmpty(queryString))
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ") AND " + queryString;
                }
                else
                {
                    queryString = "(aggregations:" + SearchOptions.AggregationCode + ")";
                }
            }

            // Set output initially to null
            return(Run_Query(queryString, SearchOptions, UserMembership, Tracer, out Complete_Result_Set_Info, out Paged_Results));
        }
Example #4
0
        /// <summary> Run a solr query against the solr document index </summary>
        /// <param name="QueryString"> Solr query string </param>
        /// <param name="SearchOptions"> Options related to this search, like the page, results per page, facets, fields, etc.. </param>
        /// <param name="UserMembership"> User-specific membership information, related to a search, which can be used to determine which items this user can discover</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 Run_Query(string QueryString, Search_Options_Info SearchOptions, Search_User_Membership_Info UserMembership, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results)
        {
            // If the query string is empty, then set it back to *:*
            if (QueryString.Trim().Length == 0)
            {
                QueryString = "*:*";
            }

            // 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
                int pageNumber = SearchOptions.Page;
                if (pageNumber <= 0)
                {
                    pageNumber = 1;
                }

                // Get and clean the solr document url
                string solrDocumentUrl = Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL;
                if ((!String.IsNullOrEmpty(solrDocumentUrl)) && (solrDocumentUrl[solrDocumentUrl.Length - 1] == '/'))
                {
                    solrDocumentUrl = solrDocumentUrl.Substring(0, solrDocumentUrl.Length - 1);
                }

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

                // Get the list of fields
                List <string> fields = new List <string> {
                    "did", "mainthumb", "title"
                };
                fields.AddRange(SearchOptions.Fields.Select(MetadataField => MetadataField.SolrCode));

                // Create the query options
                QueryOptions options = new QueryOptions
                {
                    Rows   = SearchOptions.ResultsPerPage,
                    Start  = (pageNumber - 1) * SearchOptions.ResultsPerPage,
                    Fields = fields
                };

                // Was there full text search in that?
                if ((QueryString.Contains("(fulltext:")) && (SearchOptions.IncludeFullTextSnippets))
                {
                    options.Highlight = new HighlightingParameters {
                        Fields = new[] { "fulltext" }, Fragsize = 255
                    };
                    options.ExtraParams = new Dictionary <string, string> {
                        { "hl.useFastVectorHighlighter", "true" }, { "wt", "xml" }
                    };
                }
                else
                {
                    // We still need to instruct SOLR to return the results as XML for solr to parse it
                    options.ExtraParams = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("wt", "xml") };
                }

                // If the search stats are needed, let's get the facets
                if ((SearchOptions.Facets != null) && (SearchOptions.Facets.Count > 0))
                {
                    // Create the query facters
                    options.Facet = new FacetParameters();
                    foreach (Complete_Item_Aggregation_Metadata_Type facet in SearchOptions.Facets)
                    {
                        options.Facet.Queries.Add(new SolrFacetFieldQuery(facet.SolrCode)
                        {
                            MinCount = 1, Limit = 100
                        });
                    }
                }

                // Set the sort value
                if (SearchOptions.Sort != 0)
                {
                    options.OrderBy.Clear();
                    switch (SearchOptions.Sort)
                    {
                    case 1:
                        options.OrderBy.Add(new SortOrder("title.sort", Order.ASC));
                        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("date.gregorian", Order.ASC));
                        break;

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

                    case 12:
                        options.OrderBy.Add(new SortOrder("timeline_date", Order.ASC));

                        // If sorting by this, only get records with timeline date
                        QueryString = "(" + QueryString + ") AND timeline_date:[* TO *]";
                        break;
                    }
                }

                // Should this be grouped?
                bool grouped_results = false;
                if ((SearchOptions.GroupItemsByTitle) && (SearchOptions.Sort < 10) && (QueryString.IndexOf("fulltext") < 0))
                {
                    if (Tracer != null)
                    {
                        Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Grouping search request by bibid");
                    }

                    grouped_results = true;

                    GroupingParameters groupingParams = new GroupingParameters
                    {
                        Fields = new[] { "bibid" },

                        Format = GroupingFormat.Grouped,

                        Limit = 10,

                        Ngroups = true
                    };

                    options.Grouping = groupingParams;
                }

                // Log the search term
                if (Tracer != null)
                {
                    Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Solr Query: " + QueryString);
                }

                if (Tracer != null)
                {
                    Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Perform the search");
                }

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


                if (Tracer != null)
                {
                    Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Build the results object");
                }

                // Create the search statistcs (this part assumes no grouping, and then we fix the count shortly)
                List <string> metadataLabels = SearchOptions.Fields.Select(MetadataType => MetadataType.DisplayTerm).ToList();
                Complete_Result_Set_Info = new Search_Results_Statistics(metadataLabels)
                {
                    Total_Titles = results.NumFound,
                    Total_Items  = results.NumFound,
                    QueryTime    = results.Header.QTime
                };

                // If the search stats were needed, get the facets out
                if ((SearchOptions.Facets != null) && (SearchOptions.Facets.Count > 0))
                {
                    // Copy over all the facets
                    foreach (Complete_Item_Aggregation_Metadata_Type facetTerm in SearchOptions.Facets)
                    {
                        // Create the collection and and assifn the metadata type id
                        Search_Facet_Collection thisCollection = new Search_Facet_Collection(facetTerm.ID);

                        // Add each value
                        foreach (var facet in results.FacetFields[facetTerm.SolrCode])
                        {
                            thisCollection.Facets.Add(new Search_Facet(facet.Key, facet.Value));
                        }

                        // If there was an id and facets added, save this to the search statistics
                        if ((thisCollection.MetadataTypeID > 0) && (thisCollection.Facets.Count > 0))
                        {
                            Complete_Result_Set_Info.Facet_Collections.Add(thisCollection);
                        }
                    }
                }

                // Build the results mapper object
                v5_SolrDocument_Results_Mapper mapper = new v5_SolrDocument_Results_Mapper();

                // Build the results differently, depending on whether they were grouped or not
                if (grouped_results)
                {
                    // Get the grouped results (only grouped by bibid)
                    GroupedResults <v5_SolrDocument> title_groupings = results.Grouping["bibid"];

                    // Now step through each group (i.e., titles/bibs) in the groups
                    foreach (Group <v5_SolrDocument> grouping in title_groupings.Groups)
                    {
                        // Convert the grouping to the new result
                        v5_Solr_Title_Result newResult = mapper.Map_To_Result(grouping, SearchOptions.Fields);

                        Paged_Results.Add(newResult);
                    }

                    // Now, fix the stats as well
                    Complete_Result_Set_Info.Total_Items  = title_groupings.Matches;
                    Complete_Result_Set_Info.Total_Titles = title_groupings.Ngroups.Value;
                }
                else
                {
                    // Pass all the results into the List and add the highlighted text to each result as well
                    foreach (v5_SolrDocument thisResult in results)
                    {
                        // Convert to the new result
                        v5_Solr_Title_Result newResult = mapper.Map_To_Result(thisResult, SearchOptions.Fields);

                        // Add the highlight snippet, if applicable
                        if ((results.Highlights != null) && (results.Highlights.ContainsKey(thisResult.DID)) && (results.Highlights[thisResult.DID].Count > 0) && (results.Highlights[thisResult.DID].ElementAt(0).Value.Count > 0))
                        {
                            newResult.Snippet = results.Highlights[thisResult.DID].ElementAt(0).Value.ElementAt(0);
                        }

                        Paged_Results.Add(newResult);
                    }
                }

                return(true);
            }
            catch (Exception ee)
            {
                return(false);
            }
        }