tamaramata / solrnet

Automatically exported from code.google.com/p/solrnet
0 stars 0 forks source link

Complex query #210

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I'm trying to test solr after testing elasticsearch, the dotnet query there was:

                    var filter = Filter.Terms("iDPicture", allowedResourceIds);

                    queryResults = clients[curClient].Search<Document>(
                        s => s
                                 .Fields(f => f.IDPin)
                                 .Fields(f => f.IDPicture)
                                 .Query(
                                     q => q
                                              .QueryString(
                                                  qs => qs
                                                            .OnFieldsWithBoost(
                                                                d => d
                                                                         .Add(f => f.Board, 5.0)
                                                                         .Add(f => f.User, 1.0)
                                                                         .Add(f => f.Description, 10.0)
                                                            )
                                                            .Analyzer(snowball)
                                                            .Query(text)
                                                            .PhraseSlop(slopDistance)
                                              )
                                 )
                                 .Size(searchSize)
                                 .Filter(filter)
                        );

I didn't find at the documentation the syntax to do that with Solr dot net 
client.
As seen in the code I need a query that returns only  2 fields (found how to do 
that), 
the query is on several fields and gives a different boast to each one,
snowball analyzer is used,
phrase slop is defined,
number of returned results is defined,
a filter is applied – filter by a list of allowed values for a field.

Help will be appreciated.

Ophir

Original issue reported on code.google.com by ophirmic...@gmail.com on 9 Jun 2013 at 1:03

GoogleCodeExporter commented 8 years ago
This code solves the issue:

var query = new SolrMultipleCriteriaQuery(
                        new[]
                        {
                            new SolrQueryByField( "Board", text, false ).Boost( 5 ),
                            new SolrQueryByField( "User", text, false ).Boost( 1 ),
                            new SolrQueryByField( "Description", text, false ).Boost( 10 )
                        } );
                    var queryOptions = new QueryOptions
                    {
                        Fields = new[] { "IDPin,IDPicture" },
                        Rows = searchSize,
                        ExtraParams = new Dictionary<String, String>
                        {
                            { "ps", slopDistance.ToString() }
                        }
                    };
                    queryResults = solrClient.Query(query, queryOptions);

Original comment by ophirmic...@gmail.com on 10 Jun 2013 at 3:31

GoogleCodeExporter commented 8 years ago
https://groups.google.com/d/msg/solrnet/NF_Z3kOxTx8/FmbkpuuZjSsJ

Original comment by mauricio...@gmail.com on 11 Jun 2013 at 8:26