Skip to content

Instantly share code, notes, and snippets.

Zoltan Altfatter altfatterz

Block or report user

Report or block altfatterz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View infrastructure-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
View repository-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<import resource="infrastructure-config.xml"/>
<jpa:repositories base-package="com.za.spring.fun.repository"/>
View InfrastructureConfig.java
package com.za.spring.fun.config;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
View RepositoryConfig.java
package com.za.spring.fun.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* Java based repository configuration.
*
* @author Zoltan Altfatter
View RepositoryMixConfig.java
package com.za.spring.fun.mixconfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* Java and XML based repository configuration.
*
* @author Zoltan Altfatter
@altfatterz
altfatterz / PercolateTest.java
Last active Dec 22, 2015
addGeoTypeMapping
View PercolateTest.java
private void addGeoTypeMapping() throws IOException {
XContentBuilder mapping = jsonBuilder()
.startObject()
.startObject("household")
.startObject("properties")
.startObject("location")
.field("type", "geo_point")
.endObject()
.endObject()
.endObject()
View PercolateTest.java
private FilterBuilder filterBuilder() {
return boolFilter()
.must(rangeFilter("price").from("250000").to("300000"))
.must(geoDistanceFilter("location")
.point(52.09, 5.11)
.distance(5, DistanceUnit.KILOMETERS)
);
}
View PercolateTest.java
client.prepareIndex("households", "_percolator", "myQuery")
.setSource(jsonBuilder()
.startObject()
.field("query", constantScoreQuery(filterBuilder()))
.field("user_id", "123")
.endObject())
.setRefresh(true) // Needed when the query shall be available immediately
.execute().actionGet();
@altfatterz
altfatterz / PercolateTest.java
Last active Dec 22, 2015
percolate request
View PercolateTest.java
// create a source of the percolate request
XContentBuilder docBuilder = jsonBuilder()
.startObject()
.field("doc")
.startObject()
.startObject("location")
.field("lat", 52.10)
.field("lon", 5.12)
.endObject()
.field("price", 290000)
View Household.java
public class Household {
private String id;
private String description;
private Double lat;
private Double lon;
private int price;
private Date postDate;
}
You can’t perform that action at this time.