A library for bootstrapping the development of search applications.
Creates an abstraction layer between the application and the underlying search platform.
tripod-search-api provides a generic API for interacting with a Lucene based search platform.
tripod-search-solr provides a Solr based implementation of the API.
tripod-search-lucene provides a Lucene based implementation of the API.
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-bbende-bbende-maven</id>
<name>bintray</name>
<url>https://dl.bintray.com/bbende/bbende-maven</url>
</repository>
</repositories>
-
Add a Maven dependency ontripod-search-solr:
<dependency> <groupId>com.bbende.tripod</groupId> <artifactId>tripod-search-solr</artifactId> <version>${tripod.version}</version> </dependency>
-
Create an enumeration that defines the available fields and implements the Field interface:
public enum FooField implements Field { ID("id"), TITLE("title); private String fieldName; ExampleField(String fieldName) { this.fieldName = fieldName; } @Override public String getName() { return fieldName; } }
-
Create a domain object that extends QueryResult:
public class Foo extends AbstractQueryResult { private String title; public Foo(String id) { super(Foo.ID, id); } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
-
Create a transformer that takes a SolrDocument and produces the domain object above:
public class FooTransformer implements SolrDocumentTransformer<Foo> { @Override public Foo transform(SolrDocument input) { String id = getString(input, FooField.ID.getName()); String title = getString(input, FooField.TITLE.getName()); Foo foo = new Foo(id); foo.setTitle(title); return foo; } }
-
Create a query service that extends SolrQueryService and uses the transformer above:
public class FooQueryService extends SolrQueryService<Foo> { public FooQueryService(SolrClient solrClient) { super(solrClient, new StandardSolrQueryTransformer(), new FooTransformer()); } }
-
Initialize the query service with the appropriate SolrClient and perform queries:
SolrClient solrClient = ... QueryService<Foo> queryService = new FooQueryService(solrClient); Query query = new Query("id:1"); QueryResults<Foo> results = queryService.search(query);
For additional information see the example in tripod-search-solr/src/test/java.
NOTE: Lucene support is not part of the Tripod 0.1.0 release.
-
Add a Maven dependency on tripod-search-lucene:
<dependency> <groupId>com.bbende.tripod</groupId> <artifactId>tripod-search-lucene</artifactId> <version>${tripod.version}</version> </dependency>
-
Create an enumeration that defines the available fields and implements the Field interface:
public enum FooField implements Field { ID("id"), TITLE("title"), private String fieldName; ExampleField(String fieldName) { this.fieldName = fieldName; } @Override public String getName() { return fieldName; } }
-
Create a SortTypeFactory that defines the sort type for each of the above fields:
public class FooFieldSortTypeFactory implements SortTypeFactory { private static final Map<FooField,SortField.Type> SORT_FIELD_TYPES = new HashMap<>(); static { SORT_FIELD_TYPES.put(ExampleField.ID, SortField.Type.STRING); SORT_FIELD_TYPES.put(ExampleField.TITLE, SortField.Type.STRING); } @Override public SortField.Type getSortType(final Field f) { return SORT_FIELD_TYPES.get(f); } }
-
Create a domain object that extends QueryResult:
public class Foo extends AbstractQueryResult { private String title; public Foo(String id) { super(FooField.ID, id); } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
-
Create a transformer that takes a Lucene Document and produces the domain object above:
public class FooTransformer implements LuceneDocumentTransformer<Foo> { @Override public Foo transform(Document input) { String id = input.get(ExampleField.ID.getName()); String title = input.get(ExampleField.TITLE.getName()); Foo foo = new Foo(id); foo.setTitle(title); return foo; } }
-
Create a query service that extends LuceneQueryService and uses the transformer above:
public FooQueryService(final SearcherManager searcherManager, final String defaultField, final Analyzer analyzer, final FacetsConfig facetsConfig) extends LuceneQueryService<Foo> { super(searcherManager, analyzer, new StandardLuceneQueryTransformer(defaultField, analyzer, facetsConfig), new FooTransformer(), new FooFieldSortTypeFactory()); }
-
Initialize the query service with the appropriate SeacherManager, Analyzer, and default field, and perform queries:
String defaultField = ... Analyzer analyzer = ... SearcherManager searcherManager =... FacetsConfig facetsConfig = ... QueryService<Foo> queryService = new FooQueryService(searcherManager, defaultField, analyzer, facetsConfig); Query query = new Query("id:1"); QueryResults<Foo> results = queryService.search(query);
For additional information see the example in tripod-search-lucene/src/test/java.
mvn release:prepare -DdryRun=true -Pfull,sign -Dgpg.keyname=<your_key>
mvn release:clean
mvn release:prepare -Pfull,sign -Dgpg.keyname=<your_key>
mvn release:perform -Pfull,sign -Dgpg.keyname=<your_key>
git push --all && git push --tags