Skip to content

Commit

Permalink
Merge pull request LinkedInAttic#3 from adrnai/master
Browse files Browse the repository at this point in the history
Autocomplete resource and README quick start
  • Loading branch information
iladriano committed Dec 22, 2011
2 parents 7146c42 + 8f3f06c commit 0bcc906
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,13 +32,32 @@ 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

Expand Down
3 changes: 3 additions & 0 deletions embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions embedded-api/com/flaptor/indextank/api/IndexEngineApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> prepareProperties(JSONObject jo) {
Expand Down Expand Up @@ -168,4 +169,8 @@ private Map<Integer, Double> prepareBoosts(JSONObject jo) {
return dynamicBoosts;
}

public List<String> complete(String query, String field) {
return engine.getSuggestor().complete(query, field);
}

}
49 changes: 49 additions & 0 deletions embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java
Original file line number Diff line number Diff line change
@@ -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<String> 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;

}

0 comments on commit 0bcc906

Please sign in to comment.