Skip to content

Instantly share code, notes, and snippets.

View gibrown's full-sized avatar

Greg Ichneumon Brown gibrown

View GitHub Profile
<?php
/**
* VIPs need some special vetting as they can have custom code in the functions.php
* to setup custom taxonomies / post types and the like.
*
* We need to load the functions.php file for these themes.
*
* An other problem is that things which are usually attached to early hooks such as init or after_theme_setup
* in order to register custom taxonomies or post types are not working as the init hook already fired off when the jobs action is executed.
* So we copy all functions attached to the hooks we need ( currently after_theme_setup, init ) to an other hook and fire it off
@gibrown
gibrown / gist:7122061
Created October 23, 2013 16:38
ES lang detect API text cleaning code.
//if we can't tell the lang with 5000 characters we probably can't tell the language
$text = mb_substr( $text, 0, 5000 );
//replace non-breaking spaces so they don't match the \p{L} char class
$text = preg_replace( '/[\x{00A0}\x{2007}\x{202F}]/u', ' ', $text );
//replace unicode symbols: see: http://www.utf8-chartable.de/unicode-utf8-table.pl
$text = preg_replace( '/[\x{2000}-\x{2BFF}]/u', ' ', $text ); //symbols
$text = preg_replace( '/[\x{1f000}-\x{1ffff}]/u', ' ', $text ); //symbols, emoticons
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 422,
@gibrown
gibrown / gist:5577521
Created May 14, 2013 16:53
Modifications for our main app of es-backbone.js between 0.1 and 0.2 of the es-backbone.js lib. I haven't had time to update the sample code in the lib, so hopefully this diff of our application helps show how to use what has changed.
Index: wpes-mgs-p2.css
===================================================================
--- wpes-mgs-p2.css (revision 53507)
+++ wpes-mgs-p2.css (working copy)
@@ -13,7 +13,6 @@
div#wpes-p2-header {
border-bottom: 1px solid #ccc;
- padding: 20px 30px;
}
@gibrown
gibrown / gist:4323746
Created December 18, 2012 00:23
ES fails when match_all filter uses an empty array with a faceted search.
SERVER="http://localhost:9200"
curl -XPUT "$SERVER/bugs/page/8872248-p-145" -d '{"id":145,"url":"http://alexsandbox.wordpress.com/header-test/","date":"2010-02-06 05:23:27","date_gmt":"2010-02-06 05:23:27","author":"Alex Mills","author_login":"viper007bond","title":"Header Test","content":"asdfasd as sad f","category":"Uncategorized","meta":{"_edit_lock":["1337928058:50392"],"_edit_last":["50392"],"_thumbnail_id":["147"]},"meta_raw":{"_edit_lock":["1337928058:50392"],"_edit_last":["50392"],"_thumbnail_id":["147"]}}'
curl -XGET "$SERVER/bugs/_search?pretty" -d '
{
"query":{"filtered":{"query":{"multi_match":{"query":"automattic","fields":["title","content"]}},"filter":{"match_all":{}}}},
"facets" : {
"tag" : {
"terms" : {
@gibrown
gibrown / gist:1586723
Created January 10, 2012 03:32
Profiling queries for building word clouds
#word histogram query - docs for separate ids in separate types
curl -XGET "${SERVER}/pd-0/${ID}/_search?pretty" \
-d '{
"size" : 0,
"query" : { "match_all" : { } },
"facets" : {
"q1" : {
"terms" : {
"field" : "q1",
"size" : 100
@gibrown
gibrown / gist:1571828
Created January 6, 2012 18:37
ElasticSearch server state after adding 10's of thousands of types.
Cluster Health:
{
"cluster_name" : "es_cluster_dev",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 15,
"active_shards" : 15,
"relocating_shards" : 0,