Configuring Sphinx to index a dynamic set of tables - mysql

I'm in the process of setting up a new WordPress 3.0 multisite instance and would like to use Sphinx on the database server to power search for the primary website. Ideally, this primary site would offer the ability to search against its content (posts, pages, comments, member profiles, activity updates, etc.) as well as all of the other sites that are a part of the network. Because we'll be adding new sites to the network on a regular basis, I'd like to be able to dynamically add those newly generated tables to the Sphinx .conf file (instead of editing the file and reindexing every time we add a new site).
Unfortunately, MySQL doesn't seem to support wildcards when specifying the table(s) in a query string. The best solution I've come across for grabbing a dynamic set of tables is grepping but I'm pretty certain I don't know how to do this within the .conf file (unless it's possible through magical sorcery).
Is it possible to dynamically specify tables to add to the Sphinx index? Or is this going to cause such performance issues that I'm using the wrong tool?

You could try to dynamically modify the .conf file instead.

You could query from a MySQL view that aggregates the many tables. You'd have to recreate the view with each change to the list of blogs, but I believe that all the hooks exist to support that and it should be easy enough to construct the view query.
The bigger problem may be in trying to find a suitable unique record ID for the posts in Sphinx. It has to be a straight INT, but the post IDs from the different blogs will collide with each other.

I think you can create triggers (INSERT/UPDATE/DELETE) in MySQL on the interested tables (e.g. posts, comments etc) and migrate the data to centralized global tables that are indexed by Sphinx in real time.
The point is how you can create those triggers automatically? Either you can run a cron job to scan for new tables in MySQL, or I believe you can write a simple Wordpress plugin that hook when a blog is activated.

Related

PHP script for front-end management of MySql tables

I'm looking for a PHP script that will allow me to easily manage 'MySql' tables. By managing I mean not their creation but the possibility of adding new records, modifying and deleting them.
It must be possible to specify for each user which tables he will have access to and with which modalities (insertion only, modification only, etc.).
For each user I will also have to specify whether he will be able to see all or some of the columns in the table and with which permissions.
Also I'll need to know who did what, a sort of global change LOG.
My idea was to have a back-end in which I specified the users and how to access the various tables/columns and a front-end for the users.
In the front-end users will be able to add/modify/delete records and data they are allowed and the ability to filter and/or sort the various records.
I know I could use some PHP frameworks or rely on CMS but I have to write a lot of code by hand and it seems hardly credible that such a product is not already available.
Does anyone know if there is something like this?
I had tried starting with PHP frameworks but implementing everything from scratch stopped me.
I expect there is already something available.
Thanks.
Davide.

User-Specific tables on MySQL

i'm starting a project about a social-based application, so i need to track users actions in time. To avoid an Epic-Sized table, i'm thinking about create a table for every single user, and record actions by user.
I've never heard about links of this type (row to table) and i don't know where to find some documentation about this particular argument.
About this, my boss wants to use Drupal for this project, someone have infos about this kind of structure in particular in drupal?
Hmm...maybe you should go for some "lower level" solution instead of Drupal. Drupal is CMS and if you make website Drupal's way you won't have freedom defining your tables the way you like. It's more you have one table defining some common (default) content type fields and for any new you add Drupal actually creates new table so you end up with some complex database structure.
Of course you can manually create your tables and use them also manually instead of using drupal's nodes and views and stuff, but then...what's the point of using Drupal?
So, IMHO some framework or even plain PHP would be more suitable for your project.

Which tables in a Wordpress database need to be edited for migration to a new URL?

I have seen many questions related to database migration, but none which clearly state: When editing a database which of the tables do I actually need to edit?
As a force of habit I edit the entire mySQL database, and usually that works out. (However on occasion this can mess up URL left in user comments for instance.) However it would be good to know specifically which tables I actually need to edit in order to complete a migration correctly.
EDIT: I already understand how a migration works and which tool to use, and I have read the codex entry on migration. I am not having a specific problem migrating.
This is really more of a best practices question.
What I am looking for is a definitive list of what tables I can exclude from my search and replace. For instance I know that the basic URL info is in wp_options, I know that (some) image paths are stored in wp_postmeta. Basically I want to exclude every table I possibly can, while still preserving the site's widgets, images, settings, etc.
The only references that HAVE to change are in the wp_options table. One is the home url and the other is the siteurl. These will allow you to log into the admin and view the frontend. However, you will still have to update your permalinks and rewrite rules using the admin.
I would still suggest an automated solution, however. I use this tool to find and replace database references. It is specifically made for wordpress, but it will work for any database. It also will allow you to select which tables to update and will work with serialized strings so you should be able to avoid errors in the comments section.
Simply drop the file on the root of your wordpress install and run through the prompts. Make sure to deselect the wp_comments and wp_commentmeta tables. Also, make sure you remove the file on production as it presents a potential security threat.
UPDATE BASED ON COMMENTS
Other than the two spots above, there are several places in the database that URLs are stored. Most plugins will store their options in the wp_options table. Typically, plugins will also serialize the data to avoid a ton of queries. You can't simply change the URL in the serialized data however, because there are length references in the serialized string. So if your current URL is 15 characters long and the new one is 20, you need to update the URL and the string length too. If you don't, PHP will just ignore the value. I believe this is a security measure to avoid code injection.
For assets in the media section the URLs are stored in the wp_posts under the post type attachment. If you are hardcoding absolute links in your posts, you may need to parse those as well (if this is the case, you can probably just parse the entire table). If you are using any sort of custom field plugin or doing anything with post meta for URLs you are also going to want to go through wp_postmeta.
One other thing to mention is that some plugins will add their own database tables. These are obviously on a per case basis, but a good rule of thumb is to try running a query for "%http%" in any string columns to see if there are hardcoded URLs. Here is the query I will use:
SELECT * FROM `table` WHERE `column` LIKE '%http%'
Download the file from the following link http://interconnectit.com/products/search-and-replace-for-wordpress-databases/.
Put it in the root folder and access the file and follow the steps and replace the urls.
I have been using it for quite a long time without any issues.
Hope it helps!
Thanks

Add joint primary key to wordpress posts table

I am working out how to synchronize wordpress installations where both can be updated simultaneously, and both can work offline, then come online to sync.
I think the easiest way to sync posts between sites, is to include the site id in the primary key of the posts. Therefore, any post is identified by an incremental id and the id of the server location it was created from.
Is this possible to achieve with a plugin?
What dangers lie ahead if I pursue this path?
Is there a better, alternative way to achieve what I am trying to achieve?
It is possible in several ways:
- Write a stored procedure inside the first Wordpress installation's php files, that inserts the content into the other database when something is written to it. This one probably won't work offline.
- Write a function that compares the two databases at a schedule time using a simple sql query and creates a diff log. Then copies over the difference to the other database.
It depends why you need to do this, but if this works, I would recommend this solution:
- Keep one wordpress installation. Maintain one database, and connect to it from the other website to load the content. You can create your own SQL connection to it and load whatever content you need.
- Keep one wordpress installation, and use it's RSS feed to read the content and display it in whichever second website you need to do it in.
I can't imagine how a plugin would be of much help, especially keeping the databases in sync offline too. In my experience, its usually better to write your custom php scripts, rather than use a plugin so you can have a more direct control over the functionality.
Hope this helps.

Good method for archiving MYSQL table data?

I recently inherited a website and they have a simple back-end area which was created using phpmaker. The back-end displays various MYSQL database tables.
There are two tables which hold registration information related to promotions/contests the company runs online. The client wants to begin archiving the registration data monthly, but still have the data accessible for future export or review.
So, can anyone tell me what the best approach would be to achieve this? I read about partitioning and Maatkit, but I'm not sure which - if either - would be a smart choice.
I would prefer to keep the table names the same because the table name is referenced in several instances within the PHP code running the promo/contest applications. I would also like for everything to be 'automatic' or at least executed at the click of a button; though I realize that might not be completely realistic.
I should note that I do not have the phpmaker project file and have been unable to obtain it.
Any help on this matter would be a great help.
MK-Archiver This is a good way to archive live mysql database tables
What MK- Archiver does is to archive rows from a table to another table and/or a file