1

I am using Apache Solr in a Drupal 6.22 website. The version of Solr is 3.6.2 and using apachesolr-6.x-1.8 module with it. Solr indexed all the node based contents well. But I want to have a custom table indexed. This table shows some promotional data to the website and has ~531,067 data. The schema is below,


+-------------+--------------+------+-----+-------------------+----------------+
| Field       | Type         | Null | Key | Default           | Extra          |
+-------------+--------------+------+-----+-------------------+----------------+
| topic_id    | int(11)      | NO   | PRI | NULL              | auto_increment |
| subject_id  | int(11)      | NO   | MUL | NULL              |                |
| title       | varchar(255) | NO   |     | NULL              |                |
| created     | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
| reply_count | int(11)      | NO   |     | NULL              |                |
| view_count  | int(11)      | NO   |     | NULL              |                |
+-------------+--------------+------+-----+-------------------+----------------+


How can I index that table in Solr and how can I add the schemas to schema.xml in Solr? As I have seen the HOOKS in Exposed Solr Hooks (6.x-1.x) for developers, and it seems that using hook_apachesolr_update_index(&$document, $node) will do the trick but I want to be sure on this.

Please provide me some idea on this. Thanks in advance.

2 Answers 2

1

I believe this issue has the information your looking for you have to modify the ApacheSolr schema file to include your custom fields. And tell Solr with an update hook where your data is .... importing that much data could be difficult.

An even better resource may be this blog post from Acquia: Using Apache Solr to Index Custom Data.

Sorry, I wont be able to code up any examples. I dont have Solr installed now, and dont have that much free time.

Both these example links are for D6.

3
  • thanks for your information. But I was actually looking for a code snippet. Commented Jun 14, 2013 at 16:19
  • well -- there is no code snippet for your custom data. you have to use the update_index hook and tell drupal of your custom data like Acquia did. And you may need to alter schema.xml for Solr by hand .... why? because their not Drupal tables, their custom tables. This is the price you pay for using non-drupal (table) data. Anyways, hope the docs I supplied help. I cant write you the code without installing everything you're talking about ... :/
    – tenken
    Commented Jun 14, 2013 at 17:38
  • thanks, I checked the acquia's link a time ago. I think I have to change the schema.xml and also create a custom table to store the indexing information as the main module does. Thanks for your thoughts. Commented Jun 14, 2013 at 17:59
0

In D6 you will need to register your custom data as a new node type hook_node_info() and supply at least a hook_form(). After a clear cache you should see the custom node type listed in the content types list.

From there you should be able to use hook_apachesolr_update_index() to add in the non-standard node fields to the index.

3
  • Why would he use a Drupal node hook to inject custom (non-drupal) database tables into Solr.
    – tenken
    Commented Jun 13, 2013 at 22:36
  • Drupal needs to know about the table, treating the data as a custom node type will allow the table to be indexed. Without doing this then the table data will never get passed to hook_apachesolr_update_index(). Commented Jun 13, 2013 at 22:46
  • I can't add those custom table contents to Node, if I could I would have done that. There are many nodes in the website. And this data I am talking about is getting increased each day. So importing 5 million data to node seems to be impossible Commented Jun 14, 2013 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.