コード例 #1
0
        /// <summary>
        /// Execute a search requiring all terms in the query to be present, not necessarily in
        /// the order entered, though that will boost the relevance. Pretty much the same
        /// as SearchMultiRelevance, except terms are AND'd rather than OR'd
        /// </summary>
        /// <returns></returns>
        public ISearchResults ResultsMultiAnd()
        {
            var query = new StringBuilder();

            if (Parameters.SearchTerm.Contains('"'))
            {
                // If the user has entered double quotes we don't bother
                // searching for the full string
                query.Append(QueryAllPropertiesAnd(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1.0));
            }
            else if (!Parameters.SearchTerm.Contains('"') && !Parameters.SearchTerm.Contains(' '))
            {
                // if there's no spaces or quotes we don't need to get the quoted term and boost it
                query.Append(QueryAllPropertiesAnd(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1));
            }
            else
            {
                // otherwise we search first for the entire query in quotes,
                // then for each term in the query OR'd together.
                query.AppendFormat("{0} OR {1}",
                                   QueryAllPropertiesAnd(SearchUtilities.GetSearchTermQuoted(Parameters.SearchTerm), 2)
                                   , QueryAllPropertiesAnd(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1)
                                   );
            }
            return(ExecuteSearch(WrapQuery(query)));
        }
コード例 #2
0
        /// <summary>
        /// Run a quoted query
        /// </summary>
        /// <returns></returns>
        public ISearchResults ResultsAsEntered()
        {
            var query = new StringBuilder();

            query.Append(QueryAllPropertiesAnd(SearchUtilities.GetSearchTermQuoted(Parameters.SearchTerm), 1.0));
            return(ExecuteSearch(WrapQuery(query)));
        }
コード例 #3
0
        /// <summary>
        /// "multi relevance" search does the following... roughly
        /// The index is searched for, in order of decreasing relevance
        /// 1) the exact phrase entered in any of the title properties
        /// 2) any of the terms entered in any of the title properties
        /// 3) a fuzzy match for any of the terms entered in any of the title properties
        /// 4) the exact phrase entered in any of the body properties
        /// 5) any of the terms entered in any of the body properties
        /// 6) a fuzzy match for any of the terms entered in any of the body properties
        /// </summary>
        /// <returns></returns>
        public ISearchResults ResultsMultiRelevance()
        {
            var query = new StringBuilder();

            // We formulate the query differently depending on the input.
            if (Parameters.SearchTerm.Contains('"'))
            {
                // If the user has entered double quotes we don't bother
                // searching for the full string
                query.Append(QueryAllPropertiesOr(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1));
            }
            else if (!Parameters.SearchTerm.Contains('"') && !Parameters.SearchTerm.Contains(' '))
            {
                // if there's no spaces or quotes we don't need to get the quoted term and boost it
                query.Append(QueryAllPropertiesOr(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1));
            }
            else
            {
                // otherwise we search first for the entire query in quotes,
                // then for each term in the query OR'd together.
                query.AppendFormat("({0} OR {1})",
                                   QueryAllPropertiesOr(SearchUtilities.GetSearchTermQuoted(Parameters.SearchTerm), 2)
                                   , QueryAllPropertiesOr(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1)
                                   );
            }
            var wrappedQuery = WrapQuery(query);
            var result       = ExecuteSearch(wrappedQuery);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Simple search for any term in the query. Make this simpler so it executes faster
        /// </summary>
        /// <returns></returns>
        public ISearchResults ResultsSimpleOr()
        {
            var query = new StringBuilder();

            query.Append(QueryAllProperties(SearchUtilities.GetSearchTermsSplit(Parameters.SearchTerm), 1.0, "OR", true));
            return(ExecuteSearch(WrapQuery(query)));
        }