Question

I have been working on making a Search using Solrnet which is working the way I want to. But I just would like some advice on the best way to pass my query parameters from my web page into Solrnet.

What I would ideally like to do is pass my query string parameters similar to how this site does it: http://www.watchfinder.co.uk/SearchResults.aspx?q=%3a&f_brand=Rolex&f_bracelets=Steel&f_movements=Automatic.

As you can see from the sites query string it looks like it is being passed into SolrNet directly. Here is I am doing it at the moment (facet query segment):

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;
        }       

    }

At the moment I can't seem to see how I can query all my results from my current code by add the following querystring: q=:.

Was it helpful?

Solution

I'm not sure what you mean by "parameters being passed into SolrNet directly". It seems that watchfinder is using some variant of the model binder included in the SolrNet sample app.

Also take a look at the controller in the sample app to see how the SolrNet parameters are built.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top