Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

  • Loading branch information...
commit d858038603f6fd5096346b3db97384ac0ddcdd4c 1 parent cc8a9bf
@javasoze javasoze authored
View
85 .classpath
@@ -1,32 +1,55 @@
-<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="test/src"/>
- <classpathentry exported="true" kind="lib" path="lib/master/commons-logging.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/fastutil.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/kamikaze-2.0.0.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/log4j.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/lucene-core.jar" sourcepath="/Users/john/.m2/repository/org/apache/lucene/lucene-core/3.0.2/lucene-core-3.0.2-sources.jar"/>
- <classpathentry kind="lib" path="lib/master/netty-3.2.3.Final.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/protobuf-java.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/master/spring.jar"/>
- <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="lib/master/norbert-cluster-2.8.0-0.5.1.jar"/>
- <classpathentry kind="lib" path="lib/master/norbert-java-cluster-2.8.0-0.5.1.jar"/>
- <classpathentry kind="lib" path="lib/master/norbert-java-network-2.8.0-0.5.1.jar"/>
- <classpathentry kind="lib" path="lib/master/norbert-network-2.8.0-0.5.1.jar"/>
- <classpathentry kind="lib" path="lib/master/scala-library-2.8.0.jar"/>
- <classpathentry kind="lib" path="lib/master/commons-configuration.jar"/>
- <classpathentry kind="lib" path="lib/master/servlet-api.jar"/>
- <classpathentry kind="lib" path="lib/master/zookeeper.jar"/>
- <classpathentry kind="lib" path="lib/master/commons-codec.jar"/>
- <classpathentry kind="lib" path="lib/master/commons-lang.jar"/>
- <classpathentry kind="lib" path="lib/master/json.jar"/>
- <classpathentry kind="lib" path="lib/master/commons-collections.jar"/>
- <classpathentry kind="lib" path="lib/master/kafka-0.05.jar"/>
- <classpathentry kind="lib" path="lib/master/bobo-browse-2.5.0.jar"/>
- <classpathentry kind="lib" path="lib/master/zoie-2.5.0.jar"/>
- <classpathentry kind="lib" path="lib/master/avro.jar"/>
- <classpathentry kind="output" path="output"/>
-</classpath>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
+ <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.1/ant-1.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.1/ant-launcher-1.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/asm/asm/3.2/asm-3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/avro/avro/1.4.0/avro-1.4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/bobo/bobo-browse/2.5.1-SNAPSHOT/bobo-browse-2.5.1-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar" sourcepath="M2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-beanutils/commons-beanutils-core/1.8.0/commons-beanutils-core-1.8.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-configuration/commons-configuration/1.6/commons-configuration-1.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-digester/commons-digester/1.8/commons-digester-1.8.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.5/commons-lang-2.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/fastutil/fastutil/5.0.5/fastutil-5.0.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-core-asl/1.4.2/jackson-core-asl-1.4.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/jackson/jackson-mapper-asl/1.4.2/jackson-mapper-asl-1.4.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty/6.1.22/jetty-6.1.22.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-util/6.1.22/jetty-util-6.1.22.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/json/json/20080701/json-20080701.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.5/junit-4.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/kafka/kafka/0.0.6-SNAPSHOT/kafka-0.0.6-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/kamikaze/kamikaze/3.0.3/kamikaze-3.0.3.jar" sourcepath="M2_REPO/com/sna-projects/kamikaze/kamikaze/3.0.3/kamikaze-3.0.3-sources.jar">
+ <attributes>
+ <attribute value="jar:file:/Users/john/.m2/repository/com/sna-projects/kamikaze/kamikaze/3.0.3/kamikaze-3.0.3-javadoc.jar!/" name="javadoc_location"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.15/log4j-1.2.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/2.9.1/lucene-core-2.9.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/netty/netty/3.2.3.Final/netty-3.2.3.Final.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/norbert/norbert-cluster/1.0.0-SNAPSHOT/norbert-cluster-1.0.0-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/norbert/norbert-java-cluster/1.0.0-SNAPSHOT/norbert-java-cluster-1.0.0-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/norbert/norbert-java-network/1.0.0-SNAPSHOT/norbert-java-network-1.0.0-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/norbert/norbert-network/1.0.0-SNAPSHOT/norbert-network-1.0.0-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/oro/oro/2.0.8/oro-2.0.8.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/paranamer/paranamer/2.2/paranamer-2.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/paranamer/paranamer-ant/2.2/paranamer-ant-2.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/paranamer/paranamer-generator/2.2/paranamer-generator-2.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/google/protobuf/protobuf-java/2.3.0/protobuf-java-2.3.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/qdox/qdox/1.10.1/qdox-1.10.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/scala-lang/scala-library/2.8.0/scala-library-2.8.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring/2.5.6/spring-2.5.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity/1.6.4/velocity-1.6.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/sna-projects/zoie/zoie-core/2.5.1-SNAPSHOT/zoie-core-2.5.1-SNAPSHOT.jar" sourcepath="M2_REPO/com/sna-projects/zoie/zoie-core/2.5.1-SNAPSHOT/zoie-core-2.5.1-SNAPSHOT-sources.jar">
+ <attributes>
+ <attribute value="jar:file:/Users/john/.m2/repository/com/sna-projects/zoie/zoie-core/2.5.1-SNAPSHOT/zoie-core-2.5.1-SNAPSHOT-javadoc.jar!/" name="javadoc_location"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+</classpath>
View
28 .project
@@ -1,17 +1,13 @@
-<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>sensei</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+ <name>sensei</name>
+ <comment>sensei search. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
30 .settings/org.eclipse.jdt.core.prefs
@@ -1,22 +1,26 @@
-#Mon Nov 29 15:42:07 PST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.codeComplete.argumentPrefixes=
-org.eclipse.jdt.core.codeComplete.argumentSuffixes=
-org.eclipse.jdt.core.codeComplete.fieldPrefixes=_
+#Sat Mar 05 13:33:10 PST 2011
org.eclipse.jdt.core.codeComplete.fieldSuffixes=
-org.eclipse.jdt.core.codeComplete.localPrefixes=
org.eclipse.jdt.core.codeComplete.localSuffixes=
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.codeComplete.localPrefixes=
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
-org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
+eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
-org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.codeComplete.fieldPrefixes=_
+org.eclipse.jdt.core.codeComplete.argumentSuffixes=
+org.eclipse.jdt.core.codeComplete.argumentPrefixes=
+encoding//src/main/java=UTF-8
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
+encoding//src/main/resources=UTF-8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.source=1.6
View
4 bin/sensei-client.sh
@@ -3,8 +3,8 @@
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
-lib=$bin/../lib/master
-dist=$bin/../dist
+lib=$bin/../lib
+dist=$bin/../target
resources=$bin/../resources
# HEAP_OPTS="-Xmx4096m -Xms2048m -XX:NewSize=1024m" # -d64 for 64-bit awesomeness
View
2  bin/update-protobuf.sh
@@ -4,4 +4,4 @@ bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
cd $bin/..
-protoc --java_out=src protobuf/*.proto
+protoc --java_out=src/main/java protobuf/*.proto
View
34 pom.xml
@@ -82,6 +82,34 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.26</version>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <webAppConfig>
+ <contextPath>/</contextPath>
+ </webAppConfig>
+ <scanTargetPatterns>
+ <scanTargetPattern>
+ <directory>src/main/webapp/WEB-INF</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </scanTargetPattern>
+ </scanTargetPatterns>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.13</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
+ </plugin>
+
</plugins>
</build>
@@ -211,6 +239,12 @@
<version>2.5</version>
<scope>compile</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>3.3.3</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
View
2  resources/log4j.properties
@@ -1,4 +1,4 @@
-log4j.rootLogger=INFO, sensei
+log4j.rootLogger=INFO, console1
log4j.appender.console1=org.apache.log4j.ConsoleAppender
log4j.appender.console1.layout=org.apache.log4j.PatternLayout
View
4 src/main/webapp/WEB-INF/conf/sensei-client.conf
@@ -0,0 +1,4 @@
+#cluster props
+sensei.search.cluster.name = sensei
+sensei.search.cluster.zookeeper.url = localhost:2181
+sensei.search.cluster.zookeeper.conn.timeout = 30000
View
41 src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+ <display-name>Sensei Search Client</display-name>
+ <description></description>
+
+ <context-param>
+ <param-name>config.file</param-name>
+ <param-value>src/main/webapp/WEB-INF/conf/sensei-client.conf</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>com.sensei.search.client.servlet.SenseiConfigServletContextListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>SenseiSearchServlet</servlet-name>
+ <servlet-class>com.sensei.search.client.servlet.DefaultSenseiJSONServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>senseiSpringRPCExporter</servlet-name>
+ <servlet-class>com.sensei.search.client.servlet.SenseiHttpInvokerServiceServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>senseiSpringRPCExporter</servlet-name>
+ <url-pattern>/sensei-rpc/SenseiSpringRPCService</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>SenseiSearchServlet</servlet-name>
+ <url-pattern>/sensei/*</url-pattern>
+ </servlet-mapping>
+</web-app>
View
110 src/main/webapp/css/main.css
@@ -0,0 +1,110 @@
+a {
+ cursor: pointer;
+}
+
+a:hover {
+ font-size: 18px;
+ font-weight: bold;
+}
+
+#tags a:hover {
+ font-size: 32px;
+}
+
+#tags .ROWHEAD a:hover {
+ font-size: 18px;
+}
+
+.selected {
+ color: blue !important;
+ cursor: default !important;
+ font-size: 16px !important;
+ font-weight: normal !important;
+}
+
+#hits td {
+ text-align: center;
+}
+
+.tag8 {
+ font-family: Arial;
+ font-size: 12px;
+}
+.tag7 {
+ font-family: Arial;
+ font-size: 14px;
+}
+.tag5 {
+ font-family: Arial;
+ font-size: 16px;
+}
+.tag10 {
+ font-family: Arial;
+ font-size: 18px;
+}
+.tag3 {
+ font-family: Arial;
+ font-size: 20px;
+}
+.tag6 {
+ font-family: Arial;
+ font-size: 22px;
+}
+.tag2 {
+ font-family: Arial;
+ font-size: 24px;
+}
+.tag1 {
+ font-family: Arial;
+ font-size: 26px;
+}
+.tag9 {
+ font-family: Arial;
+ font-size: 28px;
+}
+.tag4 {
+ font-family: Arial;
+ font-size: 30px;
+}
+.BREADCRUMB {
+ color: blue;
+ font-weight: normal;
+}
+.ROWHEAD {
+ background-color: #AAAAEF;
+}
+.LINKSELECTED {
+ color: blue;
+ font-size: 15px;
+ font-weight: bold;
+}
+.hitstat {
+ color: #8888EF;
+ font-family: Arial;
+}
+.scroll {
+ color: black;
+ font-size: 12px;
+}
+.sortable {
+ color: black;
+ text-decoration: underline;
+}
+#resultset a {
+ color: blue;
+ text-decoration: underline;
+}
+body {
+ font-family: Arial;
+}
+.SELECTELEM {
+ font-size: 12px;
+ text-align: left;
+}
+.SELECTELEM li {
+ list-style-type: none;
+}
+.text {
+ font-size: 12px;
+}
+
View
461 src/main/webapp/demo.html
@@ -0,0 +1,461 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
+<head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
+ <link rel="stylesheet" type="text/css" href="css/main.css" />
+ <script type="text/javascript" src="js/sensei-client.js"></script>
+ <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
+ <script type="text/javascript">
+ // <![CDATA[
+ var r = "";
+
+ var senseiClient = null;
+
+ var renderStatus = function (obj) {
+ if (!obj) return;
+
+ $('#hitcount').text(""+obj.numhits+" out of "+obj.totaldocs+" ("+obj.time*1.0/1000+" seconds)");
+ };
+
+ var renderPath = function (field, objs) {
+ if (!objs) return;
+ var headContainer = $('#'+field+' .ROWHEAD span').empty();
+
+ var div = $('#'+field).get(0);
+ var vals = [];
+ if (div.sensei_selections.length != 0) {
+ var val = div.sensei_selections[0].values;
+ var _vals = val.split('/');
+ for (var i=0; i<_vals.length; ++i) {
+ if (_vals[i] != '') {
+ vals.push([_vals[i]]);
+ var v = [];
+ for (var j=0; j<vals.length; ++j) {
+ v.push(vals[j][0]);
+ }
+ vals[vals.length-1].push(v.join('/'));
+ }
+ }
+ }
+ vals = [['All', '']].concat(vals);
+ for (var i=0; i<vals.length; ++i) {
+ headContainer.append('<a />').find('a:last')
+ .text(vals[i][0])
+ .click(function (e) {
+ if (div.sensei_selections.length == 0) {
+ div.sensei_selections.push(new SenseiSelection(field, this.value));
+ senseiClient.addSelection(div.sensei_selections[0]);
+ }
+ else {
+ div.sensei_selections[0].values = this.value;
+ }
+ refreshPage();
+ }).get(0).value = vals[i][1];
+ headContainer.append('/');
+ }
+
+ var container = $('#'+field+' table table tr').empty();
+ for (var i=0; i<objs.length; ++i) {
+ var obj = objs[i];
+ if (obj.selected)
+ continue;
+
+ var _v = obj.value.split('/');
+ var v = _v.pop();
+ while (v=='' && _v.length)
+ v = _v.pop();
+ container.append('<td />').find('td:last')
+ .append('<a />').find('a:last')
+ .text(v+' ('+obj.count+')')
+ .click(function (e) {
+ if (div.sensei_selections.length == 0) {
+ div.sensei_selections.push(new SenseiSelection(field, this.value));
+ senseiClient.addSelection(div.sensei_selections[0]);
+ }
+ else {
+ div.sensei_selections[0].values = this.value;
+ }
+ refreshPage();
+ }).get(0).value = obj.value;
+ }
+ };
+
+ var renderTags = function (objs) {
+ if (!objs) return;
+ var headContainer = $('#tags .ROWHEAD span').empty();
+
+ var div = $('#tags').get(0);
+
+ var container = $('#tags table td:last').empty();
+ for (var i=0; i<objs.length; ++i) {
+ var obj = objs[i];
+ if (obj.selected) {
+ if (headContainer.text()) headContainer.append(', ');
+ headContainer.append('<a />').find('a:last')
+ .text(obj.value)
+ .click(function (e) {
+ var a = div.sensei_selections[0].values.split(',');
+ var b = [];
+ for (var j=0; j<a.length; ++j) {
+ if (a[j] != this.value) b.push(a[j]);
+ }
+ div.sensei_selections[0].values = b.join(',');
+ if (div.sensei_selections[0].values == '') {
+ senseiClient.removeSelection(div.sensei_selections[0]);
+ div.sensei_selections.splice(0, div.sensei_selections.length);
+ }
+ refreshPage();
+ }).get(0).value = obj.value;
+ }
+ else {
+ if (container.text()) container.append(' ');
+ container.append('<a />').find('a:last')
+ .text(obj.value)
+ .addClass('tag'+i)
+ .click(function (e) {
+ if (div.sensei_selections.length == 0) {
+ div.sensei_selections.push(new SenseiSelection('tags', this.value,
+ '', SenseiSelection.prototype.Operation.AND));
+ senseiClient.addSelection(div.sensei_selections[0]);
+ }
+ else {
+ var a = div.sensei_selections[0].values.split(',');
+ a.push(this.value);
+ div.sensei_selections[0].values = a.join(',');
+ }
+ refreshPage();
+ }).get(0).value = obj.value;
+ }
+ }
+ };
+
+ var renderSimple = function (field, objs) {
+ if (!objs) return;
+ var headTD = $('#'+field+' .ROWHEAD');
+
+ var div = $('#'+field).get(0);
+
+ $('#'+field+' .selected').removeClass('selected');
+
+ var container = $('#'+field+' ul').empty();
+ container.append('<li />').find('li:last')
+ .append('<a />').find('a:last')
+ .text('All')
+ .each(function(index) {
+ if (div.sensei_selections.length == 0) $(this).addClass('selected');
+ })
+ .click(function (e) {
+ if ($(this).hasClass('selected'))
+ return false;
+ senseiClient.removeSelection(div.sensei_selections.pop());
+ refreshPage();
+ }).get(0).value = 'All';
+ for (var i=0; i<objs.length; ++i) {
+ var obj = objs[i];
+ container.append('<li />').find('li:last')
+ .append('<a />').find('a:last')
+ .text(obj.value+' ('+obj.count+')')
+ .each(function(index) {
+ if (obj.selected) $(this).addClass('selected');
+ })
+ .click(function (e) {
+ if ($(this).hasClass('selected'))
+ return false;
+ senseiClient.removeSelection(div.sensei_selections.pop());
+ div.sensei_selections.push(new SenseiSelection(field, this.value));
+ senseiClient.addSelection(div.sensei_selections[div.sensei_selections.length-1]);
+ refreshPage();
+ }).get(0).value = obj.value;
+ }
+ $('#'+field+' .ROWHEAD').text(field+': '+$('#'+field+' .selected').get(0).value);
+ };
+
+ var renderFacets = function (facets) {
+ renderPath('city', facets.city);
+ renderPath('makemodel', facets.makemodel);
+ renderTags(facets.tags);
+ renderSimple('color', facets.color);
+ renderSimple('category', facets.category);
+ renderSimple('year', facets.year);
+ renderSimple('price', facets.price);
+ renderSimple('mileage', facets.mileage);
+ };
+
+ var renderHits = function (hits) {
+ var hitsHead = $('#hits table thead tr').empty();
+ var cols = [['Sort by:', 'relevance'], ['color', 'color'], ['category', 'category'], ['year', 'year'], ['price', 'price'], ['mileage', 'mileage']];
+ for (var i=0; i<cols.length; ++i) {
+ if (cols[i][1] == 'relevance' && senseiClient._sorts[0].field == 'relevance') {
+ hitsHead.append('<th />').find('th:last').text(cols[i][0]);
+ }
+ else {
+ hitsHead.append('<th />').find('th:last')
+ .append('<a />').find('a:last')
+ .addClass('sortable')
+ .text(cols[i][0])
+ .click(function (e) {
+ var s = senseiClient._sorts[0];
+ if (s.field == this.value) {
+ s.dir = s.dir==SenseiSort.prototype.DIR.ASC ?
+ SenseiSort.prototype.DIR.DESC:SenseiSort.prototype.DIR.ASC;
+ }
+ else {
+ s.field = this.value;
+ }
+ senseiClient.offset = 0;
+ refreshPage();
+ }).get(0).value = cols[i][1];
+ }
+ }
+
+ var tbody = $('#hits').find('tbody').empty();
+
+ for(var i=0; i<hits.length; ++i) {
+ var hit = hits[i];
+ var container = tbody.append('<tr />').find('tr:last');
+ container.append('<td />').find('td:last').text(senseiClient.offset+i+1);
+ container.append('<td />').find('td:last').text(hit.color.join(','));
+ container.append('<td />').find('td:last').text(hit.category.join(','));
+ container.append('<td />').find('td:last').text(hit.year.join(','));
+ container.append('<td />').find('td:last').text(hit.price.join(','));
+ container.append('<td />').find('td:last').text(hit.mileage.join(','));
+ }
+ };
+
+ var renderPaging = function (obj) {
+ if (!obj) return;
+
+ var pager = $('#hits table tfoot tr td').empty();
+ if (senseiClient.offset > 0) {
+ pager.append('<a />').find('a:last')
+ .text('First')
+ .click(function (e) {
+ senseiClient.offset = 0;
+ refreshPage();
+ });
+ pager.append(' ');
+ pager.append('<a />').find('a:last')
+ .text('Prev')
+ .click(function (e) {
+ senseiClient.offset -= senseiClient.length;
+ if (senseiClient.offset < 0)
+ senseiClient.offset = 0;
+ refreshPage();
+ });
+ }
+ if (senseiClient.offset+senseiClient.length < obj.numhits) {
+ if (pager.text())
+ pager.append(' ');
+ pager.append('<a />').find('a:last')
+ .text('Next')
+ .click(function (e) {
+ senseiClient.offset += senseiClient.length;
+ if (senseiClient.offset > obj.numhits) {
+ if (obj.numhits % senseiClient.length)
+ senseiClient.offset = obj.numhits - (obj.numhits%senseiClient.length);
+ else
+ senseiClient.offset = obj.numhits - senseiClient.length;
+ }
+ refreshPage();
+ });
+ pager.append(' ');
+ pager.append('<a />').find('a:last')
+ .text('Last')
+ .click(function (e) {
+ if (obj.numhits % senseiClient.length)
+ senseiClient.offset = obj.numhits - (obj.numhits%senseiClient.length);
+ else
+ senseiClient.offset = obj.numhits - senseiClient.length;
+ if (senseiClient.offset < 0)
+ senseiClient.offset = 0;
+ refreshPage();
+ });
+ }
+ };
+
+ var senseiCallback = function (res) {
+ r = res;
+
+ renderStatus(res);
+
+ renderFacets(res.facets);
+ renderHits(res.hits);
+
+ renderPaging(res);
+ };
+
+ var refreshPage = function () {
+ senseiClient.request(senseiCallback);
+ };
+
+ $(function (e) {
+ $('#search').click(function (e) {
+ $('#city').get(0).sensei_selections = [];
+ $('#makemodel').get(0).sensei_selections = [];
+ $('#tags').get(0).sensei_selections = [];
+ $('#color').get(0).sensei_selections = [];
+ $('#category').get(0).sensei_selections = [];
+ $('#year').get(0).sensei_selections = [];
+ $('#price').get(0).sensei_selections = [];
+ $('#mileage').get(0).sensei_selections = [];
+
+ senseiClient = new SenseiClient($('#q').val().trim());
+
+ senseiClient.addFacet(new SenseiFacet('city'));
+ senseiClient.addFacet(new SenseiFacet('makemodel'));
+ senseiClient.addFacet(new SenseiFacet('tags', false));
+ senseiClient.addFacet(new SenseiFacet('color'));
+ senseiClient.addFacet(new SenseiFacet('category'));
+ senseiClient.addFacet(new SenseiFacet('year'));
+ senseiClient.addFacet(new SenseiFacet('price'));
+ senseiClient.addFacet(new SenseiFacet('mileage'));
+
+ senseiClient.addSort(new SenseiSort('relevance'));
+
+ refreshPage();
+ }).click();
+
+ $('#q').keypress(function (e) {
+ if (e.which == 13) {
+ e.preventDefault();
+ $('#search').click();
+ return false;
+ };
+ });
+
+ $('#resetAll').click(function (e) {
+ var ev = new $.Event("keypress");
+ ev.which = 13;
+ $('#q').val('').trigger(ev);
+ e.preventDefault();
+ return false;
+ });
+ });
+ // ]]>
+ </script>
+</head>
+<body>
+<table width="100%" border="0" summary="">
+ <tr>
+ <td align="left"> <span class="text">Hits: </span><span class="hitstat" id="hitcount"></span> </td>
+ <td align="right"> <span class="text"></span> <input id="q" /> <button id="search">Search</button> </td>
+ </tr>
+ <tr>
+ <td align="right" colspan="2"> <a id="resetAll">reset all</a> </td>
+ </tr>
+</table>
+<table width="100%" border="1" summary="">
+ <tr valign="top">
+ <td width="50%">
+ <div id="city">
+ <table width="100%">
+ <tr>
+ <td align="left" class="ROWHEAD">city: <span><a>All</a>/</span></td>
+ </tr>
+ <tr>
+ <td>
+ <table width="100%">
+ <tr>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </td>
+ <td width="50%">
+ <div id="makemodel">
+ <table width="100%">
+ <tr>
+ <td align="left" class="ROWHEAD">makemodel: <span><a>All</a></span></td>
+ </tr>
+ <tr>
+ <td>
+ <table width="100%">
+ <tr>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </td>
+ </tr>
+</table>
+<table width="100%" border="1" summary="">
+ <tr valign="top">
+ <td width="100%">
+ <div id="tags">
+ <table width="100%">
+ <tr>
+ <td class="ROWHEAD">tags: <span></span></td>
+ </tr>
+ <tr>
+ <td align="center"></td>
+ </tr>
+ </table>
+ </div>
+
+ </td>
+ </tr>
+</table>
+<table width="100%" border="1" summary="">
+ <tr valign="top">
+ <td width="20%">
+ <div id="color">
+ <table width="100%">
+ <tr><td align="left" class="ROWHEAD"></td></tr>
+ <tr align="left"><td class="SELECTELEM"><ul></ul></td></tr>
+ </table>
+ </div>
+ </td>
+ <td width="20%">
+ <div id="category">
+ <table width="100%">
+ <tr><td align="left" class="ROWHEAD"></td></tr>
+ <tr align="left"><td class="SELECTELEM"><ul></ul></td></tr>
+ </table>
+ </div>
+ </td>
+ <td width="20%">
+ <div id="year">
+ <table width="100%">
+ <tr><td align="left" class="ROWHEAD">year: </td></tr>
+ <tr align="left"><td class="SELECTELEM"><ul></ul></td></tr>
+ </table>
+ </div>
+ </td>
+ <td width="20%">
+ <div id="price">
+ <table width="100%">
+ <tr><td align="left" class="ROWHEAD">price: </td></tr>
+ <tr align="left"><td class="SELECTELEM"><ul></ul></td></tr>
+ </table>
+ </div>
+
+ </td>
+ <td width="20%">
+ <div id="mileage">
+ <table width="100%">
+ <tr><td align="left" class="ROWHEAD">mileage: </td></tr>
+ <tr align="left"><td class="SELECTELEM"><ul></ul></td></tr>
+ </table>
+ </div>
+ </td>
+ </tr>
+</table>
+<div id="hits">
+ <table width="100%">
+ <thead>
+ <tr><th width="10%">Sort by: </th><th width="18%" class="sortable"><a>color</a></th><th width="18%" class="sortable"><a>category</a></th><th width="18%" class="sortable"><a>year</a></th><th width="18%" class="sortable"><a>price</a></th><th width="18%" class="sortable"><a style="cursor: pointer;">mileage</a></th></tr>
+ </thead>
+ <tfoot>
+ <tr><td align="right" colspan="6" class="scroll"><a>Top </a><a>Up </a><a>Down </a><a>Bottom </a></td></tr>
+ </tfoot>
+ <tbody>
+ </tbody>
+ </table>
+</div>
+</body>
+</html>
+
View
52 src/main/webapp/index.html
@@ -0,0 +1,52 @@
+<html>
+<head>
+ <title>Sensei Client App</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <script type="text/javascript" src="js/sensei-client.js" ></script>
+ <script type="text/javascript" src="http://jsbeautifier.org/beautify.js" ></script>
+ <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
+</head>
+<body>
+ <table border="0" width="100%" bgcolor="black">
+ <tr valign="middle">
+ <td align="right">
+ <img src="http://sna-projects.com/sensei/images/sensei_white_transparent_s.png" />
+ </td>
+ <td align="center">
+ <h1><span style="color:white">Sensei Search Client Application</span></h1>
+ </td>
+ </tr>
+ </table>
+ <br/><br/><br/>
+ query: <input id="query" type="text" /><br/>
+ start: <input id="start" type="text" value="0" /><br/>
+ rows: <input id="rows" type="text" value="10" /> <br/>
+ return explanation: <input id="explain" type="checkbox" > <br/>
+ fetch stored fields: <input id="fetchstore" type="checkbox" > <br/>
+ <hr/>
+ sort: <input type="button" id="addsort" value="add sort" onclick="addSort()"/>
+ <input type="button" id="clearSort" value="clear" onclick="clearSorts()" />
+ <br/>
+ <div id="sorts">
+ </div>
+ <hr/>
+ selections: <input type="button" id="addsel" value="add selection" onclick="addSelection()"/>
+ <input type="button" id="clearSel" value="clear" onclick="clearSelections()" />
+ <br/>
+ <div id="selections">
+ </div>
+ <hr/>
+ facets: <input type="button" id="addfacet" value="add facet" onclick="addFacet()" />
+ <input type="button" id="clearFacets" value="clear" onclick="clearFacets()"/>
+ <div id="facets">
+ </div>
+ <hr/>
+ <input type="button" id="buildReqButton" value="build request string" onclick="buildreqString()"/><br/>
+ Rest Query:<input type="text" id="reqtext" size="200"/><br/>
+ <input type="button" id="runquery" value="run query" onclick="runQuery()"/><br/>
+
+ result: <br/>
+ <textarea rows="50" cols="100" name="content" id="content"></textarea>
+
+</body>
+</html>
View
592 src/main/webapp/js/sensei-client.js
@@ -0,0 +1,592 @@
+// Is a variable is defined.
+function isDefined(object, variable){
+ return (typeof(eval(object)[variable]) == 'undefined')? false : true;
+};
+
+// String trim function.
+String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
+
+// SenseiFacet(name, expand=true, minHits=1, maxCounts=10, orderBy=HITS)
+var SenseiFacet = function () {
+ if (arguments.length == 0) return null;
+
+ this.expand = true;
+ this.minHits = 1;
+ this.maxCounts = 10;
+ this.orderBy = this.OrderBy.HITS;
+
+ this.name = arguments[0];
+ if (arguments.length > 1)
+ this.expand = arguments[1];
+ if (arguments.length > 2)
+ this.minHits = arguments[2];
+ if (arguments.length > 3)
+ this.maxCounts = arguments[3];
+ if (arguments.length > 4)
+ this.orderBy = arguments[4];
+};
+
+SenseiFacet.prototype = {
+ OrderBy: {
+ HITS: "hits",
+ VALUE: "val"
+ }
+};
+
+var SenseiProperty = function (key, val) {
+ this.key = key;
+ this.val = val;
+};
+
+// SenseiSelection(name, values="", excludes="", operation=OR)
+var SenseiSelection = function () {
+ if (arguments.length == 0) return null;
+
+ this.values = "";
+ this.excludes = "";
+ this.operation = this.Operation.OR;
+ this.properties = [];
+
+ this.name = arguments[0];
+ if (arguments.length > 1)
+ this.values = arguments[1];
+ if (arguments.length > 2)
+ this.excludes = arguments[2];
+ if (arguments.length > 3)
+ this.operation = arguments[3];
+};
+
+SenseiSelection.prototype = {
+ Operation: {
+ OR: "or",
+ AND: "and"
+ },
+
+ addProperty: function (key, val) {
+ for (var i=0; i<this.properties.length; ++i) {
+ if (this.properties[i].key == key) {
+ this.properties[i].val = val;
+ return true;
+ }
+ }
+ this.properties.push(new SenseiProperty(key, val));
+ return true;
+ },
+
+ removeProperty: function (key) {
+ for (var i=0; i<this.properties.length; ++i) {
+ if (this.properties[i].key == key) {
+ this.properties.splice(i, 1);
+ return true;
+ }
+ }
+ return false;
+ },
+};
+
+// SenseiSort(field, dir=DESC)
+var SenseiSort = function () {
+ if (arguments.length == 0) return null;
+
+ this.dir = this.DIR.DESC;
+
+ this.field = arguments[0];
+ if (arguments.length > 1)
+ this.dir = arguments[1];
+};
+
+SenseiSort.prototype = {
+ DIR: {
+ ASC: "asc",
+ DESC: "desc"
+ }
+};
+
+// SenseiClient(query="", offset=0, length=10, explain=false, fetch=false)
+var SenseiClient = function () {
+ this._facets = [];
+ this._selections = [];
+ this._sorts = [];
+
+ this.query = "";
+ this.offset = 0;
+ this.length = 10;
+ this.explain = false;
+ this.fetch = false;
+
+ if (arguments.length > 0)
+ this.query = arguments[0];
+ if (arguments.length > 1)
+ this.offset = arguments[1];
+ if (arguments.length > 2)
+ this.length = arguments[2];
+ if (arguments.length > 3)
+ this.explain = arguments[3];
+ if (arguments.length > 4)
+ this.fetch = arguments[4];
+};
+
+SenseiClient.prototype = {
+ addFacet: function (facet) {
+ if (!facet) return false;
+
+ for (var i=0; i<this._facets.length; ++i) {
+ if (facet.name == this._facets[i].name) {
+ this._facets.splice(i, 1, facet);
+ return true;
+ }
+ }
+ this._facets.push(facet);
+
+ return true;
+ },
+
+ removeFacet: function (name) {
+ for (var i=0; i<this._facets.length; ++i) {
+ if (name == this._facets[i].name) {
+ this._facets.splice(i, 1);
+ return true;
+ }
+ }
+ return false;
+ },
+
+ clearFacets: function () {
+ this._facets = [];
+ },
+
+ addSelection: function (sel) {
+ if (!sel) return false;
+
+ for (var i=0; i<this._selections.length; ++i) {
+ if (sel == this._selections[i]) {
+ return true;
+ }
+ }
+ this._selections.push(sel);
+ return true;
+ },
+
+ removeSelection: function (sel) {
+ for (var i=0; i<this._selections.length; ++i) {
+ if (sel == this._selections[i]) {
+ this._selections.splice(i, 1);
+ return true;
+ }
+ }
+ return false;
+ },
+
+ clearSelections: function () {
+ this._selections = [];
+ },
+
+ addSort: function (sort) {
+ if (!sort) return false;
+
+ for (var i=0; i<this._sorts.length; ++i) {
+ if (sort.field == this._sorts[i].field) {
+ this._sorts.splice(i, 1, sort);
+ return true;
+ }
+ }
+ this._sorts.push(sort);
+
+ return true;
+ },
+
+ removeSort: function (field) {
+ for (var i=0; i<this._sorts.length; ++i) {
+ if (field == this._sorts[i].field) {
+ this._sorts.splice(i, 1);
+ return true;
+ }
+ }
+ return false;
+ },
+
+ clearSorts: function () {
+ this._sorts = [];
+ },
+
+ buildQuery: function () {
+ var qs = {
+ q: this.query,
+ start: this.offset,
+ rows: this.length,
+ };
+ if (this.explain)
+ qs['showexplain'] = true;
+ if (this.fetch)
+ qs['fetchstored'] = true;
+
+ for (var i=0; i<this._facets.length; ++i) {
+ var facet = this._facets[i];
+ qs["facet."+facet.name+".expand"] = facet.expand;
+ qs["facet."+facet.name+".minhit"] = facet.minHits;
+ qs["facet."+facet.name+".max"] = facet.maxCounts;
+ qs["facet."+facet.name+".order"] = facet.orderBy;
+ }
+ for (var i=0; i<this._selections.length; ++i) {
+ var sel = this._selections[i];
+ qs["select."+sel.name+".val"] = sel.values;
+ qs["select."+sel.name+".not"] = sel.excludes;
+ qs["select."+sel.name+".op"] = sel.operation;
+ var props = [];
+ for (var j=0; j<sel.properties.length; j++) {
+ props.push(""+sel.properties[j].key+":"+sel.properties[j].val);
+ }
+ props = props.join(',');
+ if (props != '')
+ qs["select."+sel.name+".prop"] = props;
+ }
+ var sl = [];
+ for (var i=0; i<this._sorts.length; ++i) {
+ var sort = this._sorts[i];
+ if (sort.field == "relevance") {
+ sl.push(sort.field);
+ }
+ else {
+ sl.push(sort.field+":"+sort.dir);
+ }
+ }
+ qs["sort"] = sl.join(',');
+
+ return qs;
+ },
+
+ request: function (callback) {
+ $.getJSON("sensei", this.buildQuery(), callback);
+ }
+};
+
+function removeAllChildren(elem){
+ if ( elem.hasChildNodes() ){
+ while (elem.childNodes.length >= 1 )
+ {
+ elem.removeChild( elem.firstChild );
+ }
+ }
+}
+
+function removeSort(sortNode){
+ var sortElement = document.getElementById("sorts");
+ sortElement.removeChild(sortNode);
+}
+
+function removeSelection(selectionNode){
+ var selElement = document.getElementById("selections");
+ selElement.removeChild(selectionNode);
+}
+
+function removeFacet(facetNode){
+ var facetElement = document.getElementById("facets");
+ facetElement.removeChild(facetNode);
+}
+
+function addFacet(){
+ var facetElement = document.getElementById("facets");
+ var divNode = document.createElement('div');
+ divNode.setAttribute('name','facet');
+ facetElement.appendChild(divNode);
+
+ divNode.appendChild(document.createTextNode('name: '));
+ var nameTextNode = document.createElement('input');
+ nameTextNode.setAttribute('type','text');
+ nameTextNode.setAttribute('name','name');
+ divNode.appendChild(nameTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('expand: '));
+ var expandCheckNode = document.createElement('input');
+ expandCheckNode.setAttribute('type','checkbox');
+ expandCheckNode.setAttribute('name','expand');
+ divNode.appendChild(expandCheckNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('min hits: '));
+ var minHitsTextNode = document.createElement('input');
+ minHitsTextNode.setAttribute('type','text');
+ minHitsTextNode.setAttribute('name','minhit');
+ minHitsTextNode.setAttribute('value','1');
+ divNode.appendChild(minHitsTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('max counts: '));
+ var maxCountsTextNode = document.createElement('input');
+ maxCountsTextNode.setAttribute('type','text');
+ maxCountsTextNode.setAttribute('name','max');
+ maxCountsTextNode.setAttribute('value','10');
+ divNode.appendChild(maxCountsTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('order by: '));
+ var dropDownOrderNode = document.createElement('select');
+ dropDownOrderNode.setAttribute('name','order');
+ var opt1 = document.createElement('option');
+ opt1.innerHTML = 'hits';
+ dropDownOrderNode.appendChild(opt1);
+ var opt2 = document.createElement('option');
+ opt2.innerHTML = 'val';
+ dropDownOrderNode.appendChild(opt2);
+ divNode.appendChild(dropDownOrderNode);
+ divNode.appendChild(document.createElement('br'));
+
+ var removeButton = document.createElement('input');
+ removeButton.setAttribute('type','button');
+ removeButton.setAttribute('value','remove facet');
+ removeButton.setAttribute('onclick','removeFacet(this.parentNode)');
+ divNode.appendChild(removeButton);
+}
+
+function buildSelectionReqString(selectionNode,prefix,paramNames){
+ var reqString = "";
+ var selName = null;
+ var firsttime=true;
+ for(var i=0; i<selectionNode.childNodes.length; i++){
+ var node = selectionNode.childNodes[i];
+ var nodeName = node.name;
+ if (nodeName == null ) continue;
+ if ("name" == nodeName){
+ selName = node.value;
+ }
+ else{
+ if (!selName) continue;
+ if (nodeName in paramNames){
+ if (!firsttime) {
+ reqString+="&";
+ }
+
+ var val;
+ if (node.type == 'checkbox'){
+ if (node.value=='on'){
+ val = 'true';
+ }
+ else{
+ val = 'false';
+ }
+ }
+ else{
+ val = node.value;
+ }
+ reqString += prefix+"."+selName+"."+nodeName+"="+val;
+ firsttime=false;
+ }
+ }
+ }
+
+ return reqString;
+}
+
+function addSelection(){
+ var selElement = document.getElementById("selections");
+ var divNode = document.createElement('div');
+ divNode.setAttribute('name','selection');
+ selElement.appendChild(divNode);
+
+ divNode.appendChild(document.createTextNode('name: '));
+ var nameTextNode = document.createElement('input');
+ nameTextNode.setAttribute('type','text');
+ nameTextNode.setAttribute('name','name');
+ divNode.appendChild(nameTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('values: '));
+ var valTextNode = document.createElement('input');
+ valTextNode.setAttribute('type','text');
+ valTextNode.setAttribute('name','val');
+ divNode.appendChild(valTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('excludes: '));
+ var notTextNode = document.createElement('input');
+ notTextNode.setAttribute('type','text');
+ notTextNode.setAttribute('name','not');
+ divNode.appendChild(notTextNode);
+ divNode.appendChild(document.createElement('br'));
+
+ divNode.appendChild(document.createTextNode('operation: '));
+ var dropDownSelNode = document.createElement('select');
+ dropDownSelNode.setAttribute('name','op');
+ var opt1 = document.createElement('option');
+ opt1.innerHTML = 'or';
+ dropDownSelNode.appendChild(opt1);
+ var opt2 = document.createElement('option');
+ opt2.innerHTML = 'and';
+ dropDownSelNode.appendChild(opt2);
+ divNode.appendChild(dropDownSelNode);
+ divNode.appendChild(document.createElement('br'));
+
+ var removeButton = document.createElement('input');
+ removeButton.setAttribute('type','button');
+ removeButton.setAttribute('value','remove selection');
+ removeButton.setAttribute('onclick','removeSelection(this.parentNode)');
+ divNode.appendChild(removeButton);
+}
+
+function buildSortString(){
+ var reqString = "sort=";
+ var firsttime=true;
+ var sortNodes = document.getElementsByName('sort');
+ if (sortNodes!=null){
+ for (var i=0;i<sortNodes.length;++i){
+
+ var reqSubString = null;
+ var field = null;
+ var dir = null;
+
+ for(var k=0; k<sortNodes[i].childNodes.length; k++){
+ var node = sortNodes[i].childNodes[k];
+ var nodeName = node.name;
+ if (nodeName == null ) continue;
+
+ if ("field" == nodeName){
+ field = node.value;
+ }
+ else if ("dir"==nodeName){
+ dir = node.value;
+ }
+ }
+
+ if (field!=null){
+ if ("relevance" == field){
+ reqSubString=field;
+ }
+ else{
+ reqSubString=field+":"+dir;
+ }
+ }
+
+ if (reqSubString!=null){
+ if (!firsttime){
+ reqString+=",";
+ }
+ else{
+ firsttime=false;
+ }
+ reqString+=reqSubString;
+ }
+ }
+ }
+ return reqString;
+}
+
+function addSort(){
+ var sortElement = document.getElementById("sorts");
+ var divNode = document.createElement('div');
+ divNode.setAttribute('name','sort');
+ sortElement.appendChild(divNode);
+
+ divNode.appendChild(document.createTextNode('sort: '));
+ var fieldTextNode = document.createElement('input');
+ fieldTextNode.setAttribute('type','text');
+ fieldTextNode.setAttribute('name','field');
+ divNode.appendChild(fieldTextNode);
+
+ var dropDownSelNode = document.createElement('select');
+ dropDownSelNode.setAttribute('name','dir');
+ var opt1 = document.createElement('option');
+ opt1.innerHTML = 'desc';
+ dropDownSelNode.appendChild(opt1);
+ var opt2 = document.createElement('option');
+ opt2.innerHTML = 'asc';
+ dropDownSelNode.appendChild(opt2);
+ divNode.appendChild(dropDownSelNode);
+ divNode.appendChild(document.createElement('br'));
+
+ var removeButton = document.createElement('input');
+ removeButton.setAttribute('type','button');
+ removeButton.setAttribute('value','remove sort');
+ removeButton.setAttribute('onclick','removeSort(this.parentNode)');
+ divNode.appendChild(removeButton);
+}
+
+function clearSorts(){
+ var sortElement = document.getElementById("sorts");
+ removeAllChildren(sortElement);
+}
+
+function clearSelections(){
+ var selElement = document.getElementById("selections");
+ removeAllChildren(selElement);
+}
+
+function clearFacets(){
+ var facetElement = document.getElementById("facets");
+ removeAllChildren(facetElement);
+}
+
+
+function buildreqString(){
+ document.getElementById('buildReqButton').disable=true;
+
+ var qstring = document.getElementById('query').value;
+
+ var start = document.getElementById('start').value;
+ var rows = document.getElementById('rows').value;
+
+ var explain = document.getElementById('explain').checked;
+
+ var fetchStore = document.getElementById('fetchstore').checked;
+
+ var reqString="q=" + qstring +"&start=" + start + "&rows=" + rows;
+
+ if (explain){
+ reqString += "&showexplain=true";
+ }
+
+ if (fetchStore){
+ reqString += "&fetchstored=true";
+ }
+
+ var selectionNodes = document.getElementsByName('selection');
+ var params = {not:"not",val:"val",op:"op"};
+ for (var i=0;i<selectionNodes.length;++i){
+ reqString+="&"+buildSelectionReqString(selectionNodes[i],"select",params);
+ }
+
+ var facetNodes = document.getElementsByName('facet');
+ var facetparams = {expand:"expand",max:"max",minhit:"minhit",order:"order"};
+ for (var i=0;i<facetNodes.length;++i){
+ reqString+="&"+buildSelectionReqString(facetNodes[i],"facet",facetparams);
+ }
+
+ reqString += "&"+buildSortString();
+
+ document.getElementById('reqtext').value=reqString;
+ document.getElementById('buildReqButton').disable=false;
+}
+
+function trim_leading_comments(str)
+{
+ // very basic. doesn't support /* ... */
+ str = str.replace(/^(\s*\/\/[^\n]*\n)+/, '');
+ str = str.replace(/^\s+/, '');
+ return str;
+}
+
+function renderResult(content){
+ var js_source = content.replace(/^\s+/, '');
+ var indent_size = 4;
+ var indent_char = ' ';
+ var preserve_newlines = true;
+ var keep_array_indentation = false;
+ var braces_on_own_line = true;
+
+ document.getElementById('content').value =
+ js_beautify(js_source, {
+ indent_size: indent_size,
+ indent_char: indent_char,
+ preserve_newlines:preserve_newlines,
+ braces_on_own_line: braces_on_own_line,
+ keep_array_indentation:keep_array_indentation,
+ space_after_anon_function:true});
+}
+
+function runQuery(){
+ document.getElementById('runquery').disable=true;
+ var reqString = document.getElementById('reqtext').value;
+ $.get("sensei?"+reqString,renderResult);
+ document.getElementById('runquery').disable=false;
+}
+
View
32 test/Test.iml
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="true" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/../dist/sensei-0.0.1.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="library" name="master" level="project" />
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/../lib/test/junit.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="module" module-name="Sensei" />
- </component>
-</module>
-
Please sign in to comment.
Something went wrong with that request. Please try again.