Make connection to Solr with PHP

526 views
Skip to first unread message

ProdigyView

unread,
Jun 11, 2012, 12:07:59 PM6/11/12
to PHP Solr Client
I've just installed Solr and I got the default schema working with me.
But when I change the schema from the default to simplier one, I
cannot connect through solr through php but can through tomcat still.
My php code looks like this:



require_once 'Apache/Solr/Service.php';

$solr = new Apache_Solr_Service(
'xxx.xx.xxx.xxx',
8080,
'/dev.example.com/');

if(!$solr->ping()){
echo 'Solr Down';
}


And my schema in solr


<?xml version="1.0" ?>
<schema name="testschema1" version="1.5">
<types>
<fieldtype name="string" class="solr.StrField"
sortMissingLast="true" omitNorms="true"/>
</types>

<fields>
<!-- general -->
<field name="id" type="string" indexed="true" stored="true"
multiValued="false" required="true"/>
<field name="type" type="string" indexed="true" stored="true"
multiValued="false" />
<field name="name" type="string" indexed="true" stored="true"
multiValued="false" />
<field name="core0" type="string" indexed="true" stored="true"
multiValued="false" />
</fields>

<!-- field to use to determine and enforce document uniqueness. -->
<uniqueKey>id</uniqueKey>

<!-- field for the QueryParser to use when an explicit fieldname is
absent -->
<defaultSearchField>name</defaultSearchField>

<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>
</schema>


Also I get this error when I use java -jar start.jr



SEVERE: org.apache.solr.common.SolrException: undefined field text
at
org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:
1330)
at org.apache.solr.schema.IndexSchema
$SolrQueryAnalyzer.getAnalyzer(IndexSchema.java:408)



Just to clarify, it only does not connect from PHP when I change the
schema to the one above, the default schema provided by solr works. Am
I missing some required option?

Donovan Jimenez

unread,
Jun 11, 2012, 12:52:49 PM6/11/12
to php-sol...@googlegroups.com

There shouldn't really be anything special you need to do to get the solr client to connect to your customized solr instance. I use a very modified schema.xml as well. Did you also change handler mapping in solrconfig.xml? Can you run queries from the solr admin interface in the customized instance? If you can't see the admin interface then that's probably a sign there's an error in the schema.xml causing solr not to fully load at all. If you can see it and can run queries successfully, I'd like to see a fuller example of your php code and the actual exception message generated.

Another possible cause: Did you reindex your documents after changing the schema? If you try to query against fields that are no longer defined in your schema but still in your documents, or are defined differently, that can cause problems - but usually not a complete lack of connectivity. 

Donovan


--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To post to this group, send email to php-sol...@googlegroups.com.
To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/php-solr-client?hl=en.


Anthony Wlodarski

unread,
Jun 11, 2012, 3:51:33 PM6/11/12
to php-sol...@googlegroups.com
A quick chime in here on this issue.  I have noticed that if you are using CentOS or RHEL or any system that implements SELinux you will have to give the processes the right permissions.  I sat here for a few hours debugging this exact after moving our servers from Debian to CentOS.  Apache or otherwise known as httpd will be sandboxed.  Change users to root and take a look in /var/log/audid/audit.log  A line similar to this will appear:

type=AVC msg=audit(1338925378.204:2193): avc:  denied  { name_connect } for  pid=20284 comm="httpd" dest=8983 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket"

To confirm even further take a look in "/var/log/messages" for something like "SELinux is preventing xxxxxxxxxxxxxxxxxxx . For complete SELinux messages. run sealert -l 1bfcbb26-c3a7-48b7-993a-b26bcc98b5fa"  Run this command and follow the instructions for how to alleviate the problem.  For solr the resolution is something I followed using the advisories found in the sealert command.

The key is to look for the port that you are using in there, I run on 8983 instead of 8080.  I believe Tomcat is the app container and is the parent thread so SELinux does not block it from accessing it, however not the case for Apache.  To enable access via apache/httpd either turn of SELinux (not recommended) or do the following:

"sudo semanage port -a -t http_port_t -p tcp 8983" (obviously change out your port for the correct one).  This fixed my issue after I began wrapping pings and calls in try/catch blocks and was getting no where.  Also beware, SELinux can compromise your box.  Read the man pages on each of the commands contained in here, otherwise you could invite a whole lot of nastiness onto your machine.

Good luck,
Anthony
Reply all
Reply to author
Forward
0 new messages