Getting SolrSharp to work

Jan 17, 2008 at 8:43 PM

I had to make a few changes to get this version to work. Here is what I did.
(My server is a Ubuntu 7.10 with SOLR)

// fix 1,. Solr server messed up Danish/Norwegian letters like "æøå" because the HttpWbRequest object wasn't sending in utf-8 to Solr server
Class: SolrSearcher, Method: public static HttpStatusCode WebPost(string url, byte[] bytesToPost, ref string statusDescription)
Changed line:
oRequest.ContentType = "text/xml";
oRequest.ContentType = "text/xml;charset=\"utf-8\"";

// fix 2, Could not get Schema.xml from server.. Permission denied.. or wrong URL.
Class SolrSearcher, Method private void SetSolrPaths()
this.SOLR_CONFIG = this.SOLR + "admin/get-file.jsp?file=solrconfig.xml";
this.SOLR_CONFIG = this.SOLR + "admin/file/?file=solrconfig.xml";

this.SOLR_SCHEMA = this.SOLR + "admin/get-file.jsp?file=schema.xml";
this.SOLR_SCHEMA = this.SOLR + "admin/file/?file=schema.xml";

// fix 3,. Added functionality. My schema had fields with required=false and the validation failed.
// e.g. if (solrService.SolrSchema.IsValidUpdateIndexDocument(iDoc)) // failed //
1) Class: SolrField, Method: public SolrField(XmlNode xnSolrField, SolrSchema solrSchema) At Last line:

this.solrschema = solrschema;

if (xnSolrField.Attributes"required" != null) {
this.required = Convert.ToBoolean(xnSolrField.Attributes"required".Value);
this.solrschema = solrSchema;

2) Added Property/getter in SolrField class
private bool required = false; public bool IsRequired
get { return this.required; }

3) Add check for IsRequired in field loop
Class: SolrSchema, Method: public bool IsValidUpdateIndexDocument(UpdateIndexDocument updateIndexDocument)
public bool IsValidUpdateIndexDocument(UpdateIndexDocument updateIndexDocument)
foreach (SolrField solrField in this.solrFields)
if ((!solrField.IsCopied) &&
(!solrField.IsDefaulted) &&
(!docfieldnames.Contains(solrField.Name) &&
solrField.IsRequired) // ADDED by Peter Thygesen
return false;

// fix 4:
// removed unnecessary namespace declarations in posted xml, (byte waste)
Class: IndexDocument, Method: public string SerializeToString()
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
Add line:
xsn.Add("", "");

Hope someone can use this.. I took me all day to figure out.

Peter Thygesen

Jan 19, 2008 at 3:39 PM
An additional note for readers: the SOLR codebase that Peter is using is a recent snapshot and constitutes many changes that will be released with an announced Solr 1.3 version release.

The released SolrSharp code was verified against the announced Solr 1.2 release.

Thanks to Peter for finding where the differences lie. There may be other changes that have not yet been detected. Please reply to this thread if you find further differences against the current Solr development release.

thygesen wrote:

I had to make a few changes to get this version to work. Here is what I did.
(My server is a Ubuntu 7.10 with SOLR)

Jan 27, 2008 at 2:32 PM
I have now uploaded two patches with minor bugs and "nice to haves" I encountered during my solrsharp research.

hope they can be of some use.
Mar 28, 2008 at 2:14 PM
Had another minor danish letters issue.

When searching for a word containing danish letter "ø" the result was empty. This I knew couldn't be right.

In SolrSearcher.cs method: GetXmlDocumentFromPost I changed the ContentType of the Request object to
oRequest.ContentType = "application/x-www-form-urlencoded;charset=\"utf-8\"";
Here adding utf-8 encoding... And now it works.
I haven't had the time to make a patch for this. Sorry.

Jan 6, 2010 at 7:25 AM

Thanks a lot Peter, you saved lots of time for us.

Jul 16, 2010 at 5:09 PM
Thanks a lot Peter. Your post helped a lot and it was first result in Google about problem with: Solr (1.4.1 version) <ERROR> Permission denied for file schema.xml </ERROR> while getting file: ....get-file.jsp?file=schema.xml from SolrSharp Library Thanks you very much!