com.threewks.thundr.search.gae.GaeSearchService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thundr-gae Show documentation
Show all versions of thundr-gae Show documentation
A thundr module enabling thundr for use on GAE (Google App Engine)
/*
* This file is a component of thundr, a software library from 3wks.
* Read more: http://3wks.github.io/thundr/
* Copyright (C) 2015 3wks,
*
* 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.threewks.thundr.search.gae;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.atomicleopard.expressive.Expressive;
import com.threewks.thundr.search.IndexOperation;
import com.threewks.thundr.search.SearchException;
import com.threewks.thundr.search.TextSearchService;
import com.threewks.thundr.search.gae.naming.DefaultIndexNamingStrategy;
import com.threewks.thundr.search.gae.naming.IndexNamingStrategy;
/**
* An implementation of {@link TextSearchService} which uses Appengine's Full Text Search Api
*
* @param
* @param
*/
public class GaeSearchService extends BaseGaeSearchService implements TextSearchService, SearchExecutor> {
/**
* Create a {@link GaeSearchService} for the given type using the {@link DefaultIndexNamingStrategy}.
*
* @param type the type this search service will index
* @param searchConfig
*/
public GaeSearchService(Class type, SearchConfig searchConfig) {
this(type, searchConfig, new DefaultIndexNamingStrategy());
}
/**
* Create a {@link GaeSearchService} for the given type using the given {@link IndexNamingStrategy}.
*
* @param type
* @param searchConfig
* @param indexNamingStrategy
*/
public GaeSearchService(Class type, SearchConfig searchConfig, IndexNamingStrategy indexNamingStrategy) {
super(type, searchConfig, indexNamingStrategy);
if (!metadata.hasIndexableFields()) {
throw new SearchException("Unable to create %s - the type %s has no indexable fields ", this.getClass().getSimpleName(), type.getSimpleName());
}
}
@Override
public IndexOperation index(T object) {
K id = metadata.getId(object);
return super.index(object, id);
}
@Override
public IndexOperation index(Collection objects) {
return super.index(objects);
}
@Override
public IndexOperation removeById(K id) {
return super.removeById(id);
}
@Override
public IndexOperation removeById(Iterable ids) {
return super.removeById(ids);
}
@Override
public IndexOperation remove(T object) {
K id = metadata.getId(object);
return super.removeById(id);
}
@Override
public IndexOperation remove(Iterable objects) {
if (Expressive.isEmpty(objects)) {
return new IndexOperation(null);
}
List ids = new ArrayList<>();
for (T object : objects) {
ids.add(metadata.getId(object));
}
return super.removeById(ids);
}
@Override
public int removeAll() {
return super.removeAll();
}
@Override
public SearchImpl search() {
return super.search();
}
}