Skip to content

Instantly share code, notes, and snippets.

View vthacker's full-sized avatar

Varun Thacker vthacker

  • Slack
  • San Francisco
View GitHub Profile
@vthacker
vthacker / gist:4705144
Created February 4, 2013 05:15
Word Delimiter Token Filter
curl -XPUT localhost:9200/test -d '{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1,
"analysis": {
"filter": {"myWordDelimiter": {"type": "word_delimiter"}},
"analyzer" : {
"myAnalyzer" : {
"type": "custom",
"tokenizer": "whitespace",
@vthacker
vthacker / gist:5874727
Created June 27, 2013 07:59
Example Lucene Indexing and Searching
/** Indexing part **/
Map<String,Analyzer> analyzerPerField = new HashMap<String,Analyzer>();
analyzerPerField.put("state", new StandardAnalyzer(Version.LUCENE_50));
analyzerPerField.put("region", new StandardAnalyzer(Version.LUCENE_50));
PerFieldAnalyzerWrapper aWrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Version.LUCENE_50), analyzerPerField); //This is the part where after basic setup enhancements should be made
IndexWriter iw;
Directory dir = new MMapDirectory(new File("/tmp/lucene"));
IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_50, aWrapper);
@vthacker
vthacker / gist:6535332
Created September 12, 2013 10:08
Perculator
package com.varun.perculator;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.SimpleAnalyzer;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.memory.MemoryIndex;
import org.apache.lucene.queryparser.classic.ParseException;
@vthacker
vthacker / gist:7245778
Last active December 27, 2015 01:29
ConstantSimilarity
poublic class ConstantSimilarity extends DefaultSimilarity {
@Override
public float tf(float freq) {
return 1;
}
@Override
public float idf(long docFreq, long numDocs) {
return 1.0f;
}
@Override public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics[] stats) {
@vthacker
vthacker / gist:8800846
Created February 4, 2014 09:52
Multiple Facets
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"facet":"true",
"indent":"true",
"q":"*:*",
"facet.limit":"1",
"facet.field":["name",
@vthacker
vthacker / examples
Created February 26, 2014 20:12
JSON Examples
curl http://localhost:8983/solr/update -H 'Content-type:application/json' -d '
[
{
"id": "1",
"title": "Doc 1"
},
{
"id": "2",
"title": "Doc 2"
}
@vthacker
vthacker / gist:9270623
Created February 28, 2014 12:59
JSON Block Join Example
{
"add": [
{
"id": "1",
"title": "Solr adds block join support",
"content_type": "parentDocument",
"_childDocuments_": [
{
"id": "2",
"comments": "SolrCloud supports it too!"
@vthacker
vthacker / firstCall
Last active August 29, 2015 13:57
Timeout Exception
SourceOptions
XPath/RenderXSL
<response>
<lst name="responseHeader">
<int name="status">500</int>
<int name="QTime">571882</int>
</lst>
<lst name="error">
<str name="msg">KeeperErrorCode = Session expired for /overseer/collection-queue-work/qnr-0000000106</str>
<str name="trace">org.apache.zookeeper.KeeperException$SessionExpiredException: KeeperErrorCode = Session expired for /overseer/collection-queue-work/qnr-0000000106 at org.apache.zookeeper.KeeperException.create(KeeperException.java:127) at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:1155) at org.apache.solr.common.cloud.SolrZkClient$7.execute(SolrZkClient.java:276) at org.apache.solr.common.cloud.SolrZkClient$7.execute(SolrZkClient.java:273) at org.apache.solr.common.cloud.ZkCmdExecutor.retryOperation(ZkCmdExecutor.java:73) at org.apache.solr.common.cloud.SolrZkClient.getData(SolrZkClient.java:273) at org.apache.solr.cloud.DistributedQueue.offer(DistributedQueue.java:313
@vthacker
vthacker / NO_COMPOUND_FILES
Created April 29, 2014 12:00
No Compound Files
-rw-r--r-- 1 varun wheel 162B Apr 29 17:29 _0.cfe
-rw-r--r-- 1 varun wheel 328B Apr 29 17:29 _0.cfs
-rw-r--r-- 1 varun wheel 259B Apr 29 17:29 _0.si
-rw-r--r-- 1 varun wheel 162B Apr 29 17:29 _1.cfe
-rw-r--r-- 1 varun wheel 1.7M Apr 29 17:29 _1.cfs
-rw-r--r-- 1 varun wheel 259B Apr 29 17:29 _1.si
-rw-r--r-- 1 varun wheel 162B Apr 29 17:29 _2.cfe
-rw-r--r-- 1 varun wheel 1.7M Apr 29 17:29 _2.cfs
-rw-r--r-- 1 varun wheel 259B Apr 29 17:29 _2.si
-rw-r--r-- 1 varun wheel 162B Apr 29 17:29 _3.cfe
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CoreAdminParams;
import java.net.MalformedURLException;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;