![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
de.picturesafe.search:picturesafe-search
Advanced tools
= picturesafe-search
== An Elasticsearch service wrapper
picturesafe-search is a Java service wrapper for the search engine Elasticsearch.
It allows the fast, flexible and easy integration of Elasticsearch functions into new or existing Java applications.
The following features are included:
== Make Elasticsearch queries easy
Elasticsearch is a very powerful search engine, but has a high complexity and requires a long learning curve.
The following example compares the execution of the logical search expression fulltext contains "(test && title)" and count >= 102 sort by id
between the Elasticsearch REST API, the Elasticsearch Java High Level REST Client and the picturesafe-search Java service wrapper:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() .query(QueryBuilders.boolQuery() .must(QueryBuilders.queryStringQuery("test && title") .field("fulltext") .defaultOperator(Operator.AND)) .filter(QueryBuilders.rangeQuery("count").gte(102))) .sort(SortBuilders .fieldSort("id.keyword") .missing("_last") .order(SortOrder.DESC));
As you can see, picturesafe-search focuses more on WHAT to search for than on HOW to search it and abstracts some complexity.
== Getting started
Only a few steps are necessary to get started with a standard configuration. A complete code example can be found https://github.com/picturesafe/picturesafe-search-samples[here]. If you want to create a Spring Boot application, you can alternatively use the https://github.com/picturesafe/picturesafe-search-starter[picturesafe-search Starter].
For more information, please see following https://picturesafe-search.io/docs/[documentation].
=== Start Elasticsearch
picturesafe-search requires a running Elasticsearch server from version 7.x.
==== Local installation of Elasticsearch
For a new application an Elasticsearch server must be installed first:
bin/elasticsearch
on Linux or macOS. Run bin\elasticsearch.bat
on Windows.Some features of picturesafe-search (for example sorting documents in a language-specific word order) require the https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html[ICU Analysis Plugin] for Elasticsearch:
bin/elasticsearch-plugin install analysis-icu
on Linux or macOS. Run bin\elasticsearch-plugin install analysis-icu
on Windows.==== Run Elasticsearch in a Docker container
As an alternative to installing Elasticsearch you can run it in a Docker container. To do this you can use the provided Docker Compose file.
docker-compose -f src/test/docker/docker-compose.yml up -d
from the project directory to start Elasticsearch.docker-compose -f src/test/docker/docker-compose.yml stop
from the project directory.=== Include java library
Add the current version of the picturesafe-search library to your project.
=== Configuration
==== Configuration bean
Implement a configuration class that imports the DefaultElasticConfiguration.class
.
This configuration can be extended later.
The following example defines three fields for the Elasticsearch index:
@Configuration @ComponentScan(basePackages = {"de.picturesafe.search.elasticsearch"}) @Import({DefaultElasticConfiguration.class}) public class Config {
@Bean
List<FieldConfiguration> fieldConfigurations() {
return Arrays.asList(
FieldConfiguration.ID_FIELD,
FieldConfiguration.FULLTEXT_FIELD,
StandardFieldConfiguration.builder(
"title", ElasticsearchType.TEXT).copyToFulltext(true).sortable(true).build(),
StandardFieldConfiguration.builder(
"count", ElasticsearchType.INTEGER).sortable(true).build()
);
}
==== Configuration properties
Add a file elasticsearch.properties
to the classpath of your application and define the following key:
This configuration can be extended later, see src/main/resources/elasticsearch.template.properties
.
==== Service implementation
Inject the SingleIndexElasticsearchService and implement an expression-based search:
OperationExpression
with two termsIf you want to implement searches for more than one index, please use ElasticsearchService
instead of SingleIndexElasticsearchService
.
@Component @ComponentScan public class GettingStarted {
private static final Logger LOGGER = LoggerFactory.getLogger(GettingStarted.class);
@Autowired
private SingleIndexElasticsearchService singleIndexElasticsearchService;
public static void main(String[] args) {
try (AnnotationConfigApplicationContext ctx
= new AnnotationConfigApplicationContext(GettingStarted.class)) {
final GettingStarted gettingStarted = ctx.getBean(GettingStarted.class);
gettingStarted.run();
}
}
private void run() {
try {
singleIndexElasticsearchService.createIndexWithAlias();
singleIndexElasticsearchService
.addToIndex(DataChangeProcessingMode.BLOCKING, Arrays.asList(
DocumentBuilder.id(1).put("title", "This is a test title")
.put("count", 101).build(),
DocumentBuilder.id(2).put("title", "This is another test title")
.put("count", 102).build(),
DocumentBuilder.id(3).put("title", "This is one more test title")
.put("count", 103).build()
));
final Expression expression = OperationExpression.and(
new FulltextExpression("test title"),
new ValueExpression("count", ValueExpression.Comparison.GE, 102));
final SearchResult searchResult = singleIndexElasticsearchService
.search(expression, SearchParameter.DEFAULT);
LOGGER.info(searchResult.toString());
} finally {
singleIndexElasticsearchService.deleteIndexWithAlias();
}
}
With implementations of the picturesafe-search Expression
-Interface complex terms of different search conditions can be easily defined.
Here are some examples:
In addition there are further expressions like InExpression
, MustNotExpression
, RangeValueExpression
, DayExpression
, https://picturesafe-search.io/docs/reference/expressions/[more]
== Building picturesafe-search
If you want to build picturesafe-search yourself there are two prerequisites:
=== JDK
You need to have installed a Java Development Kit. The picturesafe-search project is currently developed using Java 8, but has also been tested on Java 11.
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar (attach-javadocs) on project picturesafe-search: MavenReportException: Error while generating Javadoc:
, please skip generating JavaDoc until the fix has become part of the OpenJDK build you are using.
Alternatively you could use the OpenJDK 11 reference build provided by https://jdk.java.net/java-se-ri/11[Oracle], which has the fix included.
Side note on java modules: +
We are not able to provide a module-info.java
at the moment, because we are using the Elasticsearch high level rest client which has the monolithic
elasticsearch.jar
as dependency. The elasticsearch.jar
has no module-info and it makes auto module detection impossible because of its internal structure.
Please see this https://github.com/elastic/elasticsearch/issues/38299[issue] for details.
=== Apache Maven
You also need to have installed https://maven.apache.org/[Apache Maven] version 3.6.
=== Build
Change to the project directory and run the following command in your shell:
FAQs
Service API for Elasticsearch integration
We found that de.picturesafe.search:picturesafe-search demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.