From 18c57d96c3fb392146d430660d05e3606caad692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n?= Date: Thu, 22 Dec 2011 03:08:27 -0200 Subject: [PATCH 1/3] Update README.md --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2345775..aadb586 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ Apache Public License (APL) 2.0 ### Artifacts: -1. engine-1.0.0.jar <-- core library +1. indextank-engine-1.0.0.jar <-- core library ### Maven: groupId: com.flaptor.indextank -artifactId: engine +artifactId: indextank-engine version: 1.0.0 @@ -32,13 +32,31 @@ mvn package assembly:single This will create a single file in: -target/engine-1.0.0-jar-with-dependencies.jar +target/indextank-engine-1.0.0-jar-with-dependencies.jar -### Sample configuration: +### Quick start with standalone REST API + +You can try basic indexing and searching + +Main class: com.flaptor.indextank.api.Launcher + +After running the package generation: + +$ java -cp target/indextank-engine-1.0.0-jar-with-dependencies.jar com.flaptor.indextank.api.Launcher + +This command starts an API server (http://www.indextank.com/documentation/api) at port 20220. +The indexing and searching can be done with any client or for example, via curl: + +curl -d "{\"docid\":\"post1\", \"text\":\"I love Fallout\"}" -v -X PUT http://localhost:20220/v1/indexes/idx/docs +curl -d "{\"docid\":\"post2\", \"text\":\"I love Planescape\"}" -v -X PUT http://localhost:20220/v1/indexes/idx/docs + +curl http://localhost:20220/v1/indexes/idx/search?q=love + +### Sample index configuration: Main class: com.flaptor.indextank.index.IndexEngine -VM args: -verbose:gc -Xloggc:logs/gc.log -XX:+PrintGCTimeStamps -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -Dorg.apache.lucene.FSDirectory.class=org.apache.lucene.store.MMapDirectory -Xmx600M +VM args: -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -Dorg.apache.lucene.FSDirectory.class=org.apache.lucene.store.MMapDirectory -Xmx600M Program args: --facets --rti-size 500 --conf-file sample-engine-config --port 20220 --environment-prefix TEST --recover --dir index --snippets --suggest documents --boosts 3 --index-code dgmqn --functions 0:-age From 305f4a5c709a8f545bf454ae448e1768acb15ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n?= Date: Thu, 22 Dec 2011 03:08:49 -0200 Subject: [PATCH 2/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aadb586..fcd775a 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ This command starts an API server (http://www.indextank.com/documentation/api) a The indexing and searching can be done with any client or for example, via curl: curl -d "{\"docid\":\"post1\", \"text\":\"I love Fallout\"}" -v -X PUT http://localhost:20220/v1/indexes/idx/docs + curl -d "{\"docid\":\"post2\", \"text\":\"I love Planescape\"}" -v -X PUT http://localhost:20220/v1/indexes/idx/docs curl http://localhost:20220/v1/indexes/idx/search?q=love From 8f3f06cc57abd2f25eba8ad4f00a712d58ff4d3a Mon Sep 17 00:00:00 2001 From: Adrian Date: Thu, 22 Dec 2011 11:34:35 -0300 Subject: [PATCH 3/3] api wip --- .../flaptor/indextank/api/EmbeddedApiV1.java | 3 ++ .../flaptor/indextank/api/IndexEngineApi.java | 5 ++ .../indextank/api/resources/Autocomplete.java | 49 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java diff --git a/embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java b/embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java index b9d112e..e2e5d09 100644 --- a/embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java +++ b/embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java @@ -16,6 +16,7 @@ package com.flaptor.indextank.api; +import com.flaptor.indextank.api.resources.Autocomplete; import com.flaptor.indextank.api.resources.Docs; import com.flaptor.indextank.api.resources.Search; import com.ghosthack.turismo.action.Action; @@ -25,6 +26,8 @@ public class EmbeddedApiV1 extends RoutesList { protected void map() { + get("/indexes/:name/autocomplete", new Autocomplete()); + get("/indexes/:name/search", new Search()); put("/indexes/:name/docs", new Docs()); diff --git a/embedded-api/com/flaptor/indextank/api/IndexEngineApi.java b/embedded-api/com/flaptor/indextank/api/IndexEngineApi.java index ed54833..8578d22 100644 --- a/embedded-api/com/flaptor/indextank/api/IndexEngineApi.java +++ b/embedded-api/com/flaptor/indextank/api/IndexEngineApi.java @@ -136,6 +136,7 @@ public void putDocument(String id, JSONObject fields, JSONObject variables, JSON BoostingIndexer indexer = engine.getIndexer(); indexer.add(id, new Document(prepareProperties(fields)), Timestamp.inSeconds(), prepareBoosts(variables)); indexer.updateCategories(id, prepareProperties(categories)); + System.out.println(engine.getIndexer().getStats()); } private Map prepareProperties(JSONObject jo) { @@ -168,4 +169,8 @@ private Map prepareBoosts(JSONObject jo) { return dynamicBoosts; } + public List complete(String query, String field) { + return engine.getSuggestor().complete(query, field); + } + } diff --git a/embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java b/embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java new file mode 100644 index 0000000..60caa4a --- /dev/null +++ b/embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011 LinkedIn, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.flaptor.indextank.api.resources; + +import java.util.List; +import java.util.logging.Logger; + +import com.flaptor.indextank.api.IndexEngineApi; +import com.ghosthack.turismo.action.Action; + +public class Autocomplete extends Action { + + /** + * @see java.lang.Runnable#run() + */ + public void run() { + IndexEngineApi api = (IndexEngineApi) ctx().getAttribute("api"); + + String query = params("query"); + String field = params("field"); + + if(field == null || field.isEmpty()) { + field = "text"; + } + + List complete = api.complete(query, field); + + print(complete.toString()); + + } + + private static final Logger LOG = Logger.getLogger(Autocomplete.class.getName()); + private static final boolean LOG_ENABLED = true; + +}