How to POST versus GET

705 views
Skip to first unread message

billnbell

unread,
Sep 13, 2011, 12:21:04 AM9/13/11
to SolrNet
We are using Unity and Solrnet.

How would we configure Solrnet to use POST instead of GET when
selecting from SOLR?

Mauricio Scheffer

unread,
Sep 13, 2011, 8:14:46 AM9/13/11
to sol...@googlegroups.com
See http://bugsquash.blogspot.com/2010/12/customizing-solrnet.html

--
Mauricio




--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To post to this group, send email to sol...@googlegroups.com.
To unsubscribe from this group, send email to solrnet+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/solrnet?hl=en.


Deren' Andry

unread,
Sep 6, 2012, 8:39:52 AM9/6/12
to sol...@googlegroups.com
Mauricio, thank for POST-variant implementation, but looks like it not work for today.
My problem is next: We have many Solr shards on different servers, with basic authentication (impletent it you help me earlier - tnx you). But now we faced with 400 - Bad request error. Guys from "Java develompent side" of team helped me with localizing it - GET requests causes this error.
Now we need implement POST Solr request with multiple shards and Windsor.
Early I have this (for standard GET implementation):

public static void RegisterFacility<T>(IEnumerable<ShardOptions> shardOptions, string baseHttpUrl = null)
        {
            SolrNetFacility facility = null;
            if (baseHttpUrl != null)
            {
                facility = new SolrNetFacility(baseHttpUrl);
            }
            else
            {
                facility = new SolrNetFacility();
            }
            foreach (var shard in shardOptions)
            {
                var coreName = "core_" + Guid.NewGuid();
                facility.AddCore(coreName, typeof(T), shard.HttpUrl);
                RegisteredCores.Add(coreName, shard);
            }

            container.AddFacility(facility);
        }

And resolve cores for querying:

var core = container.Resolve<ISolrOperations<T>>(coreName);

Now I implement next injection:

container.Register(Component.For<ISolrConnection>().ImplementedBy<PostSolrConnection>().DependsOn(new { serverURL=baseHttpUrl}));

But after core resolving in debug Server Connection is SolrConnection and request is GET.
Ask for any help, tnx!


Вівторок, 13 вересня 2011 р. 15:14:46 UTC+3 користувач Mauricio Scheffer написав:

Deren' Andry

unread,
Sep 6, 2012, 9:10:54 AM9/6/12
to sol...@googlegroups.com
Looks like problem is with multi-core model - SolrConnection is registered for each core in Windsor

Mauricio Scheffer

unread,
Sep 6, 2012, 9:12:06 AM9/6/12
to sol...@googlegroups.com
Exactly; you need to register PostSolrConnection for each core.

--
Mauricio



On Thu, Sep 6, 2012 at 10:10 AM, Deren' Andry <dalli...@gmail.com> wrote:
Looks like problem is with multi-core model - SolrConnection is registered for each core in Windsor

--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/duFCD5pWXqkJ.

Deren' Andry

unread,
Sep 6, 2012, 9:39:57 AM9/6/12
to sol...@googlegroups.com
How I can do this? Sorry for noobie questions - generally I dont work with Windsor

Четвер, 6 вересня 2012 р. 16:12:07 UTC+3 користувач Mauricio Scheffer написав:

Mauricio Scheffer

unread,
Sep 6, 2012, 9:42:55 AM9/6/12
to sol...@googlegroups.com
Use named components and service overrides, see  http://docs.castleproject.org/Windsor.Registering-components-one-by-one.ashx#Supplying_the_component_for_a_dependency_to_use_Service_override_9 

I think you can also do it with UsingFactoryMethod accessing the creation context.

--
Mauricio



To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/Ft2_MJG53J8J.

Deren' Andry

unread,
Sep 6, 2012, 9:47:29 AM9/6/12
to sol...@googlegroups.com
Founded in SolrNet source:

private void RegisterCore(SolrCore core) {
            var coreConnectionId = core.Id + typeof (SolrConnection);
            Kernel.Register(Component.For<ISolrConnection>().ImplementedBy<SolrConnection>()
                                .Named(coreConnectionId)
                                .Parameters(Parameter.ForKey("serverURL").Eq(core.Url)));

This is heavy way to register injection, isn't it? ))) Maybe thera are more flexible way for this method?

Четвер, 6 вересня 2012 р. 16:42:58 UTC+3 користувач Mauricio Scheffer написав:

Mauricio Scheffer

unread,
Sep 6, 2012, 10:28:48 AM9/6/12
to sol...@googlegroups.com
There may be other ways to do it, of course, but I can't tell a priori if they're simpler than this or not. How would you suggest we do it?

--
Mauricio

To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/v7Yi5UfEDrMJ.

Deren' Andry

unread,
Sep 6, 2012, 10:46:40 AM9/6/12
to sol...@googlegroups.com
For me I implement generic class with <TConnectin> where TConnection:ISolrConnection. Other variant may be create class for types-config-package and generate SolrNetFacility for it.
There are no warning to implement generic version of SolrNetFacility in next versions - coz simple current implementations can stay for default. Main idea is bring control to end users, SolrNet is very usefull tool, but need more flexibility for some special scenaries.

Четвер, 6 вересня 2012 р. 17:28:49 UTC+3 користувач Mauricio Scheffer написав:

Mauricio Scheffer

unread,
Sep 6, 2012, 11:26:28 AM9/6/12
to sol...@googlegroups.com
I strongly disagree with that design or don't understand the idea. What would you gain from adding a type parameter over the ISolrConnection?
I also disagree about needing more flexibility in this case: SolrNet is designed so that you can easily arrange the components to achieve your goals for special scenarios such as this one. The Windsor facility is just one (the most common one) such arrangement. But it can't be everything for everyone. That's why the general idea of SolrNet is first and foremost to provide small, simple, reusable, composable objects; then these objects are composed to implement various features, all the while maintaining those primitive objects so that other people can easily implement their own features without having to start from scratch.

Cheers
Mauricio


To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/xw20ocW6WZkJ.

Deren' Andry

unread,
Sep 7, 2012, 4:23:18 AM9/7/12
to sol...@googlegroups.com
Mauricio, OK. Provide your own solytion for my problem with Windsor overriding

Четвер, 6 вересня 2012 р. 18:26:29 UTC+3 користувач Mauricio Scheffer написав:

Mauricio Scheffer

unread,
Sep 7, 2012, 12:53:50 PM9/7/12
to sol...@googlegroups.com
Yep, as I said I'd do this by registering PostSolrConnection for each core, using named components and service overrides.
If you're not familiar with Windsor, remember that the underlying concept here is simple: arranging component composition. You don't *need* to use the current SolrNetFacility, you're free to arrange components as you see fit, they're all public. You can even just skip Windsor and compose the components by hand, and then only register ISolrOperations in Windsor.

Cheers
Mauricio


To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/H0lgI0d7_6IJ.

Deren' Andry

unread,
Sep 7, 2012, 3:33:32 PM9/7/12
to sol...@googlegroups.com
Mauticio, with big respect to you but in good-criticizm discussion style few questions:
1. For me SolrNetFacility is best way to configure multi-core mode with WIndows, isn't it? What is it general purpose?
2. Your answer sounds like "go to old good 80th and make all by hand - forget about FWs, enjoy hardcore!". What SolrNet generic purpose is? I see it as good time-save and simple-way tool for SOLR interconection. And I don't want fight with my tools every time. Provided solution isn't simple and clear - own SolrNetFacility<TConnection> looks like more easy way for me.
3. Tnx, for you help and hint about Windsor. I'm familiar with core concepts of DI and can say that Windsor isn't my favorite tool. I'm use Ninject commonly as best and flexible DI for .NET. But there are no way use it in described solution.

Пʼятниця, 7 вересня 2012 р. 19:53:52 UTC+3 користувач Mauricio Scheffer написав:

Deren' Andry

unread,
Sep 7, 2012, 3:38:59 PM9/7/12
to sol...@googlegroups.com
Mauricio, sorry for my syntax errors. There are no edit mode?

Пʼятниця, 7 вересня 2012 р. 22:33:32 UTC+3 користувач Deren' Andry написав:

Mauricio Scheffer

unread,
Sep 8, 2012, 7:55:51 PM9/8/12
to sol...@googlegroups.com
1. No, SolrNetFacility is not the *best* way to configure multi-core. It's just one parametrizable composition of SolrNet objects for the most commonly needed scenarios. But it's not intended to parameterize everything, that would probably make the facility more cumbersome to use than manually composing the objects.
2. It's not true that I said "forget about frameworks", the solution I mentioned involved Windsor's features (namely: named components, service overrides). I additionally suggested manual composition as an alternative since you mentioned you were not familiar with Windsor. And in fact it's not "hardcore" to do the composition "manually", without any IoC containers. It's just a few lines of code.
Once again, the gist of SolrNet is that you can get many features without changing anything when it's only about rearranging the components as in this case. I blogged a bit about this idea in http://bugsquash.blogspot.com.ar/2010/12/customizing-solrnet.html

If you intend to contribute back the solution you propose around SolrNetFacility<TConnection> please explain it in detail, at first blush it doesn't look simple or clear to me. If you don't intend to contribute it back to the project, then of course just write whatever fits your project best, I don't know anything about your project so I can't have any opinions about it :)

Cheers
Mauricio


To view this discussion on the web visit https://groups.google.com/d/msg/solrnet/-/wFzbhWybCq8J.

h jalalifar

unread,
Apr 21, 2015, 5:57:58 AM4/21/15
to sol...@googlegroups.com
post with authentication problem
hi
 i cant use post in solrNet with authentication when i use below code i see authentication problem could you help me?

             var connection = new SolrConnection(solrIp)
                {
                    HttpWebRequestFactory = new SolrAuthentication()
                };

               Startup.Init<solrField>(new PostSolrConnection(connection, solrIp));

 

public class SolrAuthentication : IHttpWebRequestFactory
    {
        public IHttpWebRequest Create(Uri url)
        {
            string userName = System.Configuration.ConfigurationManager.AppSettings["solrUserName"].ToString();
            string password = System.Configuration.ConfigurationManager.AppSettings["solrPass"].ToString();
            HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
            CredentialCache wrCache = new CredentialCache();
            wrCache.Add(url, "Basic", new NetworkCredential(userName,password));
            webrequest.Credentials = wrCache;
            return new HttpWebRequestAdapter((HttpWebRequest)webrequest);
        }
    }
Reply all
Reply to author
Forward
0 new messages