Skip to content

Instantly share code, notes, and snippets.

@kevindoran
kevindoran / socketClient.py
Last active December 7, 2021 21:25
A simple Python script to send messages to a sever over Bluetooth using Python sockets (with Python 3.3 or above).
"""
A simple Python script to send messages to a sever over Bluetooth using
Python sockets (with Python 3.3 or above).
"""
import socket
serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
@kevindoran
kevindoran / Search.java
Created February 9, 2013 01:31
SolrJ example
public class SimpleSolrSearch {
private String solrUrl = "http://192.168.1.103:8983/solr/auctions";
private SolrServer server;
public SimpleSolrSearch() {
server = new HttpSolrServer(solrUrl);
}
public Collection<Integer> search(String searchTerms, String category, BigDecimal maxBidAmount) throws SolrServerException {
SolrQuery query = new SolrQuery();
@kevindoran
kevindoran / requestHandler.xml
Last active December 12, 2015 04:18
An example Solr search request handler definition.
<requestHandler name="/broadQuery" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">edismax</str> <!-- The search parser to use. -->
<str name="wt">xml</str> <!-- Output type. -->
<str name="fl">auction_id title</str> <!-- The fields to list in the search response -->
<str name="qf">Title^2 Feature</str> <!-- The fields (and their weightings) to search in.-->
<str name="rows">100</str> <!-- The number of results to return. -->
<str name="pf">Title^4 Feature^2</str> <!-- Phrase field (and their weightings). Fields to search for closely located matches. -->
<str name="ps">0</str> <!-- Phrase slop. How many tokens apart must words be to be able to qualify as a phrase-->
<str name="echoParams">all</str> <!-- Print the search settings in the search results. Just a handy feature -->
@kevindoran
kevindoran / xmlToSolrDoc.xml
Created February 5, 2013 03:49
XSLT file used to convert a XML file to Solr's expected format.
<?xml version="1.0" encoding="UTF-8" ?>
<!-- the 2.0 version of xsl reqires a custom processor to be used. Saxon9he is used, and is
located in Jetty's ext/ folder. This library requires Jetty to be started like so:
java -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl -jar start.jar
-->
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
@kevindoran
kevindoran / comparison.xml
Created February 5, 2013 03:43
Comparison between original and solr format
<!-- original XML format: -->
<auction>
<auction_id>54432834</auction_id>
<title>Dell M2012 24" IPS Monitor</title>
<category>monitors</category>
<current_bid>279.95</current_bid>
</auction>
<!-- The format Solr requires: -->
<doc>
@kevindoran
kevindoran / solrconfigPart.xml
Created February 5, 2013 03:36
XML post request handler in Solr
<!-- in solrconfig.xml -->
<requestHandler name="/update" class="solr.UpdateRequestHandler" />
@kevindoran
kevindoran / schemaPart.xml
Last active December 12, 2015 04:08
Effects of multivalued fields in Solr
<!-- What an auction might look like in its original XML form: -->
<auction>
<title>Desktop PC</title>
<feature>
<name>RAM</name>
<value>16 GB</value>
</feature>
<feature>
<name>CPU Frequency</name>
<value>4.5 GHz</value>
@kevindoran
kevindoran / schemaPart.xml
Created February 5, 2013 02:37
The default text_en fieldType.
<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
@kevindoran
kevindoran / schema.xml
Created February 5, 2013 02:16
Example of copy and dynamic fields in Solr schema
<schema name="example" version="1.5">
<fields>
<field name="title" type="text_en" indexed="true" stored="true" required="true" multiValued="false" />
<field name="category" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="feature" type="string" indexed="true" stored="true" required="false" multiValued="true" />
<field name="allText" type="text_en" indexed="true" stored="false" required="true" multiValued="true" />
</fields>
<copyField source="title" dest="allText" />
<copyField source="category" dest="allText" />
@kevindoran
kevindoran / schema.xml
Created February 5, 2013 01:36
Example Solr schema.
<schema name="example" version="1.5">
<fields>
<field name="_version_" type="long" indexed="true" stored="true" required="true"/>
<field name="auction_id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="title" type="text_en" indexed="true" stored="true" required="true" multiValued="false" />
<field name="category" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="current_bid" type="currency" indexed="true" stored="true" required="true" multiValued="false" />
<field name="end_date" type="date" indexed="true" stored="true" required="true" multiValued="false" />
<field name="feature" type="string" indexed="true" stored="true" required="false" multiValued="true" />
</fields>