将查询参数传递给Solrnet的最佳方法

时间:2011-01-13 09:44:13

标签: search solrnet

我一直致力于使用Solrnet进行搜索,这是我想要的方式。但我想就将查询参数从我的网页传递到Solrnet的最佳方法提出一些建议。

我理想的做法是传递我的查询字符串参数,类似于此网站的工作方式:http://www.watchfinder.co.uk/SearchResults.aspx?q= %3a & f_brand =劳力士& f_bracelets = Steel& f_movements =自动的。

正如您从网站查询字符串中看到的那样,它看起来像是直接传递到SolrNet。我现在正在做这个(facet查询段):

public class SoftwareSalesSearcher
    {
        public static SoftwareSalesSearchResults Facet()
        {
            ISolrOperations solr = SolrOperationsCache.GetSolrOperations(ConfigurationManager.AppSettings["SolrUrl"]);

        //Iterate through querystring to get the required fields to query Solrnet
            List queryCollection = new List();
            foreach (string key in HttpContext.Current.Request.QueryString.Keys)
            {
                queryCollection.Add(new SolrQuery(String.Format("{0}:{1}", key, HttpContext.Current.Request.QueryString[key])));
            }

            var lessThan25 = new SolrQueryByRange("SoftwareSales", 0m, 25m);
            var moreThan25 = new SolrQueryByRange("SoftwareSales", 26m, 50m);
            var moreThan50 = new SolrQueryByRange("SoftwareSales", 51m, 75m);
            var moreThan75 = new SolrQueryByRange("SoftwareSales", 76m, 100m);

            QueryOptions options = new QueryOptions
            {
                Rows = 0,
                Facet = new FacetParameters {
                    Queries = new[] { new SolrFacetQuery(lessThan25), new SolrFacetQuery(moreThan25), new SolrFacetQuery(moreThan50), new SolrFacetQuery(moreThan75) }
                                            },
                FilterQueries = queryCollection.ToArray()
            };


            var results = solr.Query(SolrQuery.All, options);

            var searchResults = new SoftwareSalesSearchResults();

            List softwareSalesInformation = new List();

            foreach (var facet in results.FacetQueries)
            {
                if (facet.Value != 0)
                {
                    SoftwareSalesFacetDetail salesItem = new SoftwareSalesFacetDetail();

                    salesItem.Price = facet.Key;
                    salesItem.Value = facet.Value;

                    softwareSalesInformation.Add(salesItem);
                }

            }

            searchResults.Results = softwareSalesInformation;
            searchResults.TotalResults = results.NumFound;
            searchResults.QueryTime = results.Header.QTime;

            return searchResults;
        }       

    }

目前我似乎无法通过添加以下查询字符串来查看如何从当前代码查询我的所有结果:q =

1 个答案:

答案 0 :(得分:1)

我不确定“参数直接传递到SolrNet”是什么意思。看来,取景器正在使用model binder included in the SolrNet sample app的一些变体。

另请查看controller in the sample app以了解SolrNet参数的构建方式。