Skip to content

Instantly share code, notes, and snippets.

View maephisto's full-sized avatar

Marius Mischie maephisto

View GitHub Profile
@maephisto
maephisto / PayloadQParserPlugin.java
Last active November 24, 2016 12:56
Simple Payload Query Parser (Solr/Lucene)
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadTermQuery;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
@maephisto
maephisto / CustomSolrSimilarity.java
Last active January 3, 2016 07:59
Simple Custom Similarity for Payloads (Solr/Lucene)
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.util.BytesRef;
public class CustomSolrSimilarity extends DefaultSimilarity {
@Override
public float scorePayload(int doc, int start, int end, BytesRef payload) {
if (payload != null) {
return PayloadHelper.decodeFloat(payload.bytes);;
@maephisto
maephisto / schema.xml
Last active January 3, 2016 07:59
Changes that need to be made to schema.xml
<similarity class="com.custom.solr.CustomSolrSimilarity" />
@maephisto
maephisto / solrconfig.xml
Last active January 3, 2016 07:59
Changes that need to be made to solrconfig.xml
<lib path="../../lib/solr-payloads-plugin.jar"/>
<!-- Request Handler to do payload queries -->
<queryParser name="payloadQueryParser" class="com.custom.solr.PayloadQParserPlugin"/>
<requestHandler name="/pds-search" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">payloadQueryParser</str>
</lst>
</requestHandler>
@maephisto
maephisto / response.json
Created January 15, 2014 09:56
Solr response for http://localhost:8983/solr/collection1/pds-search?q=payloads:testone&wt=json&indent=true&debugQuery=true
{
"responseHeader":{
"status":0,
"QTime":2},
"response":{"numFound":4,"start":0,"docs":[
{
"id":"1",
"title":["Doc one"],
"payloads":"testone|10.4 testtwo|30.2 testthree|5.6",
"_version_":1457289004134170624},
@maephisto
maephisto / documents.xml
Created January 15, 2014 10:02
documents added
<add>
<doc>
<field name="id">1</field>
<field name="title">Doc one</field>
<field name="payloads">testone|10.4 testtwo|30.2 testthree|5.6</field>
<field name="text">I testone, you testtwo, they testthree</field>
</doc>
<doc>
<field name="id">2</field>
<field name="title">Doc two</field>
@maephisto
maephisto / Javascript ISO country code to country name conversion
Last active August 15, 2024 03:08
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
@maephisto
maephisto / get languages spoken in a certain country (by country code)
Created February 28, 2014 14:38
This gist shows how to get languages spoken in a certain country (by country code)
var countryToLanguages = { AD: [ 'ca' ],
AE: [ 'ar', 'fa', 'en', 'hi', 'ur' ],
AF: [ 'fa', 'ps', 'uz', 'tk' ],
AG: [ 'en' ],
AI: [ 'en' ],
AL: [ 'sq', 'el' ],
AM: [ 'hy' ],
AO: [ 'pt' ],
AR: [ 'es', 'en', 'it', 'de', 'fr', 'gn' ],
AS: [ 'en', 'sm', 'to' ],
@maephisto
maephisto / AWS base64 image upload
Created June 16, 2014 11:30
Node upload base64 image data to AWS
var config = {
"aws" : {
"bucket": "...",
"domain" : "...",
"prefix" : "..",
"path": "my/test/",
"credentials" : {
"accessKeyId": "...",
"secretAccessKey": "..."
}
@maephisto
maephisto / solution.js
Created January 29, 2015 21:03
Trello Javascript challenge solution
// what we're working with
var characterList = 'acdegilmnoprstuw';
// what we're going for
var theHashWeWereLookingFor = 956446786872726;
var theMagicString = '';
//Now reverse engineer
while (theHashWeWereLookingFor > 7 ) {
var counter = 0;