summaryrefslogtreecommitdiffstats
path: root/sample-apps
diff options
context:
space:
mode:
authorLester Solbakken <lesters@yahoo-inc.com>2017-05-31 09:59:30 +0200
committerLester Solbakken <lesters@yahoo-inc.com>2017-05-31 09:59:30 +0200
commit2010f09a5c819d6aee03f93d2367e02e9ffc221b (patch)
tree40cf2ee7b0de47265c0d2d520ad162b91dc7f672 /sample-apps
parent5ee7713ecb01a026c3fb502f171faacb0fc9a196 (diff)
Add tensor sample app
Diffstat (limited to 'sample-apps')
-rw-r--r--sample-apps/basic-search-tensor/README.md4
-rw-r--r--sample-apps/basic-search-tensor/music-data-1.json17
-rw-r--r--sample-apps/basic-search-tensor/music-data-2.json17
-rw-r--r--sample-apps/basic-search-tensor/pom.xml86
-rw-r--r--sample-apps/basic-search-tensor/src/main/application/hosts.xml7
-rw-r--r--sample-apps/basic-search-tensor/src/main/application/search/query-profiles/types/root.xml3
-rw-r--r--sample-apps/basic-search-tensor/src/main/application/searchdefinitions/music.sd55
-rw-r--r--sample-apps/basic-search-tensor/src/main/application/services.xml32
-rw-r--r--sample-apps/basic-search-tensor/src/main/java/com/yahoo/example/ExampleTensorSearcher.java32
9 files changed, 253 insertions, 0 deletions
diff --git a/sample-apps/basic-search-tensor/README.md b/sample-apps/basic-search-tensor/README.md
new file mode 100644
index 00000000000..e4dca548c10
--- /dev/null
+++ b/sample-apps/basic-search-tensor/README.md
@@ -0,0 +1,4 @@
+# tensor-testing
+
+Testing our tensors in general
+
diff --git a/sample-apps/basic-search-tensor/music-data-1.json b/sample-apps/basic-search-tensor/music-data-1.json
new file mode 100644
index 00000000000..247745a5e32
--- /dev/null
+++ b/sample-apps/basic-search-tensor/music-data-1.json
@@ -0,0 +1,17 @@
+{
+ "fields": {
+ "album": "Bad",
+ "artist": "Michael Jackson",
+ "title": "Bad",
+ "year": 1987,
+ "duration": 247,
+ "tensor_attribute": {
+ "cells": [
+ { "address" : { "x" : "0" }, "value": 1.0 },
+ { "address" : { "x" : "1" }, "value": 2.0 },
+ { "address" : { "x" : "2" }, "value": 3.0 },
+ { "address" : { "x" : "3" }, "value": 5.0 }
+ ]
+ }
+ }
+}
diff --git a/sample-apps/basic-search-tensor/music-data-2.json b/sample-apps/basic-search-tensor/music-data-2.json
new file mode 100644
index 00000000000..d5419902574
--- /dev/null
+++ b/sample-apps/basic-search-tensor/music-data-2.json
@@ -0,0 +1,17 @@
+{
+ "fields": {
+ "album": "Recovery",
+ "artist": "Eminem",
+ "title": "So Bad",
+ "year": 2010,
+ "tensor_attribute": {
+ "cells": [
+ { "address" : { "x" : "0" }, "value": 2.0 },
+ { "address" : { "x" : "1" }, "value": 3.0 },
+ { "address" : { "x" : "2" }, "value": 4.0 },
+ { "address" : { "x" : "3" }, "value": 6.0 }
+ ]
+ }
+ }
+}
+
diff --git a/sample-apps/basic-search-tensor/pom.xml b/sample-apps/basic-search-tensor/pom.xml
new file mode 100644
index 00000000000..e0b821272fc
--- /dev/null
+++ b/sample-apps/basic-search-tensor/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0"?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.yahoo.example</groupId>
+ <artifactId>basic-search-java</artifactId>
+ <version>1.0.1</version>
+ <packaging>container-plugin</packaging> <!-- Use Vespa packaging -->
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <test.hide>true</test.hide>
+ <!--<vespa_version>6-SNAPSHOT</vespa_version>-->
+ <vespa_version>6.101.9</vespa_version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>application</artifactId> <!-- Is this needed? -->
+ <version>${vespa_version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>container-dev</artifactId> <!-- not container-dev -->
+ <version>${vespa_version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.6.1</version>
+ <configuration>
+ <optimize>true</optimize>
+ <showDeprecation>true</showDeprecation>
+ <showWarnings>true</showWarnings>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <systemPropertyVariables>
+ <isMavenSurefirePlugin>true</isMavenSurefirePlugin>
+ </systemPropertyVariables>
+ <redirectTestOutputToFile>${test.hide}</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>vespa-application-maven-plugin</artifactId> <!-- Zip the application package -->
+ <version>${vespa_version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>packageApplication</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>bundle-plugin</artifactId>
+ <version>${vespa_version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/sample-apps/basic-search-tensor/src/main/application/hosts.xml b/sample-apps/basic-search-tensor/src/main/application/hosts.xml
new file mode 100644
index 00000000000..3ab86a21aef
--- /dev/null
+++ b/sample-apps/basic-search-tensor/src/main/application/hosts.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<hosts>
+ <host name="localhost">
+ <alias>node1</alias>
+ </host>
+</hosts>
diff --git a/sample-apps/basic-search-tensor/src/main/application/search/query-profiles/types/root.xml b/sample-apps/basic-search-tensor/src/main/application/search/query-profiles/types/root.xml
new file mode 100644
index 00000000000..b3971cc9b66
--- /dev/null
+++ b/sample-apps/basic-search-tensor/src/main/application/search/query-profiles/types/root.xml
@@ -0,0 +1,3 @@
+<query-profile-type id="root" inherits="native">
+ <field name="ranking.features.query(atensor)" type="tensor(x{})" />
+</query-profile-type> \ No newline at end of file
diff --git a/sample-apps/basic-search-tensor/src/main/application/searchdefinitions/music.sd b/sample-apps/basic-search-tensor/src/main/application/searchdefinitions/music.sd
new file mode 100644
index 00000000000..85d59504321
--- /dev/null
+++ b/sample-apps/basic-search-tensor/src/main/application/searchdefinitions/music.sd
@@ -0,0 +1,55 @@
+search music {
+ document music {
+ field artist type string {
+ indexing: summary | index
+ }
+
+ field artistId type string {
+ indexing: summary | attribute
+ }
+
+ field title type string {
+ indexing: summary | index
+ }
+
+ field album type string {
+ indexing: index
+ }
+
+ field duration type int {
+ indexing: summary
+ }
+
+ field year type int {
+ indexing: summary | attribute
+ }
+
+ field popularity type int {
+ indexing: summary | attribute
+ }
+
+ field tensor_attribute type tensor(x{}) {
+ indexing: summary | attribute
+ attribute: tensor(x{})
+ }
+
+ }
+
+ constant tensor_constant {
+ file: constants/constant_tensor_file.json
+ type: tensor(x{})
+ }
+
+ rank-profile simple_tensor_ranking inherits default {
+ first-phase {
+ expression: sum(query(tensor) * attribute(tensor_attribute))
+ }
+ }
+
+ rank-profile constant_tensor_ranking inherits default {
+ first-phase {
+ expression: sum(query(tensor) * attribute(tensor_attribute) * constant(tensor_constant))
+ }
+ }
+
+}
diff --git a/sample-apps/basic-search-tensor/src/main/application/services.xml b/sample-apps/basic-search-tensor/src/main/application/services.xml
new file mode 100644
index 00000000000..a6b0350a918
--- /dev/null
+++ b/sample-apps/basic-search-tensor/src/main/application/services.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<services version="1.0">
+
+ <admin version="2.0">
+ <adminserver hostalias="node1"/>
+ </admin>
+
+ <jdisc version="1.0">
+ <search>
+ <chain id="default" inherits="vespa">
+ <searcher id="com.yahoo.example.ExampleTensorSearcher" bundle="basic-search-java" />
+ </chain>
+ </search>
+ <document-api/>
+ <nodes jvmargs="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8998">
+ <node hostalias="node1"/>
+ </nodes>
+ </jdisc>
+
+ <content id="music" version="1.0">
+ <redundancy>1</redundancy>
+ <documents>
+ <document type="music" mode="index" />
+ </documents>
+ <nodes>
+ <node hostalias="node1" distribution-key="0" />
+ </nodes>
+ </content>
+
+</services>
+
diff --git a/sample-apps/basic-search-tensor/src/main/java/com/yahoo/example/ExampleTensorSearcher.java b/sample-apps/basic-search-tensor/src/main/java/com/yahoo/example/ExampleTensorSearcher.java
new file mode 100644
index 00000000000..375ad7c98cb
--- /dev/null
+++ b/sample-apps/basic-search-tensor/src/main/java/com/yahoo/example/ExampleTensorSearcher.java
@@ -0,0 +1,32 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.example;
+
+import com.yahoo.processing.request.CompoundName;
+import com.yahoo.search.searchchain.Execution;
+import com.yahoo.search.Query;
+import com.yahoo.search.Result;
+import com.yahoo.search.Searcher;
+import com.yahoo.tensor.Tensor;
+
+public class ExampleTensorSearcher extends Searcher {
+
+ @Override
+ public Result search(Query query, Execution execution) {
+
+ Object tensorProperty = query.properties().get("tensor");
+ if (tensorProperty != null) {
+
+ // Construct a Tensor object based on the query parameter
+ Tensor tensor = Tensor.from(tensorProperty.toString());
+
+ // Create a new rank feature using this tensor
+ query.getRanking().getFeatures().put("query(tensor)", tensor);
+
+ // Set the rank profile to use
+ query.properties().set(new CompoundName("ranking"), "simple_tensor_ranking");
+ }
+
+ return execution.search(query);
+ }
+
+}