コード例 #1
0
        private SuggestionCollection Execute(string q, SolrNet.Commands.Parameters.QueryOptions options)
        {
            if (q == null)
            {
                q = string.Empty;
            }

            // Prepare our search string
            q = q.Trim();
            int    pos       = q.LastIndexOf(' ');
            string prefix    = "";
            string queryTerm = q;

            if (pos >= 0)
            {
                prefix    = q.Substring(0, pos + 1);
                queryTerm = q.Substring(pos + 1);
            }

            try
            {
                var suggestResults = Solr.Query(new SolrQuery(queryTerm), options);
                return(new SuggestionCollection(suggestResults.SpellChecking, prefix));
            }
            catch (Exception ex)
            {
                Utils.ThrowException(ex);
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public new CrownPeakQueryResults <T> Execute(ISolrQuery q, SolrNet.Commands.Parameters.QueryOptions options)
        {
            var param   = GetAllParameters(q, options);
            var results = new CrownPeakQueryResults <T>();
            var r       = _connection.Get(Handler, param);
            var xml     = XDocument.Parse(r);

            _parser.Parse(xml, results);
            return(results);
        }
コード例 #3
0
 /// <summary>
 /// Execute the query and return the results
 /// </summary>
 /// <param name="query"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public new CrownPeakQueryResults <T> Query(ISolrQuery query, SolrNet.Commands.Parameters.QueryOptions options)
 {
     return(_queryExecuter.Execute(query, options));
 }
コード例 #4
0
 /// <summary>
 /// Executes a query
 /// </summary>
 /// <param name="query"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public new CrownPeakQueryResults <T> Query(ISolrQuery query, SolrNet.Commands.Parameters.QueryOptions options)
 {
     return(_basicServer.Query(query, options));
 }
コード例 #5
0
 /// <summary>
 /// Executes a query
 /// </summary>
 /// <param name="query"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public new CrownPeakQueryResults <T> Query(string query, SolrNet.Commands.Parameters.QueryOptions options)
 {
     return(Query(new SolrQuery(query), options));
 }
コード例 #6
0
ファイル: Search.asmx.cs プロジェクト: runarbe/Paths.WebAPI
        public string DoSearch(string mQuery, string mStart, string mLength)
        {
            var mTimer = new Stopwatch();
            mTimer.Start();

            string strRV = string.Empty;
            ISolrOperations<Dictionary<string, object>> mSolr = default(ISolrOperations<Dictionary<string, object>>);
            // This method must be improved at some stage to remove the unecessary exception
            try
            {
                mSolr = ServiceLocator.Current.GetInstance<ISolrOperations<Dictionary<string, object>>>();
            }
            catch (Exception)
            {
                Startup.Init<Dictionary<string, object>>(Utility.solrInstance);
                mSolr = ServiceLocator.Current.GetInstance<ISolrOperations<Dictionary<string, object>>>();
            }
            SolrQueryResults<Dictionary<string, object>> mSolrResults = new SolrQueryResults<Dictionary<string, object>>();
            SolrNet.Commands.Parameters.QueryOptions mQueryOptions = new SolrNet.Commands.Parameters.QueryOptions();

            //Set offset from start (used to load page number "N")
            if (Utility.IsNumeric(mStart))
            {
                mQueryOptions.Start = Convert.ToInt32(mStart);
            }
            else
            {
                mQueryOptions.Start = 0;
            }

            //Set pagesize
            if (Utility.IsNumeric(mLength))
            {
                mQueryOptions.Rows = Convert.ToInt32(mLength);
            }
            else
            {
                mQueryOptions.Rows = 10;
            }

            //Set default query
            if (string.IsNullOrEmpty(mQuery))
            {
                mQuery = "*:*";
            }

            //Execute query
            try
            {
                mSolrResults = mSolr.Query(mQuery, mQueryOptions);
                //Create result container
                Dictionary<string, object> mDictionary = new Dictionary<string, object>();
                mDictionary.Add("code", Utility.msgStatusCodes.OperationCompletedSuccessfully);
                mDictionary.Add("data", mSolrResults);
                //Create JSON and return
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Utility.LogRequest(strRV, false, mTimer);
                strRV = serializer.Serialize(mDictionary);
            }
            catch (Exception ex)
            {
                Utility.LogRequest(strRV, true, mTimer);
                strRV = Utility.GetMsg(Utility.msgStatusCodes.OperationFailed, "SOLR error: " + ex.Message);

            }
            mSolr = null;
            mSolrResults = null;
            return strRV;
        }