/// <summary> Constructor for a new instance of the Text_Search_ItemViewer class, which allows the full text of an
        /// individual resource to be searched and individual matching pages are displayed with page thumbnails </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Text_Search_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Text_Search_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem      = BriefItem;
            this.CurrentUser    = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            if (!String.IsNullOrWhiteSpace(CurrentRequest.Text_Search))
            {
                List <string> terms      = new List <string>();
                List <string> web_fields = new List <string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentRequest.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Performing Solr/Lucene search");

                int page = CurrentRequest.SubPage.HasValue ? Math.Max(CurrentRequest.SubPage.Value, ((ushort)1)) : 1;
                results = Solr_Page_Results.Search(BriefItem.BibID, BriefItem.VID, terms, 20, page, false);

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
Ejemplo n.º 2
0
        private string compute_text_redirect_stem()
        {
            // Split the parts
            List <string> terms  = new List <string>();
            List <string> fields = new List <string>();

            // Split the terms correctly
            SobekCM_Assistant.Split_Clean_Search_Terms_Fields(RequestSpecificValues.Current_Mode.Search_String, RequestSpecificValues.Current_Mode.Search_Fields, RequestSpecificValues.Current_Mode.Search_Type, terms, fields, UI_ApplicationCache_Gateway.Search_Stop_Words, RequestSpecificValues.Current_Mode.Search_Precision, ',');

            // See about a text search string
            StringBuilder textSearcher = new StringBuilder();

            // Step through each term and field
            bool text_included_in_search = false;

            for (int i = 0; (i < terms.Count) && (i < fields.Count); i++)
            {
                if ((fields[i].Length > 1) && (terms[i].Length > 1))
                {
                    // If this is either for ANYWHERE or for TEXT, include it
                    if (((fields[i].IndexOf("TX") >= 0) || (fields[i].IndexOf("ZZ") >= 0)) && (fields[i][0] != '-'))
                    {
                        if (textSearcher.Length > 0)
                        {
                            textSearcher.Append("+=" + terms[i].Replace("\"", "%22"));
                        }
                        else
                        {
                            textSearcher.Append(terms[i].Replace("\"", "%22"));
                        }
                    }

                    // See if this was explicitly a search against full text
                    if (fields[i].IndexOf("TX") >= 0)
                    {
                        text_included_in_search = true;
                    }
                }
            }

            string url_options = UrlWriterHelper.URL_Options(RequestSpecificValues.Current_Mode);

            if (!String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Coordinates))
            {
                return((url_options.Length > 0) ? "?coord=" + RequestSpecificValues.Current_Mode.Coordinates + "&" + url_options : "?coord=" + RequestSpecificValues.Current_Mode.Coordinates);
            }

            if (textSearcher.Length > 0)
            {
                if ((RequestSpecificValues.Current_Mode.Search_Type == Search_Type_Enum.Full_Text) || (text_included_in_search))
                {
                    return((url_options.Length > 0) ? "/search?search=" + textSearcher + "&" + url_options :  "/search?search=" + textSearcher);
                }

                return((url_options.Length > 0) ? "?search=" + textSearcher + "&" + url_options : "?search=" + textSearcher);
            }
            return((url_options.Length > 0) ?  "?" + url_options :  String.Empty);
        }
Ejemplo n.º 3
0
        /// <summary> This provides an opportunity for the viewer to perform any pre-display work
        /// which is necessary before entering any of the rendering portions </summary>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <remarks> This method his class pulls any full-text search results for this single item from the Solr/Lucene engine </remarks>
        public override void Perform_PreDisplay_Work(Custom_Tracer Tracer)
        {
            if (CurrentMode.Text_Search.Length > 0)
            {
                List <string> terms      = new List <string>();
                List <string> web_fields = new List <string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentMode.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_Item_Viewer.Perform_PreDisplay_Work", "Performing Solr/Lucene search");

                results = Solr_Page_Results.Search(CurrentItem.BibID, CurrentItem.VID, terms, 20, CurrentMode.SubPage, false);

                Tracer.Add_Trace("Text_Search_Item_Viewer.Perform_PreDisplay_Work", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
Ejemplo n.º 4
0
        private DataSet Perform_Database_Search()
        {
            // Get the aggregation
            string code = Aggregation;

            if (Aggregation.Length == 0)
            {
                code = Institution;
            }

            // Build the search string and search fields string
            string        searchString      = First_Value + "|" + Second_Value + "|" + Third_Value + "|" + Fourth_Value;
            StringBuilder termStringBuilder = new StringBuilder();

            termStringBuilder.Append(term_to_code(First_Term) + "|");
            termStringBuilder.Append(join_to_symbol(First_Link) + term_to_code(Second_Term) + "|");
            termStringBuilder.Append(join_to_symbol(Second_Link) + term_to_code(Third_Term) + "|");
            termStringBuilder.Append(join_to_symbol(Third_Link) + term_to_code(Fourth_Term));
            string fieldString = termStringBuilder.ToString();


            List <string> terms      = new List <string>();
            List <string> web_fields = new List <string>();
            List <int>    db_fields  = new List <int>();
            List <int>    links      = new List <int>();

            // Split the terms correctly
            SobekCM_Assistant.Split_Clean_Search_Terms_Fields(searchString, fieldString, Search_Type_Enum.Advanced, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

            // Get the count that will be used
            int actualCount = Math.Min(terms.Count, web_fields.Count);

            // If there are no terms, return an empty item collection
            if (terms.Count == 0)
            {
                return(null);
            }

            // Special code for searching by bibid, oclc, or aleph
            if (actualCount == 1)
            {
                // Was this a OCLC search?
                if ((web_fields[0] == "OC") && (terms[0].Length > 0))
                {
                    bool is_number = terms[0].All(Char.IsNumber);

                    if (is_number)
                    {
                        long oclc = Convert.ToInt64(terms[0]);
                        return(SobekCM_Database.Tracking_Items_By_OCLC_Number(oclc, null));
                    }
                }

                // Was this a ALEPH search?
                if ((web_fields[0] == "AL") && (terms[0].Length > 0))
                {
                    bool is_number = terms[0].All(Char.IsNumber);

                    if (is_number)
                    {
                        int aleph = Convert.ToInt32(terms[0]);
                        return(SobekCM_Database.Tracking_Items_By_ALEPH_Number(aleph, null));
                    }
                }
            }

            // Step through all the web fields and convert to db fields
            for (int i = 0; i < actualCount; i++)
            {
                if (web_fields[i].Length > 1)
                {
                    // Find the joiner
                    if ((web_fields[i][0] == '+') || (web_fields[i][0] == '=') || (web_fields[i][0] == '-'))
                    {
                        if (i != 0)
                        {
                            if (web_fields[i][0] == '+')
                            {
                                links.Add(0);
                            }
                            if (web_fields[i][0] == '=')
                            {
                                links.Add(1);
                            }
                            if (web_fields[i][0] == '-')
                            {
                                links.Add(2);
                            }
                        }
                        web_fields[i] = web_fields[i].Substring(1);
                    }
                    else
                    {
                        if (i != 0)
                        {
                            links.Add(0);
                        }
                    }

                    // Find the db field number
                    //db_fields.Add( Settings.SMaRT_GlobalValues.Search_Fields.Metadata_Field_Number(web_fields[i]));
                }

                // Also add starting and ending quotes to all the valid searches
                if (terms[i].Length > 0)
                {
                    if ((terms[i].IndexOf("\"") < 0) && (terms[i].IndexOf(" ") < 0))
                    {
                        // Since this is a single word, see what type of special codes to include
                        switch (Search_Precision)
                        {
                        case Search_Precision_Type_Enum.Contains:
                            terms[i] = "\"" + terms[i] + "\"";
                            break;

                        case Search_Precision_Type_Enum.Inflectional_Form:
                            // If there are any non-characters, don't use inflectional for this term
                            bool inflectional = terms[i].All(Char.IsLetter);
                            if (inflectional)
                            {
                                terms[i] = "FORMSOF(inflectional," + terms[i] + ")";
                            }
                            else
                            {
                                terms[i] = "\"" + terms[i] + "\"";
                            }
                            break;

                        case Search_Precision_Type_Enum.Synonmic_Form:
                            terms[i] = "FORMSOF(thesaurus," + terms[i] + ")";
                            break;
                        }
                    }
                    else
                    {
                        if (Search_Precision != Search_Precision_Type_Enum.Exact_Match)
                        {
                            terms[i] = "\"" + terms[i] + "\"";
                        }
                    }
                }
            }

            // If this is an exact match, just do the search
            if (Search_Precision == Search_Precision_Type_Enum.Exact_Match)
            {
                return(SobekCM_Database.Tracking_Metadata_Exact_Search(terms[0], db_fields[0], code));
            }

            // Finish filling up the fields and links
            while (links.Count < 9)
            {
                links.Add(0);
            }
            while (db_fields.Count < 10)
            {
                db_fields.Add(-1);
            }
            while (terms.Count < 10)
            {
                terms.Add(String.Empty);
            }

            // See if this is a simple search, which can use a more optimized search routine
            bool simplified_search = db_fields.All(field => field <= 0);

            // Perform either the simpler metadata search, or the more complex
            if (simplified_search)
            {
                StringBuilder searchBuilder = new StringBuilder();
                for (int i = 0; i < terms.Count; i++)
                {
                    if (terms[i].Length > 0)
                    {
                        if (i > 0)
                        {
                            if (i > links.Count)
                            {
                                searchBuilder.Append(" AND ");
                            }
                            else
                            {
                                switch (links[i - 1])
                                {
                                case 0:
                                    searchBuilder.Append(" AND ");
                                    break;

                                case 1:
                                    searchBuilder.Append(" OR ");
                                    break;

                                case 2:
                                    searchBuilder.Append(" AND NOT ");
                                    break;
                                }
                            }
                        }

                        searchBuilder.Append(terms[i]);
                    }
                }

                return(SobekCM_Database.Tracking_Metadata_Search(searchBuilder.ToString(), code));
                // OLD CODE WHEN USING THE SIMPLE METADATA SEARCH WHICH INCLUDES THE SAME LINK TYPE
                //return Database.SobekCM_Database.Perform_Metadata_Search(terms[0], terms[1], terms[2], terms[3],
                //  terms[4], terms[5], terms[6], terms[7], terms[8], terms[9], main_link, include_private, Current_Mode.Aggregation, Tracer);
            }

            return(SobekCM_Database.Tracking_Metadata_Search(terms[0], db_fields[0], links[0], terms[1], db_fields[1], links[1], terms[2], db_fields[2], links[2], terms[3],
                                                             db_fields[3], links[3], terms[4], db_fields[4], links[4], terms[5], db_fields[5], links[5], terms[6], db_fields[6], links[6], terms[7], db_fields[7], links[7], terms[8], db_fields[8],
                                                             links[8], terms[9], db_fields[9], code));
        }