Skip to content

Instantly share code, notes, and snippets.

View gibrown's full-sized avatar

Greg Ichneumon Brown gibrown

View GitHub Profile
@gibrown
gibrown / gist:9419022
Created March 7, 2014 20:11
WP.com related posts query building
public static function post( $blog_id, $post_id, $mlt_fields = array( 'mlt_content' ), $analyzer = false ) {
switch_to_blog( $blog_id );
$post = get_post( $post_id );
$fld_bldr = new ES_WP_Field_Builder();
$tax_data = $fld_bldr->taxonomy( $post );
$mlt_content = $fld_bldr->mlt_content( array(
'title' => $fld_bldr->clean_string( $post->post_title ),
'content' => $fld_bldr->clean_string( $post->post_content ),
@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,
@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
diff --git a/src/common/class.wpes-analyzer-builder.php b/src/common/class.wpes-analyzer-builder.php
index 0357ea4..5787479 100644
--- a/src/common/class.wpes-analyzer-builder.php
+++ b/src/common/class.wpes-analyzer-builder.php
@@ -340,6 +340,29 @@ class WPES_Analyzer_Builder {
continue;
}
+ if ( 'de' == $lang ) {
+ ////From: http://gibrown.wordpress.com/2013/05/01/three-principles-for-multilingal-indexing-in-elasticsearch/#comment-857
@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: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;
}
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 422,
@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
<?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
Մեր հÕ րևÕ Õ բÕ կում երկու եղբÕ յր Õ Õ Õ Õ պրում ՄÕ օր եղբÕ յրÕ երը որոÕ եցÕ Õ բÕ րձրÕ Õ Õ լ Õ րեÕ ց Õ Õ Õ Õ Õ Õ Õ քը ՔÕ Õ եցÕ Õ բերեցÕ Õ ծÕ Õ ր սÕ Õ դուղքը ու բÕ րձրÕ ցÕ Õ մութ Õ Õ Õ Õ քը Փոքր եղբÕ յրը Õ Õ Õ վÕ խկոÕ Õ ր Õ սկ մեծ եղբÕ յրը Õ Õ ըÕ դհÕ Õ Õ րÕ Õ հÕ մոզում Õ ր որ Õ մեÕ Õ Õ չ լÕ վ կլÕ Õ Õ որ չվÕ խեÕ Õ ՀÕ զÕ վ Õ Õ Õ բÕ րձրÕ ցել վերև երբ փոքր եղբÕ յրը չÕ կÕ Õ եց գեÕ Õ Õ Õ դրվÕ ծ Õ Õ խÕ Õ կÕ երը ոÕ քով դÕ պÕ վ դրÕ Õ ց ու վÕ յր ըÕ կÕ վ ՔÕ Õ Õ որ փոքր Õ ր Õ սկույÕ սկսեց լÕ ց լÕ Õ ել Õ սկ մեծ եղբÕ յրը Õ րÕ Õ հÕ Õ գսÕ Õ ցրեց Õ սելով որ դÕ կլÕ Õ Õ Õ րեÕ ց գÕ ղÕ Õ Õ քը և ոչ ոք Õ յդ մÕ սÕ Õ չÕ Õ մÕ Õ Õ
WordPress.com Debug
11:42 AM (32 minutes ago)
to greg
Text: