Skip to content

Commit

Permalink
api wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Dec 22, 2011
1 parent 305f4a5 commit 8f3f06c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions embedded-api/com/flaptor/indextank/api/EmbeddedApiV1.java
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
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
@@ -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 8f3f06c

Please sign in to comment.