From d72f50279b7c3b1f33c9101ac48dd03d0d47b075 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Sun, 7 Jul 2024 15:41:24 -0300 Subject: [PATCH] Removing obsolete code, ancient modules and dropped features --- pom.xml | 5 +- querydsl-docs/pom.xml | 2 +- querydsl-examples/pom.xml | 2 +- .../querydsl-example-jpa-guice/pom.xml | 2 +- .../querydsl-example-jpa-quarkus/pom.xml | 2 +- .../querydsl-example-jpa-spring/pom.xml | 2 +- .../querydsl-example-kotlin-codegen/pom.xml | 2 +- .../querydsl-example-kotlin-jpa/pom.xml | 2 +- .../querydsl-example-kotlin-mongodb/pom.xml | 2 +- .../pom.xml | 2 +- .../querydsl-example-sql-guice/pom.xml | 2 +- .../querydsl-example-sql-spring/pom.xml | 2 +- querydsl-libraries/pom.xml | 7 +- .../querydsl-collections/pom.xml | 2 +- querydsl-libraries/querydsl-core/pom.xml | 2 +- .../java/com/querydsl/core/FilterFactory.java | 2 +- .../querydsl/core/MatchingFiltersFactory.java | 107 +-- .../com/querydsl/core/ProjectionsFactory.java | 25 +- .../com/querydsl/core/QuerydslModule.java | 4 - querydsl-libraries/querydsl-guava/pom.xml | 2 +- .../querydsl-hibernate-search/pom.xml | 186 ---- .../hibernate/search/AbstractSearchQuery.java | 172 ---- .../hibernate/search/SearchQuery.java | 48 - .../hibernate/search/SearchSerializer.java | 60 -- .../hibernate/search/package-info.java | 16 - .../hibernate/search/AbstractQueryTest.java | 91 -- .../com/querydsl/hibernate/search/QUser.java | 35 - .../hibernate/search/SearchQueryTest.java | 167 ---- .../search/SearchSerializerTest.java | 29 - .../com/querydsl/hibernate/search/User.java | 90 -- .../src/test/resources/derby.properties | 15 - .../querydsl-jpa-spring/pom.xml | 2 +- querydsl-libraries/querydsl-jpa/pom.xml | 2 +- querydsl-libraries/querydsl-kotlin/pom.xml | 2 +- querydsl-libraries/querydsl-lucene3/README.md | 59 -- querydsl-libraries/querydsl-lucene3/pom.xml | 92 -- .../querydsl/lucene3/AbstractLuceneQuery.java | 365 -------- .../IgnoreCaseUnsupportedException.java | 28 - .../querydsl/lucene3/LuceneExpressions.java | 71 -- .../java/com/querydsl/lucene3/LuceneOps.java | 38 - .../com/querydsl/lucene3/LuceneQuery.java | 54 -- .../querydsl/lucene3/LuceneSerializer.java | 542 ------------ .../com/querydsl/lucene3/PhraseElement.java | 31 - .../com/querydsl/lucene3/QueryElement.java | 32 - .../com/querydsl/lucene3/ResultIterator.java | 84 -- .../com/querydsl/lucene3/TermElement.java | 31 - .../java/com/querydsl/lucene3/TypedQuery.java | 52 -- .../com/querydsl/lucene3/package-info.java | 16 - .../com/querydsl/lucene3/LuceneQueryTest.java | 745 ---------------- .../LuceneSerializerNotTokenizedTest.java | 218 ----- .../lucene3/LuceneSerializerTest.java | 697 --------------- .../java/com/querydsl/lucene3/Person.java | 42 - .../querydsl/lucene3/PhraseElementTest.java | 51 -- .../java/com/querydsl/lucene3/QDocument.java | 35 - .../querydsl/lucene3/QueryElementTest.java | 35 - .../com/querydsl/lucene3/TermElementTest.java | 44 - .../test/resources/log4j.properties.example | 9 - querydsl-libraries/querydsl-lucene4/README.md | 57 -- querydsl-libraries/querydsl-lucene4/pom.xml | 104 --- .../querydsl/lucene4/AbstractLuceneQuery.java | 371 -------- .../IgnoreCaseUnsupportedException.java | 28 - .../querydsl/lucene4/LuceneExpressions.java | 73 -- .../java/com/querydsl/lucene4/LuceneOps.java | 38 - .../com/querydsl/lucene4/LuceneQuery.java | 54 -- .../querydsl/lucene4/LuceneSerializer.java | 553 ------------ .../com/querydsl/lucene4/PhraseElement.java | 31 - .../com/querydsl/lucene4/QueryElement.java | 32 - .../com/querydsl/lucene4/ResultIterator.java | 84 -- .../com/querydsl/lucene4/TermElement.java | 31 - .../java/com/querydsl/lucene4/TypedQuery.java | 52 -- .../com/querydsl/lucene4/package-info.java | 16 - .../com/querydsl/lucene4/LuceneQueryTest.java | 747 ---------------- .../LuceneSerializerNotTokenizedTest.java | 218 ----- .../lucene4/LuceneSerializerTest.java | 718 --------------- .../java/com/querydsl/lucene4/Person.java | 42 - .../querydsl/lucene4/PhraseElementTest.java | 51 -- .../java/com/querydsl/lucene4/QDocument.java | 35 - .../querydsl/lucene4/QueryElementTest.java | 35 - .../com/querydsl/lucene4/TermElementTest.java | 44 - .../test/resources/log4j.properties.example | 9 - querydsl-libraries/querydsl-lucene5/README.md | 57 -- querydsl-libraries/querydsl-lucene5/pom.xml | 104 --- .../querydsl/lucene5/AbstractLuceneQuery.java | 395 --------- .../IgnoreCaseUnsupportedException.java | 28 - .../querydsl/lucene5/LuceneExpressions.java | 73 -- .../java/com/querydsl/lucene5/LuceneOps.java | 38 - .../com/querydsl/lucene5/LuceneQuery.java | 53 -- .../querydsl/lucene5/LuceneSerializer.java | 580 ------------- .../com/querydsl/lucene5/PhraseElement.java | 31 - .../com/querydsl/lucene5/QueryElement.java | 32 - .../com/querydsl/lucene5/ResultIterator.java | 84 -- .../com/querydsl/lucene5/TermElement.java | 31 - .../java/com/querydsl/lucene5/TypedQuery.java | 52 -- .../com/querydsl/lucene5/package-info.java | 16 - .../com/querydsl/lucene5/LuceneQueryTest.java | 820 ------------------ .../LuceneSerializerNotTokenizedTest.java | 218 ----- .../lucene5/LuceneSerializerTest.java | 718 --------------- .../java/com/querydsl/lucene5/Person.java | 42 - .../querydsl/lucene5/PhraseElementTest.java | 51 -- .../java/com/querydsl/lucene5/QDocument.java | 35 - .../querydsl/lucene5/QueryElementTest.java | 35 - .../com/querydsl/lucene5/TermElementTest.java | 44 - .../test/resources/log4j.properties.example | 9 - querydsl-libraries/querydsl-mongodb/pom.xml | 2 +- querydsl-libraries/querydsl-r2dbc/pom.xml | 2 +- .../r2dbc/R2DBCMatchingFiltersFactory.java | 104 ++- querydsl-libraries/querydsl-scala/pom.xml | 2 +- querydsl-libraries/querydsl-spatial/pom.xml | 2 +- .../querydsl-sql-spatial/pom.xml | 2 +- .../querydsl-sql-spring/pom.xml | 2 +- querydsl-libraries/querydsl-sql/pom.xml | 2 +- querydsl-tooling/pom.xml | 2 +- querydsl-tooling/querydsl-apt/pom.xml | 31 +- .../javax.annotation.processing.Processor | 1 - .../javax.annotation.processing.Processor | 1 - .../apt/jdo/JDOAnnotationProcessor.java | 48 - .../querydsl/apt/jdo/JDOConfiguration.java | 128 --- .../com/querydsl/apt/jdo/package-info.java | 16 - .../apt/roo/RooAnnotationProcessor.java | 55 -- .../com/querydsl/apt/roo/package-info.java | 16 - .../querydsl-apt/src/main/jdo.xml | 19 - .../querydsl-apt/src/main/roo.xml | 19 - .../apt/QuerydslAnnotationProcessorTest.java | 52 +- .../java/com/querydsl/apt/domain/JDOTest.java | 67 +- .../com/querydsl/apt/domain/KeywordsTest.java | 8 - .../apt/domain/QueryProjectionTest.java | 2 - .../apt/domain/QuerySuperTypeTest.java | 25 - .../com/querydsl/apt/domain/RooEntities.java | 29 - .../querydsl/apt/domain/RooEntitiesTest.java | 18 - .../querydsl-codegen-utils/pom.xml | 2 +- querydsl-tooling/querydsl-codegen/pom.xml | 2 +- .../java/com/querydsl/codegen/Keywords.java | 29 - .../querydsl/codegen/PropertyHandling.java | 15 - querydsl-tooling/querydsl-jpa-codegen/pom.xml | 2 +- .../querydsl-kotlin-codegen/pom.xml | 2 +- .../querydsl-maven-plugin/pom.xml | 7 +- .../com/querydsl/maven/JDOExporterMojo.java | 42 - .../m2e/lifecycle-mapping-metadata.xml | 1 - .../test/java/com/querydsl/maven/Entity.java | 2 - .../querydsl/maven/JDOExporterMojoTest.java | 27 - querydsl-tooling/querydsl-sql-codegen/pom.xml | 2 +- 141 files changed, 180 insertions(+), 12041 deletions(-) delete mode 100644 querydsl-libraries/querydsl-hibernate-search/pom.xml delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java delete mode 100644 querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties delete mode 100644 querydsl-libraries/querydsl-lucene3/README.md delete mode 100644 querydsl-libraries/querydsl-lucene3/pom.xml delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example delete mode 100644 querydsl-libraries/querydsl-lucene4/README.md delete mode 100644 querydsl-libraries/querydsl-lucene4/pom.xml delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example delete mode 100644 querydsl-libraries/querydsl-lucene5/README.md delete mode 100644 querydsl-libraries/querydsl-lucene5/pom.xml delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java delete mode 100644 querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example delete mode 100644 querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor delete mode 100644 querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor delete mode 100644 querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java delete mode 100644 querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java delete mode 100644 querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java delete mode 100644 querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java delete mode 100644 querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java delete mode 100644 querydsl-tooling/querydsl-apt/src/main/jdo.xml delete mode 100644 querydsl-tooling/querydsl-apt/src/main/roo.xml delete mode 100644 querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java delete mode 100644 querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java delete mode 100644 querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java delete mode 100644 querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java delete mode 100644 querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java diff --git a/pom.xml b/pom.xml index c9001743c8..fcede599e9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.openfeign.querydsl querydsl-root - 6.6-SNAPSHOT + 7.0-SNAPSHOT pom Querydsl @@ -87,6 +87,9 @@ + + true + false UTF-8 http://www.querydsl.com diff --git a/querydsl-docs/pom.xml b/querydsl-docs/pom.xml index 106943bff4..66f4186a73 100644 --- a/querydsl-docs/pom.xml +++ b/querydsl-docs/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-docs diff --git a/querydsl-examples/pom.xml b/querydsl-examples/pom.xml index 2a347dfb98..af8f522795 100644 --- a/querydsl-examples/pom.xml +++ b/querydsl-examples/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-examples diff --git a/querydsl-examples/querydsl-example-jpa-guice/pom.xml b/querydsl-examples/querydsl-example-jpa-guice/pom.xml index e3f4728c46..05dd220e85 100644 --- a/querydsl-examples/querydsl-example-jpa-guice/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-guice/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-guice diff --git a/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml b/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml index 7c1c603916..bf958c0a39 100644 --- a/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-quarkus/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-quarkus diff --git a/querydsl-examples/querydsl-example-jpa-spring/pom.xml b/querydsl-examples/querydsl-example-jpa-spring/pom.xml index 53dc713083..2248421ee3 100755 --- a/querydsl-examples/querydsl-example-jpa-spring/pom.xml +++ b/querydsl-examples/querydsl-example-jpa-spring/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-jpa-spring diff --git a/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml b/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml index 5faaa1e550..6f00c4fbf1 100644 --- a/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-codegen/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin-codegen Querydsl example - Kotlin Codegen diff --git a/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml b/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml index 2d83a65ae3..29cf1084d6 100644 --- a/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-jpa/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin Querydsl example - Kotlin JPA diff --git a/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml b/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml index 13b3f79f66..1df66761f5 100644 --- a/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml +++ b/querydsl-examples/querydsl-example-kotlin-mongodb/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-kotlin-mongodb Querydsl example - Kotlin MongoDB diff --git a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml index 171b8d8954..ff7066be00 100644 --- a/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml +++ b/querydsl-examples/querydsl-example-r2dbc-sql-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-r2dbc-sql-codegen diff --git a/querydsl-examples/querydsl-example-sql-guice/pom.xml b/querydsl-examples/querydsl-example-sql-guice/pom.xml index a0e07ab7ab..c589830370 100644 --- a/querydsl-examples/querydsl-example-sql-guice/pom.xml +++ b/querydsl-examples/querydsl-example-sql-guice/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-sql-guice diff --git a/querydsl-examples/querydsl-example-sql-spring/pom.xml b/querydsl-examples/querydsl-example-sql-spring/pom.xml index 6bd1900295..5229f0d9bc 100644 --- a/querydsl-examples/querydsl-example-sql-spring/pom.xml +++ b/querydsl-examples/querydsl-example-sql-spring/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-examples - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-example-sql-spring diff --git a/querydsl-libraries/pom.xml b/querydsl-libraries/pom.xml index 05035921c4..4fe7e54b8b 100644 --- a/querydsl-libraries/pom.xml +++ b/querydsl-libraries/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-libraries @@ -97,8 +97,6 @@ org.hibernate:hibernate-envers:*:*:compile org.hibernate.validator:hibernate-validator:*:*:compile org.eclipse.persistence:eclipselink:*:*:compile - org.datanucleus:javax.jdo:*:*:compile - org.springframework.roo:org.springframework.roo.annotations:*:*:compile org.mongodb.morphia:morphia:*:*:compile org.joda:joda-money:*:*:compile org.batoo.jpa:batoo-jpa:*:*:compile @@ -111,6 +109,9 @@ jakarta.xml.bind:jakarta.xml.bind-api:*:*:compile javax.*:*:*:*:* + + org.datanucleus:javax.jdo:*:*:* + org.springframework.roo:org.springframework.roo.annotations:*:*:compile org.hsqldb:hsqldb:*:*:compile com.h2database:h2:*:*:compile diff --git a/querydsl-libraries/querydsl-collections/pom.xml b/querydsl-libraries/querydsl-collections/pom.xml index ee6059de32..87c3304c49 100644 --- a/querydsl-libraries/querydsl-collections/pom.xml +++ b/querydsl-libraries/querydsl-collections/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT io.github.openfeign.querydsl diff --git a/querydsl-libraries/querydsl-core/pom.xml b/querydsl-libraries/querydsl-core/pom.xml index 8dc698c3c8..d2a2984917 100644 --- a/querydsl-libraries/querydsl-core/pom.xml +++ b/querydsl-libraries/querydsl-core/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-core diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/FilterFactory.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/FilterFactory.java index 65c31bc4f2..e34119dd9f 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/FilterFactory.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/FilterFactory.java @@ -340,7 +340,7 @@ public Collection string( rv.add(expr.notBetween("A", "Z")); rv.add(expr.notBetween(other, other)); - if (!target.equals(Target.DERBY) && !module.equals(QuerydslModule.JDO)) { + if (!target.equals(Target.DERBY)) { // https://issues.apache.org/jira/browse/DERBY-4389 rv.add(new Coalesce(String.class, expr, other).getValue().eq("xxx")); } diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/MatchingFiltersFactory.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/MatchingFiltersFactory.java index c3cbeb8a56..e1f3c6a9c3 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/MatchingFiltersFactory.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/MatchingFiltersFactory.java @@ -13,8 +13,23 @@ */ package com.querydsl.core; -import com.querydsl.core.types.*; -import com.querydsl.core.types.dsl.*; +import com.querydsl.core.types.CollectionExpression; +import com.querydsl.core.types.Constant; +import com.querydsl.core.types.Expression; +import com.querydsl.core.types.MapExpression; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.ArrayExpression; +import com.querydsl.core.types.dsl.CollectionExpressionBase; +import com.querydsl.core.types.dsl.ComparableExpression; +import com.querydsl.core.types.dsl.DateExpression; +import com.querydsl.core.types.dsl.DateTimeExpression; +import com.querydsl.core.types.dsl.ListExpression; +import com.querydsl.core.types.dsl.ListPath; +import com.querydsl.core.types.dsl.MapExpressionBase; +import com.querydsl.core.types.dsl.NumberExpression; +import com.querydsl.core.types.dsl.SimpleExpression; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.TimeExpression; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -78,7 +93,6 @@ public Collection date( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && !target.equals(Target.FIREBIRD) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { @@ -120,7 +134,6 @@ public Collection dateTime( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { rv.add(expr.dayOfWeek().eq(other.dayOfWeek())); @@ -198,12 +211,10 @@ public > Collection numeric( public Collection string(StringExpression expr, StringExpression other) { HashSet rv = new HashSet(); - if (module != QuerydslModule.LUCENE) { - rv.addAll(comparable(expr, other)); + rv.addAll(comparable(expr, other)); - rv.add(expr.charAt(0).eq(other.charAt(0))); - rv.add(expr.charAt(1).eq(other.charAt(1))); - } + rv.add(expr.charAt(0).eq(other.charAt(0))); + rv.add(expr.charAt(1).eq(other.charAt(1))); rv.add(expr.contains(other)); rv.add(expr.contains(other.substring(0, 1))); @@ -232,58 +243,50 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.eq(other)); rv.add(expr.equalsIgnoreCase(other)); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.indexOf(other).eq(0)); - rv.add(expr.locate(other).eq(1)); - } + rv.add(expr.indexOf(other).eq(0)); + rv.add(expr.locate(other).eq(1)); - if (target != Target.DERBY && module != QuerydslModule.LUCENE) { + if (target != Target.DERBY) { rv.add(expr.indexOf(other.substring(1)).eq(1)); rv.add(expr.indexOf(other.substring(2)).eq(2)); } - if (module != QuerydslModule.LUCENE) { - rv.add(expr.isEmpty().not()); - rv.add(expr.isNotEmpty()); - } + rv.add(expr.isEmpty().not()); + rv.add(expr.isNotEmpty()); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.length().eq(other.length())); - rv.add(expr.like(other)); + rv.add(expr.length().eq(other.length())); + rv.add(expr.like(other)); - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.like(other.substring(0, 1).append("%"))); - rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); - rv.add(expr.like(other.substring(1).prepend("%"))); - rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); - } + if (other instanceof Constant) { + rv.add(expr.like(other.substring(0, 1).append("%"))); + rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); + rv.add(expr.like(other.substring(1).prepend("%"))); + rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); } rv.add(expr.lower().eq(other.lower())); - if (module != QuerydslModule.LUCENE) { - if (!module.equals(QuerydslModule.SQL) - || (!target.equals(Target.HSQLDB) - && !target.equals(Target.FIREBIRD) - && !target.equals(Target.H2) - && !target.equals(Target.DB2) - && !target.equals(Target.DERBY) - && !target.equals(Target.SQLITE) - && !target.equals(Target.SQLSERVER))) { - - rv.add(expr.matches(other)); - - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.matches(other.substring(0, 1).append(".*"))); - rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); - rv.add(expr.matches(other.substring(1).prepend(".*"))); - rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); - } + if (!module.equals(QuerydslModule.SQL) + || (!target.equals(Target.HSQLDB) + && !target.equals(Target.FIREBIRD) + && !target.equals(Target.H2) + && !target.equals(Target.DB2) + && !target.equals(Target.DERBY) + && !target.equals(Target.SQLITE) + && !target.equals(Target.SQLSERVER))) { + + rv.add(expr.matches(other)); + + if (other instanceof Constant) { + rv.add(expr.matches(other.substring(0, 1).append(".*"))); + rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); + rv.add(expr.matches(other.substring(1).prepend(".*"))); + rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); } - - rv.add(expr.ne(other)); } + rv.add(expr.ne(other)); + rv.add(expr.startsWith(other)); rv.add(expr.startsWith(other.substring(0, 1))); rv.add(expr.startsWith(other.substring(0, 2))); @@ -292,13 +295,11 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.startsWithIgnoreCase(other.substring(0, 1))); rv.add(expr.startsWithIgnoreCase(other.substring(0, 2))); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); - rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); - rv.add(expr.substring(1).eq(other.substring(1))); + rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); + rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); + rv.add(expr.substring(1).eq(other.substring(1))); - rv.add(expr.trim().eq(other.trim())); - } + rv.add(expr.trim().eq(other.trim())); rv.add(expr.upper().eq(other.upper())); return Collections.unmodifiableSet(rv); diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java index 31ac3a9ce9..4dc4e8e055 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/ProjectionsFactory.java @@ -17,7 +17,18 @@ import com.querydsl.core.types.Constant; import com.querydsl.core.types.Expression; import com.querydsl.core.types.MapExpression; -import com.querydsl.core.types.dsl.*; +import com.querydsl.core.types.dsl.ArrayExpression; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.core.types.dsl.CollectionExpressionBase; +import com.querydsl.core.types.dsl.DateExpression; +import com.querydsl.core.types.dsl.DateTimeExpression; +import com.querydsl.core.types.dsl.ListExpression; +import com.querydsl.core.types.dsl.ListPath; +import com.querydsl.core.types.dsl.MapExpressionBase; +import com.querydsl.core.types.dsl.NumberExpression; +import com.querydsl.core.types.dsl.SimpleExpression; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.TimeExpression; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -143,9 +154,7 @@ private > Collection> numer rv.add(expr.countDistinct()); } - if (!(other instanceof Constant - || module == QuerydslModule.JDO - || module == QuerydslModule.RDFBEAN)) { + if (!(other instanceof Constant || module == QuerydslModule.RDFBEAN)) { CaseBuilder cases = new CaseBuilder(); rv.add( NumberConstant.create(1) @@ -209,9 +218,7 @@ public Collection> stringProjections( rv.add(expr.substring(1)); rv.add(expr.substring(0, 1)); - if (!(other instanceof Constant - || module == QuerydslModule.JDO - || module == QuerydslModule.RDFBEAN)) { + if (!(other instanceof Constant || module == QuerydslModule.RDFBEAN)) { CaseBuilder cases = new CaseBuilder(); rv.add(cases.when(expr.eq("A")).then(other).when(expr.eq("B")).then(expr).otherwise(other)); @@ -222,9 +229,7 @@ public Collection> stringProjections( rv.add(expr.upper()); - if (module != QuerydslModule.JDO) { - rv.add(expr.nullif("xxx")); - } + rv.add(expr.nullif("xxx")); return Collections.unmodifiableSet(rv); } diff --git a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java index 30cf177219..9b060f4870 100644 --- a/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java +++ b/querydsl-libraries/querydsl-core/src/test/java/com/querydsl/core/QuerydslModule.java @@ -22,11 +22,7 @@ public enum QuerydslModule { /** */ JPA, /** */ - JDO, - /** */ RDFBEAN, /** */ SQL, - /** */ - LUCENE; } diff --git a/querydsl-libraries/querydsl-guava/pom.xml b/querydsl-libraries/querydsl-guava/pom.xml index 41df9d5a87..f272312a5d 100644 --- a/querydsl-libraries/querydsl-guava/pom.xml +++ b/querydsl-libraries/querydsl-guava/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-guava diff --git a/querydsl-libraries/querydsl-hibernate-search/pom.xml b/querydsl-libraries/querydsl-hibernate-search/pom.xml deleted file mode 100644 index 981ef7dc0c..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/pom.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-hibernate-search - Querydsl - Hibernate Search support - Hibernate Search support for querydsl - - - 6.3.1.Final - 8.0.1.Final - 6.2.2.Final - 5.5.5 - org.apache.lucene.*;version="[3.6,4)", - org.hibernate.*;version="[4,5)", - ${osgi.import.package.root} - - - - - - org.apache.lucene - lucene-core - ${lucene.version} - - - org.hibernate.common - hibernate-commons-annotations - 6.0.6.Final - - - - - - - io.github.openfeign.querydsl - querydsl-lucene5 - ${project.version} - - - - - org.hibernate.orm - hibernate-core - ${hibernate.version} - provided - - - asm - asm - - - org.jboss.logging - jboss-logging - - - - - org.hibernate.validator - hibernate-validator - ${hibernate.validator.version} - provided - - - org.jboss.logging - jboss-logging - - - - - - jakarta.persistence - jakarta.persistence-api - 3.1.0 - provided - - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.hibernate.search - hibernate-search-mapper-orm-orm6 - ${hibernate.search.version} - provided - - - hsqldb - hsqldb - - - org.hibernate.orm - hibernate-core - - - org.slf4j - slf4j-api - - - - - javassist - javassist - 3.12.1.GA - provided - - - - - org.apache.derby - derby - ${derby.version} - test - - - org.apache.derby - derbytools - ${derby.version} - test - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - javax.xml.bind - jaxb-api - 2.3.1 - test - - - - jakarta.validation - jakarta.validation-api - test - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.hibernate.search - - - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - - derby.stream.error.file - target/derby.log - - - - - - - - diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java deleted file mode 100644 index 4c5edc8ad7..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/AbstractSearchQuery.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.EntityPath; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Predicate; -import com.querydsl.lucene5.LuceneSerializer; -import java.util.List; -import org.hibernate.Session; -import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory; -import org.hibernate.search.engine.search.query.SearchQuery; -import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep; -import org.hibernate.search.mapper.orm.Search; -import org.hibernate.search.mapper.orm.search.loading.dsl.SearchLoadingOptionsStep; -import org.hibernate.search.mapper.orm.session.SearchSession; - -/** - * Abstract base class for Hibernate Search query classes - * - * @param result type - * @param concrete subtype - */ -public abstract class AbstractSearchQuery> - implements SimpleQuery, Fetchable { - - private final EntityPath path; - - private final QueryMixin queryMixin; - - private final LuceneSerializer serializer; - - private final SearchSession session; - - @SuppressWarnings("unchecked") - public AbstractSearchQuery(SearchSession session, EntityPath path) { - this.queryMixin = new QueryMixin((Q) this); - this.session = session; - this.path = path; - this.serializer = SearchSerializer.DEFAULT; - queryMixin.from(path); - } - - public AbstractSearchQuery(Session session, EntityPath path) { - this(Search.session(session), path); - } - - @Override - public long fetchCount() { - return createQuery(true).fetchTotalHitCount(); - } - - private SearchQuery createQuery(boolean forCount) { - QueryMetadata metadata = queryMixin.getMetadata(); - Class type = (Class) path.getType(); - // org.apache.lucene.search.Query query; - // if (metadata.getWhere() != null) { - // query = serializer.toQuery(metadata.getWhere(), metadata); - // } else { - // query = new MatchAllDocsQuery(); - // } - - // TODO: implement where clause - - SearchQueryOptionsStep queryStep = - session.search(type).where(SearchPredicateFactory::matchAll); - - // TODO: add sorting - // List> orderBy = metadata.getOrderBy(); - // if (!orderBy.isEmpty() && !forCount) { - // fullTextQuery.setSort(serializer.toSort(metadata.getOrderBy())); - // } - return queryStep.toQuery(); - } - - @Override - public Q distinct() { - return queryMixin.distinct(); - } - - @Override - @SuppressWarnings("unchecked") - public CloseableIterator iterate() { - return new IteratorAdapter(fetchAll(createQuery(false)).iterator()); - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @SuppressWarnings("unchecked") - @Override - public List fetch() { - return fetchAll(createQuery(false)); - } - - @SuppressWarnings("unchecked") - @Override - public QueryResults fetchResults() { - SearchQuery query = createQuery(false); - return new QueryResults( - fetchAll(query), queryMixin.getMetadata().getModifiers(), query.fetchTotalHitCount()); - } - - private List fetchAll(SearchQuery query) { - return query.fetchHits( - queryMixin.getMetadata().getModifiers().getOffsetAsInteger(), - queryMixin.getMetadata().getModifiers().getLimitAsInteger()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @Override - public T fetchFirst() { - return limit(1).fetchFirst(); - } - - @SuppressWarnings("unchecked") - @Override - public T fetchOne() throws NonUniqueResultException { - try { - return (T) createQuery(false).fetchSingleHit(); - } catch (org.hibernate.NonUniqueResultException e) { - throw new NonUniqueResultException(e); - } - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java deleted file mode 100644 index 6f17ebf3f2..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchQuery.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import com.querydsl.core.types.EntityPath; -import org.hibernate.Session; -import org.hibernate.search.mapper.orm.Search; -import org.hibernate.search.mapper.orm.session.SearchSession; - -/** - * {@code SearchQuery} is a Query implementation for Hibernate Search - * - * @author tiwe - * @param - */ -public class SearchQuery extends AbstractSearchQuery> { - - /** - * Create a new SearchQuery instance - * - * @param session session - * @param path query source - */ - public SearchQuery(SearchSession session, EntityPath path) { - super(session, path); - } - - /** - * Create a new SearchQuery instance - * - * @param session session - * @param path query source - */ - public SearchQuery(Session session, EntityPath path) { - this(Search.session(session), path); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java deleted file mode 100644 index a8cf5539f5..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/SearchSerializer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import com.querydsl.core.types.Path; -import com.querydsl.lucene5.LuceneSerializer; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; - -/** - * {@code SearchSerializer} extends the {@link LuceneSerializer} to use {@link FullTextField} - * annotation data from paths - * - * @author tiwe - */ -public class SearchSerializer extends LuceneSerializer { - - public static final SearchSerializer DEFAULT = new SearchSerializer(false, true); - - /** - * Create a new SearchSerializer instance - * - * @param lowerCase lowercase names - * @param splitTerms split terms - */ - public SearchSerializer(boolean lowerCase, boolean splitTerms) { - super(lowerCase, splitTerms); - } - - @Override - public String toField(Path path) { - if (path.getAnnotatedElement() != null) { - FullTextField fullTextField = path.getAnnotatedElement().getAnnotation(FullTextField.class); - if (fullTextField != null && fullTextField.name().length() > 0) { - return fullTextField.name(); - } - KeywordField keywordField = path.getAnnotatedElement().getAnnotation(KeywordField.class); - if (keywordField != null && keywordField.name().length() > 0) { - return keywordField.name(); - } - GenericField genericField = path.getAnnotatedElement().getAnnotation(GenericField.class); - if (genericField != null && genericField.name().length() > 0) { - return genericField.name(); - } - } - return super.toField(path); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java b/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java deleted file mode 100644 index 3d00e239e7..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/main/java/com/querydsl/hibernate/search/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** Hibernate Search support */ -package com.querydsl.hibernate.search; diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java deleted file mode 100644 index 063371f552..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/AbstractQueryTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import com.querydsl.core.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.sql.SQLException; -import java.util.List; -import java.util.Properties; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.hibernate.resource.transaction.spi.TransactionStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -public abstract class AbstractQueryTest { - - private static SessionFactory sessionFactory; - - @BeforeClass - public static void setUpClass() throws IOException { - FileUtils.delete(new File("target/derbydb")); - FileUtils.delete(new File("target/lucene3")); - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass(User.class); - Properties props = new Properties(); - try (InputStream is = SearchQueryTest.class.getResourceAsStream("/derby.properties")) { - props.load(is); - } - cfg.setProperties(props); - sessionFactory = cfg.buildSessionFactory(); - } - - @AfterClass - public static void tearDownClass() { - if (sessionFactory != null) { - sessionFactory.close(); - } - } - - private Session session; - - protected Session getSession() { - return session; - } - - @SuppressWarnings("unchecked") - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - - // clean up - List users = session.createQuery("from User").list(); - for (User user : users) { - session.delete(user); - } - session.flush(); - } - - @After - public void tearDown() throws HibernateException, SQLException { - if (session - .getTransaction() - .getStatus() - .isNotOneOf( - TransactionStatus.ROLLED_BACK, - TransactionStatus.ROLLING_BACK, - TransactionStatus.MARKED_ROLLBACK)) { - session.getTransaction().commit(); - } - session.close(); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java deleted file mode 100644 index ed454309ad..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/QUser.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.StringPath; - -public class QUser extends EntityPathBase { - - private static final long serialVersionUID = 8362025864799201294L; - - public QUser(String variable) { - super(User.class, PathMetadataFactory.forVariable(variable)); - } - - public final StringPath emailAddress = createString("emailAddress"); - - public final StringPath firstName = createString("firstName"); - - public final StringPath lastName = createString("lastName"); - - public final StringPath middleName = createString("middleName"); -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java deleted file mode 100644 index acb5a1b7d9..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchQueryTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.dsl.BooleanExpression; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.hibernate.Session; -import org.junit.Ignore; -import org.junit.Test; - -public class SearchQueryTest extends AbstractQueryTest { - - private final QUser user = new QUser("user"); - - @Override - public void setUp() { - super.setUp(); - createUser("Bob", "Stewart", "Smith", "bob@example.com"); - - createUser("Barbara", "X", "Lock", "barbara@a.com"); - createUser("Anton", "X", "Bruckner", "anton@b.com"); - createUser("Robert", "X", "Downing", "bob@c.com"); - createUser("John", "X", "Stewart", "john@d.com"); - - Session session = getSession(); - session.flush(); - session.getTransaction().commit(); - session.beginTransaction(); - } - - @Test - public void exists() { - assertThat(query().where(user.emailAddress.eq("bob@example.com")).fetchCount() > 0).isTrue(); - assertThat(query().where(user.emailAddress.eq("bobby@example.com")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query().where(user.emailAddress.eq("bob@example.com")).fetchCount() == 0).isFalse(); - assertThat(query().where(user.emailAddress.eq("bobby@example.com")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - assertThat(query().where(filter).fetchCount()).isEqualTo(1); - } - - @Test - public void uniqueResult() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - User u = query().where(filter).fetchOne(); - assertThat(u).isNotNull(); - assertThat(u.getEmailAddress()).isEqualTo("bob@example.com"); - } - - @Test - public void list() { - BooleanExpression filter = user.emailAddress.eq("bob@example.com"); - List list = query().where(filter).fetch(); - assertThat(list).hasSize(1); - User u = query().where(filter).fetchOne(); - assertThat(list.getFirst()).isEqualTo(u); - } - - @Test(expected = NonUniqueResultException.class) - public void unique_result_throws_exception_on_multiple_results() { - query().where(user.middleName.eq("X")).fetchOne(); - } - - @Test - public void singleResult() { - assertThat(query().where(user.middleName.eq("X")).fetchFirst()).isNotNull(); - } - - @Test - public void ordering() { - BooleanExpression filter = user.middleName.eq("X"); - // asc - List asc = getFirstNames(query().where(filter).orderBy(user.firstName.asc()).fetch()); - assertThat(asc).isEqualTo(Arrays.asList("Anton", "Barbara", "John", "Robert")); - - // desc - List desc = getFirstNames(query().where(filter).orderBy(user.firstName.desc()).fetch()); - assertThat(desc).isEqualTo(Arrays.asList("Robert", "John", "Barbara", "Anton")); - } - - @Test - public void paging() { - BooleanExpression filter = user.middleName.eq("X"); - OrderSpecifier order = user.firstName.asc(); - - // limit - List limit = getFirstNames(query().where(filter).orderBy(order).limit(2).fetch()); - assertThat(limit).isEqualTo(Arrays.asList("Anton", "Barbara")); - - // offset - List offset = getFirstNames(query().where(filter).orderBy(order).offset(1).fetch()); - assertThat(offset).isEqualTo(Arrays.asList("Barbara", "John", "Robert")); - - // limit + offset - List limitAndOffset = - getFirstNames(query().where(filter).orderBy(order).limit(2).offset(1).fetch()); - assertThat(limitAndOffset).isEqualTo(Arrays.asList("Barbara", "John")); - } - - @Test - public void listResults() { - BooleanExpression filter = user.middleName.eq("X"); - QueryResults users = - query().where(filter).orderBy(user.firstName.asc()).limit(2).fetchResults(); - List asc = getFirstNames(users.getResults()); - assertThat(asc).isEqualTo(Arrays.asList("Anton", "Barbara")); - assertThat(users.getTotal()).isEqualTo(4); - } - - @Test - public void no_where() { - assertThat(query().fetch()).hasSize(5); - } - - @Test - @Ignore // OufOfMemoryError - public void limit_max_value() { - assertThat(query().limit(Long.MAX_VALUE).fetch()).hasSize(5); - } - - private List getFirstNames(List users) { - List rv = new ArrayList(users.size()); - for (User user : users) { - rv.add(user.getFirstName()); - } - return rv; - } - - private User createUser(String firstName, String middleName, String lastName, String email) { - User user = new User(); - user.setFirstName(firstName); - user.setMiddleName(middleName); - user.setLastName(lastName); - user.setEmailAddress(email); - getSession().save(user); - return user; - } - - private SearchQuery query() { - return new SearchQuery(getSession(), user); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java deleted file mode 100644 index 6c2db1097c..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/SearchSerializerTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class SearchSerializerTest { - - @Test - public void toField() { - SearchSerializer serializer = SearchSerializer.DEFAULT; - QUser user = new QUser("user"); - assertThat(serializer.toField(user.emailAddress)).isEqualTo("email"); - assertThat(serializer.toField(user.firstName)).isEqualTo("firstName"); - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java b/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java deleted file mode 100644 index 33497b092e..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/java/com/querydsl/hibernate/search/User.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.hibernate.search; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import java.io.Serializable; -import org.hibernate.annotations.NaturalId; -import org.hibernate.search.engine.backend.types.Projectable; -import org.hibernate.search.engine.backend.types.Searchable; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; -import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; - -@Entity -@Table(name = "user_") -@Indexed -public class User implements Serializable { - - private static final long serialVersionUID = 5955148455600241741L; - - @Id @GeneratedValue @DocumentId private Long id; - - // @SortableField - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String firstName; - - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String lastName; - - @GenericField(searchable = Searchable.YES, projectable = Projectable.YES) - private String middleName; - - @NaturalId - @GenericField(searchable = Searchable.YES, name = "email", projectable = Projectable.YES) - private String emailAddress; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { - this.middleName = middleName; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } -} diff --git a/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties b/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties deleted file mode 100644 index 4d96c12e66..0000000000 --- a/querydsl-libraries/querydsl-hibernate-search/src/test/resources/derby.properties +++ /dev/null @@ -1,15 +0,0 @@ -## Derby -hibernate.dialect=org.hibernate.dialect.DerbyDialect -hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver -hibernate.connection.url=jdbc:derby:target/derbydb;create=true -hibernate.connection.pool_size=0 - -## Common properties -hibernate.show_sql=false -hibernate.flushMode=FLUSH_AUTO -hibernate.hbm2ddl.auto=update - -hibernate.search.default.directory_provider=org.hibernate.search.store.impl.FSDirectoryProvider -hibernate.search.default.indexBase=target/lucene/indexes -hibernate.search.default.batch.merge_factor=10 -hibernate.search.default.batch.max_buffered_docs=10 diff --git a/querydsl-libraries/querydsl-jpa-spring/pom.xml b/querydsl-libraries/querydsl-jpa-spring/pom.xml index 0843764dfe..e0db2211b2 100644 --- a/querydsl-libraries/querydsl-jpa-spring/pom.xml +++ b/querydsl-libraries/querydsl-jpa-spring/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa-spring diff --git a/querydsl-libraries/querydsl-jpa/pom.xml b/querydsl-libraries/querydsl-jpa/pom.xml index 0ba8f25a03..84aeb1f222 100644 --- a/querydsl-libraries/querydsl-jpa/pom.xml +++ b/querydsl-libraries/querydsl-jpa/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa diff --git a/querydsl-libraries/querydsl-kotlin/pom.xml b/querydsl-libraries/querydsl-kotlin/pom.xml index 1a9e2875cc..0285803835 100644 --- a/querydsl-libraries/querydsl-kotlin/pom.xml +++ b/querydsl-libraries/querydsl-kotlin/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-kotlin diff --git a/querydsl-libraries/querydsl-lucene3/README.md b/querydsl-libraries/querydsl-lucene3/README.md deleted file mode 100644 index 898825b003..0000000000 --- a/querydsl-libraries/querydsl-lucene3/README.md +++ /dev/null @@ -1,59 +0,0 @@ -## Querydsl Lucene 3 - -The Lucene module provides integration with the Lucene 3 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : - -```XML - - io.github.openfeign.querydsl - querydsl-lucene3 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); - ``` - -which is transformed into the following Lucene query : - -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene3/pom.xml b/querydsl-libraries/querydsl-lucene3/pom.xml deleted file mode 100644 index 54437d3498..0000000000 --- a/querydsl-libraries/querydsl-lucene3/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene3 - Querydsl - Lucene 3 support - Lucene support for Querydsl - - - 3.6.2 - org.apache.lucene.*;version="[3.6,4)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene3 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java deleted file mode 100644 index ed518222fd..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/AbstractLuceneQuery.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.FieldSelector; -import org.apache.lucene.document.MapFieldSelector; -import org.apache.lucene.search.ChainedFilter; -import org.apache.lucene.search.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of query - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private FieldSelector fieldSelector; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - if (queryMixin.getMetadata().getWhere() == null) { - return new MatchAllDocsQuery(); - } - return serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - - /** - * Create a filter for constraints defined in this query - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - filter = new ChainedFilter(filters.toArray(new Filter[0])); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort).scoreDocs; - } else { - scoreDocs = searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset).scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldSelector, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given FieldSelector to the query - * - * @param fieldSelector field selector - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(FieldSelector fieldSelector) { - this.fieldSelector = fieldSelector; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - List fields = new ArrayList(paths.length); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldSelector = new MapFieldSelector(fields); - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating the - * fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc).scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldSelector != null) { - document = searcher.doc(scoreDocs[index].doc, fieldSelector); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java deleted file mode 100644 index 79bbabed31..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java deleted file mode 100644 index 5539335652..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneExpressions.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param minimumSimilarity a value between 0 and 1 to set the required similarity - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, float minimumSimilarity) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, minimumSimilarity)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param minimumSimilarity a value between 0 and 1 to set the required similarity - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, float minimumSimilarity, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, minimumSimilarity, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java deleted file mode 100644 index cc598e440b..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java deleted file mode 100644 index ead825a659..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneQuery.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- *
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java deleted file mode 100644 index 1fac8516ba..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/LuceneSerializer.java +++ /dev/null @@ -1,542 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.search.*; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, Integer> sortFields = new HashMap, Integer>(); - - static { - sortFields.put(Integer.class, SortField.INT); - sortFields.put(Float.class, SortField.FLOAT); - sortFields.put(Long.class, SortField.LONG); - sortFields.put(Double.class, SortField.DOUBLE); - sortFields.put(Short.class, SortField.SHORT); - sortFields.put(Byte.class, SortField.BYTE); - sortFields.put(BigDecimal.class, SortField.DOUBLE); - sortFields.put(BigInteger.class, SortField.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") // This is the expected type - Query rv = ((Constant) operation.getArg(0)).getConstant(); - return rv; - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private String convertNumber(Number number) { - if (Integer.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (Double.class.isInstance(number)) { - return NumericUtils.doubleToPrefixCoded(number.doubleValue()); - } else if (Long.class.isInstance(number)) { - return NumericUtils.longToPrefixCoded(number.longValue()); - } else if (Float.class.isInstance(number)) { - return NumericUtils.floatToPrefixCoded(number.floatValue()); - } else if (Byte.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (Short.class.isInstance(number)) { - return NumericUtils.intToPrefixCoded(number.intValue()); - } else if (BigDecimal.class.isInstance(number)) { - return NumericUtils.doubleToPrefixCoded(number.doubleValue()); - } else if (BigInteger.class.isInstance(number)) { - return NumericUtils.longToPrefixCoded(number.longValue()); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") // This is the second argument type - Constant> collConstant = (Constant>) operation.getArg(1); - Collection values = collConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return new TermRangeQuery( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return new TermRangeQuery( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return new TermRangeQuery( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), sortLocale, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java deleted file mode 100644 index f0e855cbc0..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java deleted file mode 100644 index 340312ec27..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java deleted file mode 100644 index 30ed43dd7e..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.FieldSelector; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final FieldSelector fieldSelector; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable FieldSelector fieldSelector, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldSelector = fieldSelector; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldSelector != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldSelector); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java deleted file mode 100644 index e4b6b13adc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java deleted file mode 100644 index 76baca5cc7..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index search - * @param transformer transformer to transform documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java b/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java deleted file mode 100644 index 777d96cb34..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/main/java/com/querydsl/lucene3/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** Lucene 3 support */ -package com.querydsl.lucene3; diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java deleted file mode 100644 index 53d01d745f..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneQueryTest.java +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.*; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.MapFieldSelector; -import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - final Document doc = new Document(); - - doc.add(new Field("title", docTitle, Store.YES, Index.ANALYZED)); - doc.add(new Field("author", docAuthor, Store.YES, Index.ANALYZED)); - doc.add(new Field("text", docText, Store.YES, Index.ANALYZED)); - doc.add(new NumericField("year", Store.YES, true).setIntValue(docYear)); - doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(docGross)); - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new Field("sort", "a\u00c4", Store.YES, Index.NOT_ANALYZED)); - d2.add(new Field("sort", "ab", Store.YES, Index.NOT_ANALYZED)); - d3.add(new Field("sort", "aa", Store.YES, Index.NOT_ANALYZED)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getFieldable("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getFieldable("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getFieldable("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getFieldable("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getFieldable("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getFieldable("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(new MapFieldSelector("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(new MapFieldSelector("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 718e2edf97..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static com.querydsl.lucene3.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java deleted file mode 100644 index b46810dda3..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/LuceneSerializerTest.java +++ /dev/null @@ -1,697 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.junit.jupiter.api.Assertions.*; - -import com.querydsl.core.*; -import com.querydsl.core.types.*; -import com.querydsl.core.types.dsl.*; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.NumericUtils; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = NumericUtils.intToPrefixCoded(1990); - private static final String GROSS_PREFIX_CODED = NumericUtils.doubleToPrefixCoded(900.00); - private static final String LONG_PREFIX_CODED = NumericUtils.longToPrefixCoded(1); - private static final String SHORT_PREFIX_CODED = NumericUtils.intToPrefixCoded(1); - private static final String BYTE_PREFIX_CODED = NumericUtils.intToPrefixCoded(1); - private static final String FLOAT_PREFIX_CODED = NumericUtils.floatToPrefixCoded((float) 1.0); - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new NumericField("year", Store.YES, true).setIntValue(1990)); - doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(900.00)); - - doc.add(new NumericField("longField", Store.YES, true).setLongValue(1)); - doc.add(new NumericField("shortField", Store.YES, true).setIntValue(1)); - doc.add(new NumericField("byteField", Store.YES, true).setIntValue(1)); - doc.add(new NumericField("floatField", Store.YES, true).setFloatValue(1)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~0.5", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f), "rating:Good~0.6", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 0.6f, 0), "rating:Good~0.6", 1); - } - - @Test - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java deleted file mode 100644 index 98b5b9091b..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java deleted file mode 100644 index 0fa6f92014..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java deleted file mode 100644 index 84c11ce8fc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java deleted file mode 100644 index 74ede9c968..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java b/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java deleted file mode 100644 index ca879526a7..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/java/com/querydsl/lucene3/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene3; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example deleted file mode 100644 index 0c3a1143dc..0000000000 --- a/querydsl-libraries/querydsl-lucene3/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene3=DEBUG diff --git a/querydsl-libraries/querydsl-lucene4/README.md b/querydsl-libraries/querydsl-lucene4/README.md deleted file mode 100644 index 60e5c75742..0000000000 --- a/querydsl-libraries/querydsl-lucene4/README.md +++ /dev/null @@ -1,57 +0,0 @@ -## Querydsl Lucene 4 - -The Lucene module provides integration with the Lucene 4 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : -```XML - - io.github.openfeign.querydsl - querydsl-lucene4 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); -``` - -which is transformed into the following Lucene query : -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene4/pom.xml b/querydsl-libraries/querydsl-lucene4/pom.xml deleted file mode 100644 index 257682d532..0000000000 --- a/querydsl-libraries/querydsl-lucene4/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene4 - Querydsl - Lucene 4 support - Lucene support for Querydsl - - - 4.10.4 - org.apache.lucene.*;version="[4,5)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-analyzers-common - ${lucene.version} - provided - - - org.apache.lucene - lucene-queryparser - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene4 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java deleted file mode 100644 index 9f409722ad..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/AbstractLuceneQuery.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.queries.ChainedFilter; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of querydsl - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private Set fieldsToLoad; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.getIndexReader().maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - if (queryMixin.getMetadata().getWhere() == null) { - return new MatchAllDocsQuery(); - } - return serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - - /** - * Create a filter for constraints defined in this querydsl - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - filter = new ChainedFilter(filters.toArray(new Filter[0])); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search(createQuery(), getFilter(), sumOfLimitAndOffset, sort, false, false) - .scoreDocs; - } else { - scoreDocs = - searcher.search( - createQuery(), getFilter(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false) - .scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldsToLoad, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given fields to load - * - * @param fieldsToLoad fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Set fieldsToLoad) { - this.fieldsToLoad = fieldsToLoad; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - Set fields = new HashSet(); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldsToLoad = fields; - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating the - * fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = - searcher.search(createQuery(), getFilter(), maxDoc, Sort.INDEXORDER, false, false) - .scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[index].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.getIndexReader().maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java deleted file mode 100644 index 6a33cff01f..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java deleted file mode 100644 index e8054f82a0..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneExpressions.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.util.automaton.LevenshteinAutomata; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value, int maxEdits) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, int maxEdits, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java deleted file mode 100644 index d11f3d01a5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java deleted file mode 100644 index 5e9ad57d1c..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneQuery.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- *
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java deleted file mode 100644 index 8fe0919519..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/LuceneSerializer.java +++ /dev/null @@ -1,553 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryparser.classic.QueryParser; -import org.apache.lucene.search.*; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, SortField.Type> sortFields = - new HashMap, SortField.Type>(); - - static { - sortFields.put(Integer.class, SortField.Type.INT); - sortFields.put(Float.class, SortField.Type.FLOAT); - sortFields.put(Long.class, SortField.Type.LONG); - sortFields.put(Double.class, SortField.Type.DOUBLE); - sortFields.put(Short.class, SortField.Type.SHORT); - sortFields.put(Byte.class, SortField.Type.BYTE); - sortFields.put(BigDecimal.class, SortField.Type.DOUBLE); - sortFields.put(BigInteger.class, SortField.Type.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") // this is the expected type - Constant expectedConstant = (Constant) operation.getArg(0); - return expectedConstant.getConstant(); - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private BytesRef convertNumber(Number number) { - if (Integer.class.isInstance(number) - || Byte.class.isInstance(number) - || Short.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_INT); - NumericUtils.intToPrefixCoded(number.intValue(), 0, bytes); - return bytes.toBytesRef(); - } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_LONG); - long l = NumericUtils.doubleToSortableLong(number.doubleValue()); - NumericUtils.longToPrefixCoded(l, 0, bytes); - return bytes.toBytesRef(); - } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_LONG); - NumericUtils.longToPrefixCoded(number.longValue(), 0, bytes); - return bytes.toBytesRef(); - } else if (Float.class.isInstance(number)) { - BytesRefBuilder bytes = new BytesRefBuilder(); - bytes.setLength(NumericUtils.BUF_SIZE_INT); - int i = NumericUtils.floatToSortableInt(number.floatValue()); - NumericUtils.intToPrefixCoded(i, 0, bytes); - return bytes.toBytesRef(); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") // this is the expected type - Constant> expectedConstant = (Constant>) operation.getArg(1); - Collection values = expectedConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return TermRangeQuery.newStringRange( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return TermRangeQuery.newStringRange( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return TermRangeQuery.newStringRange( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java deleted file mode 100644 index 16a7e8c13b..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java deleted file mode 100644 index 141c8ede51..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java deleted file mode 100644 index c2b76d06a3..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final Set fieldsToLoad; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable Set fieldsToLoad, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldsToLoad = fieldsToLoad; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java deleted file mode 100644 index edf055d37e..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java deleted file mode 100644 index 0809eefe34..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java b/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java deleted file mode 100644 index e4fa5fc679..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/main/java/com/querydsl/lucene4/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** Lucene 4 support */ -package com.querydsl.lucene4; diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java deleted file mode 100644 index ac02ce1acf..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneQueryTest.java +++ /dev/null @@ -1,747 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.*; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.*; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - final Document doc = new Document(); - - doc.add(new TextField("title", docTitle, Store.YES)); - doc.add(new TextField("author", docAuthor, Store.YES)); - doc.add(new TextField("text", docText, Store.YES)); - doc.add(new IntField("year", docYear, Store.YES)); - doc.add(new DoubleField("gross", docGross, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_42)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - @Ignore - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - @Ignore // FIXME - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new Field("sort", "a\u00c4", Store.YES, Index.NOT_ANALYZED)); - d2.add(new Field("sort", "ab", Store.YES, Index.NOT_ANALYZED)); - d3.add(new Field("sort", "aa", Store.YES, Index.NOT_ANALYZED)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(Collections.singleton("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(Collections.singleton("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - @Ignore - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - @Ignore - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - @Ignore - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 4f5ac8c122..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static com.querydsl.lucene4.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java deleted file mode 100644 index c3214f66e5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/LuceneSerializerTest.java +++ /dev/null @@ -1,718 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.MatchingFiltersFactory; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QuerydslModule; -import com.querydsl.core.StringConstant; -import com.querydsl.core.Target; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.CollectionPath; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.PathBuilder; -import com.querydsl.core.types.dsl.StringPath; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.FloatField; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.LongField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.Version; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = ""; - private static final String GROSS_PREFIX_CODED = ""; - private static final String LONG_PREFIX_CODED = ""; - private static final String SHORT_PREFIX_CODED = ""; - private static final String BYTE_PREFIX_CODED = ""; - private static final String FLOAT_PREFIX_CODED = ""; - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new IntField("year", 1990, Store.YES)); - doc.add(new DoubleField("gross", 900.0, Store.YES)); - - doc.add(new LongField("longField", 1, Store.YES)); - doc.add(new IntField("shortField", 1, Store.YES)); - doc.add(new IntField("byteField", 1, Store.YES)); - doc.add(new FloatField("floatField", 1, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(Version.LUCENE_42, new StandardAnalyzer(Version.LUCENE_42)) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = IndexReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2, 0), "rating:Good~2", 1); - } - - @Test - @Ignore - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java deleted file mode 100644 index d201e3c2b5..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java deleted file mode 100644 index 7c94e762cc..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java deleted file mode 100644 index e55c66f386..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java deleted file mode 100644 index 0049bd96be..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java b/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java deleted file mode 100644 index f552069711..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/java/com/querydsl/lucene4/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene4; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example deleted file mode 100644 index 50eef686c1..0000000000 --- a/querydsl-libraries/querydsl-lucene4/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene4=DEBUG diff --git a/querydsl-libraries/querydsl-lucene5/README.md b/querydsl-libraries/querydsl-lucene5/README.md deleted file mode 100644 index 3bcd908515..0000000000 --- a/querydsl-libraries/querydsl-lucene5/README.md +++ /dev/null @@ -1,57 +0,0 @@ -## Querydsl Lucene 5 - -The Lucene module provides integration with the Lucene 5 indexing library. - -**Maven integration** - - Add the following dependencies to your Maven project : -```XML - - io.github.openfeign.querydsl - querydsl-lucene5 - ${querydsl.version} - -``` - -**Creating the query types** - -With fields year and title a manually created query type could look something like this: - -```JAVA -public class QDocument extends EntityPathBase{ - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final StringPath year = createString("year"); - - public final StringPath title = createString("title"); -} -``` - -QDocument represents a Lucene document with the fields year and title. - -Code generation is not available for Lucene, since no schema data is available. - -**Querying** - -Querying with Querydsl Lucene is as simple as this: - -```JAVA -QDocument doc = new QDocument("doc"); - -IndexSearcher searcher = new IndexSearcher(index); -LuceneQuery query = new LuceneQuery(true, searcher); -List documents = query - .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle")) - .fetch(); -``` - -which is transformed into the following Lucene query : -``` -+year:[1800 TO 2000] +title:huckle* -``` - -For more information on the Querydsl Lucene module visit the reference documentation http://www.querydsl.com/static/querydsl/latest/reference/html/ch02s05.html diff --git a/querydsl-libraries/querydsl-lucene5/pom.xml b/querydsl-libraries/querydsl-lucene5/pom.xml deleted file mode 100644 index 53134d5322..0000000000 --- a/querydsl-libraries/querydsl-lucene5/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - - io.github.openfeign.querydsl - querydsl-libraries - 6.0-SNAPSHOT - - - querydsl-lucene5 - Querydsl - Lucene 5 support - Lucene support for Querydsl - - - 5.5.5 - org.apache.lucene.*;version="[5.1.0,6)", - ${osgi.import.package.root} - - - - - org.jetbrains - annotations - provided - - - org.apache.lucene - lucene-core - ${lucene.version} - provided - - - org.apache.lucene - lucene-analyzers-common - ${lucene.version} - provided - - - org.apache.lucene - lucene-queryparser - ${lucene.version} - provided - - - org.apache.lucene - lucene-queries - ${lucene.version} - provided - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - - - - - io.github.openfeign.querydsl - querydsl-core - ${project.version} - test-jar - test - - - - io.github.openfeign.querydsl - querydsl-apt - ${project.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - com.querydsl.lucene5 - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - com.querydsl.apt.QuerydslAnnotationProcessor - - - - - - diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java deleted file mode 100644 index 1a9159f651..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/AbstractLuceneQuery.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.commons.lang.EmptyCloseableIterator; -import com.mysema.commons.lang.IteratorAdapter; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.Fetchable; -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.SimpleQuery; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Predicate; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TotalHitCountCollector; -import org.jetbrains.annotations.Nullable; - -/** - * AbstractLuceneQuery is an abstract super class for Lucene query implementations - * - * @author tiwe - * @param projection type - * @param concrete subtype of querydsl - */ -public abstract class AbstractLuceneQuery> - implements SimpleQuery, Fetchable { - - private static final String JAVA_ISO_CONTROL = "[\\p{Cntrl}&&[^\r\n\t]]"; - - private final QueryMixin queryMixin; - - private final IndexSearcher searcher; - - private final LuceneSerializer serializer; - - private final Function transformer; - - @Nullable private Set fieldsToLoad; - - private List filters = Collections.emptyList(); - - @Nullable private Filter filter; - - @Nullable private Sort querySort; - - @SuppressWarnings("unchecked") - public AbstractLuceneQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - queryMixin = new QueryMixin((Q) this, new DefaultQueryMetadata()); - this.serializer = serializer; - this.searcher = searcher; - this.transformer = transformer; - } - - public AbstractLuceneQuery(IndexSearcher searcher, Function transformer) { - this(LuceneSerializer.DEFAULT, searcher, transformer); - } - - private long innerCount() { - try { - final int maxDoc = searcher.getIndexReader().maxDoc(); - if (maxDoc == 0) { - return 0; - } - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(createQuery(), getFilter(), collector); - return collector.getTotalHits(); - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public long fetchCount() { - return innerCount(); - } - - protected Query createQuery() { - Query returnedQuery = null; - Query originalQuery = null; - if (queryMixin.getMetadata().getWhere() == null) { - originalQuery = new MatchAllDocsQuery(); - } else { - originalQuery = - serializer.toQuery(queryMixin.getMetadata().getWhere(), queryMixin.getMetadata()); - } - Filter filter = getFilter(); - if (filter != null) { - BooleanQuery booleanQuery = new BooleanQuery(); - booleanQuery.add(originalQuery, Occur.MUST); - booleanQuery.add(filter, Occur.FILTER); - returnedQuery = booleanQuery; - } else { - returnedQuery = originalQuery; - } - - return returnedQuery; - } - - /** - * Create a filter for constraints defined in this querydsl - * - * @return filter - */ - public Filter asFilter() { - return new QueryWrapperFilter(createQuery()); - } - - @Override - public Q distinct() { - throw new UnsupportedOperationException("use distinct(path) instead"); - } - - /** - * Add a DuplicateFilter for the field of the given property path - * - * @param property distinct property - * @return the current object - */ - public Q distinct(Path property) { - return filter(new DuplicateFilter(serializer.toField(property))); - } - - /** - * Apply the given Lucene filter to the search results - * - * @param filter filter - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q filter(Filter filter) { - if (filters.isEmpty()) { - this.filter = filter; - filters = Collections.singletonList(filter); - } else { - this.filter = null; - if (filters.size() == 1) { - filters = new ArrayList(); - } - filters.add(filter); - } - return (Q) this; - } - - private Filter getFilter() { - if (filter == null && !filters.isEmpty()) { - BooleanQuery filterQuery = new BooleanQuery(); - for (Filter filter : filters) { - filterQuery.add(filter, Occur.SHOULD); - } - filter = new QueryWrapperFilter(filterQuery); - } - return filter; - } - - @Override - public Q limit(long limit) { - return queryMixin.limit(limit); - } - - @Override - public CloseableIterator iterate() { - final QueryMetadata metadata = queryMixin.getMetadata(); - final List> orderBys = metadata.getOrderBy(); - final Integer queryLimit = metadata.getModifiers().getLimitAsInteger(); - final Integer queryOffset = metadata.getModifiers().getOffsetAsInteger(); - Sort sort = querySort; - int limit; - final int offset = queryOffset != null ? queryOffset : 0; - try { - limit = maxDoc(); - if (limit == 0) { - return new EmptyCloseableIterator(); - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - if (queryLimit != null && queryLimit < limit) { - limit = queryLimit; - } - if (sort == null && !orderBys.isEmpty()) { - sort = serializer.toSort(orderBys); - } - - try { - ScoreDoc[] scoreDocs; - int sumOfLimitAndOffset = limit + offset; - if (sumOfLimitAndOffset < 1) { - throw new QueryException( - "The given limit (" - + limit - + ") and offset (" - + offset - + ") cause an integer overflow."); - } - if (sort != null) { - scoreDocs = - searcher.search( - createQuery(), - // sumOfLimitAndOffset).scoreDocs; - sumOfLimitAndOffset, - sort, - false, - false) - .scoreDocs; - } else { - scoreDocs = - searcher.search(createQuery(), sumOfLimitAndOffset, Sort.INDEXORDER, false, false) - .scoreDocs; - } - if (offset < scoreDocs.length) { - return new ResultIterator(scoreDocs, offset, searcher, fieldsToLoad, transformer); - } - return new EmptyCloseableIterator(); - } catch (final IOException e) { - throw new QueryException(e); - } - } - - private List innerList() { - return new IteratorAdapter(iterate()).asList(); - } - - @Override - public List fetch() { - return innerList(); - } - - /** - * Set the given fields to load - * - * @param fieldsToLoad fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Set fieldsToLoad) { - this.fieldsToLoad = fieldsToLoad; - return (Q) this; - } - - /** - * Load only the fields of the given paths - * - * @param paths fields to load - * @return the current object - */ - @SuppressWarnings("unchecked") - public Q load(Path... paths) { - Set fields = new HashSet(); - for (Path path : paths) { - fields.add(serializer.toField(path)); - } - this.fieldsToLoad = fields; - return (Q) this; - } - - @Override - public QueryResults fetchResults() { - List documents = innerList(); - /* - * TODO Get rid of fetchCount(). It could be implemented by iterating - * the fetch results in fetch* from n to m. - */ - return new QueryResults(documents, queryMixin.getMetadata().getModifiers(), innerCount()); - } - - @Override - public Q offset(long offset) { - return queryMixin.offset(offset); - } - - public Q orderBy(OrderSpecifier o) { - return queryMixin.orderBy(o); - } - - @Override - public Q orderBy(OrderSpecifier... o) { - return queryMixin.orderBy(o); - } - - @Override - public Q restrict(QueryModifiers modifiers) { - return queryMixin.restrict(modifiers); - } - - @Override - public

Q set(ParamExpression

param, P value) { - return queryMixin.set(param, value); - } - - @SuppressWarnings("unchecked") - public Q sort(Sort sort) { - this.querySort = sort; - return (Q) this; - } - - @Nullable - private T oneResult(boolean unique) { - try { - int maxDoc = maxDoc(); - if (maxDoc == 0) { - return null; - } - final ScoreDoc[] scoreDocs = - searcher.search(createQuery(), maxDoc, Sort.INDEXORDER, false, false).scoreDocs; - int index = 0; - QueryModifiers modifiers = queryMixin.getMetadata().getModifiers(); - Long offset = modifiers.getOffset(); - if (offset != null) { - index = offset.intValue(); - } - Long limit = modifiers.getLimit(); - if (unique - && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) { - throw new NonUniqueResultException( - "Unique result requested, but " + scoreDocs.length + " found."); - } else if (scoreDocs.length > index) { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[index].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[index].doc); - } - return transformer.apply(document); - } else { - return null; - } - } catch (IOException | IllegalArgumentException e) { - throw new QueryException(e); - } - } - - @Override - public T fetchFirst() { - return oneResult(false); - } - - @Override - public T fetchOne() throws NonUniqueResultException { - return oneResult(true); - } - - public Q where(Predicate e) { - return queryMixin.where(e); - } - - @Override - public Q where(Predicate... e) { - return queryMixin.where(e); - } - - @Override - public String toString() { - return createQuery().toString().replaceAll(JAVA_ISO_CONTROL, "_"); - } - - private int maxDoc() throws IOException { - return searcher.getIndexReader().maxDoc(); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java deleted file mode 100644 index de7c597b38..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/IgnoreCaseUnsupportedException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -/** - * Thrown for case ignore usage - * - * @author tiwe - */ -public class IgnoreCaseUnsupportedException extends UnsupportedOperationException { - - private static final long serialVersionUID = 412913389929530788L; - - public IgnoreCaseUnsupportedException() { - super("Ignore case queries are not supported with Lucene"); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java deleted file mode 100644 index a1bc496729..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneExpressions.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.BooleanExpression; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.util.automaton.LevenshteinAutomata; - -/** - * Utility methods to create filter expressions for Lucene queries that are not covered by the - * Querydsl standard expression model - * - * @author tiwe - */ -public final class LuceneExpressions { - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @return condition - */ - public static BooleanExpression fuzzyLike(Path path, String value, int maxEdits) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits)); - } - - /** - * Create a fuzzy query - * - * @param path path - * @param value value to match - * @param maxEdits must be >= 0 and <= {@link - * LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @param prefixLength length of common (non-fuzzy) prefix - * @return condition - */ - public static BooleanExpression fuzzyLike( - Path path, String value, int maxEdits, int prefixLength) { - Term term = new Term(path.getMetadata().getName(), value); - return new QueryElement(new FuzzyQuery(term, maxEdits, prefixLength)); - } - - private LuceneExpressions() {} -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java deleted file mode 100644 index 375316fe25..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneOps.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.Operator; - -/** - * Lucene specific operators - * - * @author tiwe - */ -public enum LuceneOps implements Operator { - LUCENE_QUERY(Object.class), - PHRASE(String.class), - TERM(String.class); - - private final Class type; - - LuceneOps(Class type) { - this.type = type; - } - - @Override - public Class getType() { - return type; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java deleted file mode 100644 index 9c7fa0431c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneQuery.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code LuceneQuery} is a Querydsl query implementation for Lucene queries. - * - *

Example: - * - *

{@code
- * QDocument doc = new QDocument("doc");
- * IndexSearcher searcher = new IndexSearcher(index);
- * LuceneQuery query = new LuceneQuery(true, searcher);
- * List documents = query
- *     .where(doc.year.between("1800", "2000").and(doc.title.startsWith("Huckle"))
- *     .fetch();
- * }
- * - * @author vema - */ -public class LuceneQuery extends AbstractLuceneQuery { - - private static final Function TRANSFORMER = - new Function() { - @Override - public Document apply(Document input) { - return input; - } - }; - - public LuceneQuery(IndexSearcher searcher) { - super(searcher, TRANSFORMER); - } - - public LuceneQuery(LuceneSerializer luceneSerializer, IndexSearcher searcher) { - super(luceneSerializer, searcher, TRANSFORMER); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java deleted file mode 100644 index 2601e07f8a..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/LuceneSerializer.java +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Constant; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.ExpressionUtils; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.PathMetadata; -import com.querydsl.core.types.PathType; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryparser.classic.QueryParser; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.NumericRangeQuery; -import org.apache.lucene.search.PhraseQuery; -import org.apache.lucene.search.PrefixQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.SortField; -import org.apache.lucene.search.SortedNumericSortField; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.TermRangeQuery; -import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.NumericUtils; -import org.jetbrains.annotations.Nullable; - -/** - * Serializes Querydsl queries to Lucene queries. - * - * @author vema - */ -public class LuceneSerializer { - private static final Map, SortField.Type> sortFields = - new HashMap, SortField.Type>(); - - static { - sortFields.put(Integer.class, SortField.Type.INT); - sortFields.put(Float.class, SortField.Type.FLOAT); - sortFields.put(Long.class, SortField.Type.LONG); - sortFields.put(Double.class, SortField.Type.DOUBLE); - sortFields.put(BigDecimal.class, SortField.Type.DOUBLE); - sortFields.put(BigInteger.class, SortField.Type.LONG); - } - - public static final LuceneSerializer DEFAULT = new LuceneSerializer(false, true); - - private final boolean lowerCase; - - private final boolean splitTerms; - - private final Locale sortLocale; - - public LuceneSerializer(boolean lowerCase, boolean splitTerms) { - this(lowerCase, splitTerms, Locale.getDefault()); - } - - public LuceneSerializer(boolean lowerCase, boolean splitTerms, Locale sortLocale) { - this.lowerCase = lowerCase; - this.splitTerms = splitTerms; - this.sortLocale = sortLocale; - } - - private Query toQuery(Operation operation, QueryMetadata metadata) { - Operator op = operation.getOperator(); - if (op == Ops.OR) { - return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata); - } else if (op == Ops.AND) { - return toTwoHandSidedQuery(operation, Occur.MUST, metadata); - } else if (op == Ops.NOT) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } else if (op == Ops.LIKE) { - return like(operation, metadata); - } else if (op == Ops.LIKE_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.EQ) { - return eq(operation, metadata, false); - } else if (op == Ops.EQ_IGNORE_CASE) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.NE) { - return ne(operation, metadata, false); - } else if (op == Ops.STARTS_WITH) { - return startsWith(metadata, operation, false); - } else if (op == Ops.STARTS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.ENDS_WITH) { - return endsWith(operation, metadata, false); - } else if (op == Ops.ENDS_WITH_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.STRING_CONTAINS) { - return stringContains(operation, metadata, false); - } else if (op == Ops.STRING_CONTAINS_IC) { - throw new IgnoreCaseUnsupportedException(); - } else if (op == Ops.BETWEEN) { - return between(operation, metadata); - } else if (op == Ops.IN) { - return in(operation, metadata, false); - } else if (op == Ops.NOT_IN) { - return notIn(operation, metadata, false); - } else if (op == Ops.LT) { - return lt(operation, metadata); - } else if (op == Ops.GT) { - return gt(operation, metadata); - } else if (op == Ops.LOE) { - return le(operation, metadata); - } else if (op == Ops.GOE) { - return ge(operation, metadata); - } else if (op == LuceneOps.LUCENE_QUERY) { - @SuppressWarnings("unchecked") - // this is the expected type - Constant expectedConstant = (Constant) operation.getArg(0); - return expectedConstant.getConstant(); - } - throw new UnsupportedOperationException("Illegal operation " + operation); - } - - private Query toTwoHandSidedQuery(Operation operation, Occur occur, QueryMetadata metadata) { - Query lhs = toQuery(operation.getArg(0), metadata); - Query rhs = toQuery(operation.getArg(1), metadata); - BooleanQuery bq = new BooleanQuery(); - bq.add(createBooleanClause(lhs, occur)); - bq.add(createBooleanClause(rhs, occur)); - return bq; - } - - /** - * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT clause it will be - * returned as is. Otherwise it will be wrapped in a BooleanClause with the given Occur. - */ - private BooleanClause createBooleanClause(Query query, Occur occur) { - if (query instanceof BooleanQuery) { - BooleanClause[] clauses = ((BooleanQuery) query).getClauses(); - if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) { - return clauses[0]; - } - } - return new BooleanClause(query, occur); - } - - protected Query like(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convert(path, operation.getArg(1)); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, terms[0])); - } - - protected Query eq(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - - if (Number.class.isAssignableFrom(operation.getArg(1).getType())) { - @SuppressWarnings("unchecked") - // guarded by previous check - Constant rightArg = (Constant) operation.getArg(1); - return new TermQuery(new Term(field, convertNumber(rightArg.getConstant()))); - } - - return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase); - } - - private BytesRef convertNumber(Number number) { - if (Integer.class.isInstance(number) - || Byte.class.isInstance(number) - || Short.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - NumericUtils.intToPrefixCoded(number.intValue(), 0, ref); - return ref.get(); - } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - long l = NumericUtils.doubleToSortableLong(number.doubleValue()); - NumericUtils.longToPrefixCoded(l, 0, ref); - return ref.get(); - } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - NumericUtils.longToPrefixCoded(number.longValue(), 0, ref); - return ref.get(); - } else if (Float.class.isInstance(number)) { - BytesRefBuilder ref = new BytesRefBuilder(); - int i = NumericUtils.floatToSortableInt(number.floatValue()); - NumericUtils.intToPrefixCoded(i, 0, ref); - return ref.get(); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); - } - } - - protected Query eq(String field, String[] terms, boolean ignoreCase) { - if (terms.length > 1) { - PhraseQuery pq = new PhraseQuery(); - for (String s : terms) { - pq.add(new Term(field, s)); - } - return pq; - } - return new TermQuery(new Term(field, terms[0])); - } - - protected Query in(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - Path path = getPath(operation.getArg(0)); - String field = toField(path); - @SuppressWarnings("unchecked") - // this is the expected type - Constant> expectedConstant = (Constant>) operation.getArg(1); - Collection values = expectedConstant.getConstant(); - BooleanQuery bq = new BooleanQuery(); - if (Number.class.isAssignableFrom(path.getType())) { - for (Object value : values) { - TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value))); - bq.add(eq, Occur.SHOULD); - } - } else { - for (Object value : values) { - String[] str = convert(path, value); - bq.add(eq(field, str, ignoreCase), Occur.SHOULD); - } - } - return bq; - } - - protected Query notIn(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query ne(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - BooleanQuery bq = new BooleanQuery(); - bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), Occur.MUST_NOT)); - bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); - return bq; - } - - protected Query startsWith(QueryMetadata metadata, Operation operation, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == 0 ? terms[i] + "*" : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new PrefixQuery(new Term(field, terms[0])); - } - - protected Query stringContains( - Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (String s : terms) { - bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0] + "*")); - } - - protected Query endsWith(Operation operation, QueryMetadata metadata, boolean ignoreCase) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - String field = toField(path); - String[] terms = convertEscaped(path, operation.getArg(1), metadata); - if (terms.length > 1) { - BooleanQuery bq = new BooleanQuery(); - for (int i = 0; i < terms.length; ++i) { - String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*"; - bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST); - } - return bq; - } - return new WildcardQuery(new Term(field, "*" + terms[0])); - } - - protected Query between(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - // TODO Phrase not properly supported - return range( - path, toField(path), operation.getArg(1), operation.getArg(2), true, true, metadata); - } - - protected Query lt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), false, false, metadata); - } - - protected Query gt(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, false, false, metadata); - } - - protected Query le(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), null, operation.getArg(1), true, true, metadata); - } - - protected Query ge(Operation operation, QueryMetadata metadata) { - verifyArguments(operation); - Path path = getPath(operation.getArg(0)); - return range(path, toField(path), operation.getArg(1), null, true, true, metadata); - } - - protected Query range( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - if (min != null && Number.class.isAssignableFrom(min.getType()) - || max != null && Number.class.isAssignableFrom(max.getType())) { - @SuppressWarnings("unchecked") - // guarded by previous check - Constant minConstant = (Constant) min; - @SuppressWarnings("unchecked") - // guarded by previous check - Constant maxConstant = (Constant) max; - - Class numType = - minConstant != null ? minConstant.getType() : maxConstant.getType(); - // this is not necessarily safe, but compile time checking - // on the user side mandates these types to be interchangeable - @SuppressWarnings("unchecked") - Class unboundedNumType = (Class) numType; - return numericRange( - unboundedNumType, - field, - minConstant == null ? null : minConstant.getConstant(), - maxConstant == null ? null : maxConstant.getConstant(), - minInc, - maxInc); - } - return stringRange(leftHandSide, field, min, max, minInc, maxInc, metadata); - } - - protected NumericRangeQuery numericRange( - Class clazz, - String field, - @Nullable N min, - @Nullable N max, - boolean minInc, - boolean maxInc) { - if (clazz.equals(Integer.class)) { - return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); - } else if (clazz.equals(Double.class)) { - return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); - } else if (clazz.equals(Float.class)) { - return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); - } else if (clazz.equals(Long.class)) { - return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); - } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { - return NumericRangeQuery.newIntRange( - field, - min != null ? min.intValue() : null, - max != null ? max.intValue() : null, - minInc, - maxInc); - } else { - throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); - } - } - - protected Query stringRange( - Path leftHandSide, - String field, - @Nullable Expression min, - @Nullable Expression max, - boolean minInc, - boolean maxInc, - QueryMetadata metadata) { - - if (min == null) { - return TermRangeQuery.newStringRange( - field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); - } else if (max == null) { - return TermRangeQuery.newStringRange( - field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); - } else { - return TermRangeQuery.newStringRange( - field, - convert(leftHandSide, min, metadata)[0], - convert(leftHandSide, max, metadata)[0], - minInc, - maxInc); - } - } - - private Path getPath(Expression leftHandSide) { - if (leftHandSide instanceof Path) { - return (Path) leftHandSide; - } else if (leftHandSide instanceof Operation) { - Operation operation = (Operation) leftHandSide; - if (operation.getOperator() == Ops.LOWER || operation.getOperator() == Ops.UPPER) { - return (Path) operation.getArg(0); - } - } - throw new IllegalArgumentException("Unable to transform " + leftHandSide + " to path"); - } - - /** - * template method, override to customize - * - * @param path path - * @return field name - */ - protected String toField(Path path) { - PathMetadata md = path.getMetadata(); - if (md.getPathType() == PathType.COLLECTION_ANY) { - return toField(md.getParent()); - } else { - String rv = md.getName(); - if (md.getParent() != null) { - Path parent = md.getParent(); - if (parent.getMetadata().getPathType() != PathType.VARIABLE) { - rv = toField(parent) + "." + rv; - } - } - return rv; - } - } - - private void verifyArguments(Operation operation) { - List> arguments = operation.getArgs(); - for (int i = 1; i < arguments.size(); ++i) { - if (!(arguments.get(i) instanceof Constant) - && !(arguments.get(i) instanceof ParamExpression) - && !(arguments.get(i) instanceof PhraseElement) - && !(arguments.get(i) instanceof TermElement)) { - throw new IllegalArgumentException( - "operand was of unsupported type " + arguments.get(i).getClass().getName()); - } - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - if (rightHandSide instanceof Operation) { - Operation operation = (Operation) rightHandSide; - if (operation.getOperator() == LuceneOps.PHRASE) { - return operation.getArg(0).toString().split("\\s+"); - } else if (operation.getOperator() == LuceneOps.TERM) { - return new String[] {operation.getArg(0).toString()}; - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } else if (rightHandSide instanceof ParamExpression) { - Object value = metadata.getParams().get(rightHandSide); - if (value == null) { - throw new ParamNotSetException((ParamExpression) rightHandSide); - } - return convert(leftHandSide, value); - - } else if (rightHandSide instanceof Constant) { - return convert(leftHandSide, ((Constant) rightHandSide).getConstant()); - } else { - throw new IllegalArgumentException(rightHandSide.toString()); - } - } - - /** - * template method - * - * @param leftHandSide left hand side - * @param rightHandSide right hand side - * @return results - */ - protected String[] convert(Path leftHandSide, Object rightHandSide) { - String str = rightHandSide.toString(); - if (lowerCase) { - str = str.toLowerCase(); - } - if (splitTerms) { - if (str.equals("")) { - return new String[] {str}; - } else { - return str.split("\\s+"); - } - } else { - return new String[] {str}; - } - } - - private String[] convertEscaped( - Path leftHandSide, Expression rightHandSide, QueryMetadata metadata) { - String[] str = convert(leftHandSide, rightHandSide, metadata); - for (int i = 0; i < str.length; i++) { - str[i] = QueryParser.escape(str[i]); - } - return str; - } - - public Query toQuery(Expression expr, QueryMetadata metadata) { - if (expr instanceof Operation) { - return toQuery((Operation) expr, metadata); - } else { - return toQuery(ExpressionUtils.extract(expr), metadata); - } - } - - public Sort toSort(List> orderBys) { - List sorts = new ArrayList(orderBys.size()); - for (OrderSpecifier order : orderBys) { - if (!(order.getTarget() instanceof Path)) { - throw new IllegalArgumentException("argument was not of type Path."); - } - Class type = order.getTarget().getType(); - boolean reverse = !order.isAscending(); - Path path = getPath(order.getTarget()); - if (Number.class.isAssignableFrom(type)) { - sorts.add(new SortedNumericSortField(toField(path), sortFields.get(type), reverse)); - } else { - sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse)); - } - } - Sort sort = new Sort(); - sort.setSort(sorts.toArray(new SortField[0])); - return sort; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java deleted file mode 100644 index b41cc8b839..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/PhraseElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code PhraseElement} represents the embedded String as a phrase - * - * @author tiwe - */ -public class PhraseElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public PhraseElement(String str) { - super(LuceneOps.PHRASE, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java deleted file mode 100644 index 33d2c781b6..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/QueryElement.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.BooleanOperation; -import org.apache.lucene.search.Query; - -/** - * {@code QueryElement} wraps a Lucene Query - * - * @author tiwe - */ -public class QueryElement extends BooleanOperation { - - private static final long serialVersionUID = 470868107363840155L; - - public QueryElement(Query query) { - super(LuceneOps.LUCENE_QUERY, ConstantImpl.create(query)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java deleted file mode 100644 index 42fe409577..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/ResultIterator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.mysema.commons.lang.CloseableIterator; -import com.querydsl.core.QueryException; -import java.io.IOException; -import java.util.Set; -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.ScoreDoc; -import org.jetbrains.annotations.Nullable; - -/** - * {@code ResultIterator} is a {@link CloseableIterator} implementation for Lucene query results - * - * @author tiwe - * @param - */ -public final class ResultIterator implements CloseableIterator { - - private final ScoreDoc[] scoreDocs; - - private int cursor; - - private final IndexSearcher searcher; - - @Nullable private final Set fieldsToLoad; - - private final Function transformer; - - public ResultIterator( - ScoreDoc[] scoreDocs, - int offset, - IndexSearcher searcher, - @Nullable Set fieldsToLoad, - Function transformer) { - this.scoreDocs = scoreDocs.clone(); - this.cursor = offset; - this.searcher = searcher; - this.fieldsToLoad = fieldsToLoad; - this.transformer = transformer; - } - - @Override - public boolean hasNext() { - return cursor != scoreDocs.length; - } - - @Override - public T next() { - try { - Document document; - if (fieldsToLoad != null) { - document = searcher.doc(scoreDocs[cursor++].doc, fieldsToLoad); - } else { - document = searcher.doc(scoreDocs[cursor++].doc); - } - return transformer.apply(document); - } catch (IOException e) { - throw new QueryException(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void close() {} -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java deleted file mode 100644 index c5264f9740..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TermElement.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.dsl.StringOperation; - -/** - * {@code TermElement} represents the embedded String as a term - * - * @author tiwe - */ -public class TermElement extends StringOperation { - - private static final long serialVersionUID = 2350215644019186076L; - - public TermElement(String str) { - super(LuceneOps.TERM, ConstantImpl.create(str)); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java deleted file mode 100644 index acbc62b12c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/TypedQuery.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import java.util.function.Function; -import org.apache.lucene.document.Document; -import org.apache.lucene.search.IndexSearcher; - -/** - * {@code TypedQuery} is a typed query implementation for Lucene queries. - * - *

Converts Lucene documents to typed results via a constructor supplied transformer - * - * @param result type - * @author laim - * @author tiwe - */ -public class TypedQuery extends AbstractLuceneQuery> { - - /** - * Create a new TypedQuery instance - * - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery(IndexSearcher searcher, Function transformer) { - super(searcher, transformer); - } - - /** - * Create a new TypedQuery instance - * - * @param serializer serializer - * @param searcher index searcher - * @param transformer transformer to transform Lucene documents to result objects - */ - public TypedQuery( - LuceneSerializer serializer, IndexSearcher searcher, Function transformer) { - super(serializer, searcher, transformer); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java b/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java deleted file mode 100644 index 65984f31f8..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/main/java/com/querydsl/lucene5/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** Lucene 5 support */ -package com.querydsl.lucene5; diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java deleted file mode 100644 index 7e30244c3a..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneQueryTest.java +++ /dev/null @@ -1,820 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.easymock.EasyMock.createMockBuilder; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import com.querydsl.core.NonUniqueResultException; -import com.querydsl.core.QueryException; -import com.querydsl.core.QueryModifiers; -import com.querydsl.core.QueryResults; -import com.querydsl.core.types.ParamNotSetException; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.Param; -import com.querydsl.core.types.dsl.StringPath; -import java.io.IOException; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleDocValuesField; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.NumericDocValuesField; -import org.apache.lucene.document.SortedDocValuesField; -import org.apache.lucene.document.TextField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.sandbox.queries.DuplicateFilter; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Sort; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.BytesRef; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneQuery - * - * @author vema - */ -public class LuceneQueryTest { - - private LuceneQuery query; - private StringPath title; - private NumberPath year; - private NumberPath gross; - - private final StringPath sort = Expressions.stringPath("sort"); - - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private Field titleField = null; - private SortedDocValuesField titleSortedField; - private TextField authorField = null; - private SortedDocValuesField authorSortedField; - private TextField textField = null; - private IntField yearField = null; - private DoubleField grossField = null; - private SortedDocValuesField textSortedField; - private NumericDocValuesField yearSortedField; - private DoubleDocValuesField grossSortedField; - - private Document createDocument( - final String docTitle, - final String docAuthor, - final String docText, - final int docYear, - final double docGross) { - Document doc = new Document(); - // Reusing field for performance - if (titleField == null) { - titleField = new TextField("title", docTitle, Store.YES); - doc.add(titleField); - titleSortedField = new SortedDocValuesField("title", new BytesRef(docTitle)); - doc.add(titleSortedField); - } else { - titleField.setStringValue(docTitle); - titleSortedField.setBytesValue(new BytesRef(docTitle)); - doc.add(titleField); - doc.add(titleSortedField); - } - if (authorField == null) { - authorField = new TextField("author", docAuthor, Store.YES); - doc.add(authorField); - authorSortedField = new SortedDocValuesField("author", new BytesRef(docAuthor)); - doc.add(authorSortedField); - - } else { - authorField.setStringValue(docAuthor); - authorSortedField.setBytesValue(new BytesRef(docAuthor)); - doc.add(authorField); - doc.add(authorSortedField); - } - if (textField == null) { - textField = new TextField("text", docText, Store.YES); - doc.add(textField); - textSortedField = new SortedDocValuesField("text", new BytesRef(docText)); - doc.add(textSortedField); - } else { - textField.setStringValue(docText); - textSortedField.setBytesValue(new BytesRef(docText)); - doc.add(textField); - doc.add(textSortedField); - } - if (yearField == null) { - yearField = new IntField("year", docYear, Store.YES); - doc.add(yearField); - yearSortedField = new NumericDocValuesField("year", docYear); - doc.add(yearSortedField); - } else { - yearField.setIntValue(docYear); - yearSortedField.setLongValue(docYear); - doc.add(yearField); - doc.add(yearSortedField); - } - - if (grossField == null) { - grossField = new DoubleField("gross", docGross, Store.YES); - doc.add(grossField); - grossSortedField = new DoubleDocValuesField("gross", docGross); - doc.add(grossSortedField); - } else { - grossField.setDoubleValue(docGross); - grossSortedField.setDoubleValue(docGross); - doc.add(grossField); - doc.add(grossSortedField); - } - - return doc; - } - - @Before - public void setUp() throws Exception { - final QDocument entityPath = new QDocument("doc"); - title = entityPath.title; - year = entityPath.year; - gross = entityPath.gross; - - idx = new RAMDirectory(); - writer = createWriter(idx); - - writer.addDocument( - createDocument( - "Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00)); - writer.addDocument( - createDocument( - "Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00)); - writer.addDocument( - createDocument( - "The Lord of the Rings", - "John R. R. Tolkien", - "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in" - + " the darkness bind them", - 1954, - 89.00)); - writer.addDocument( - createDocument( - "Introduction to Algorithms", - "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", - "Bubble sort", - 1990, - 30.50)); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - } - - private IndexWriter createWriter(RAMDirectory idx) throws Exception { - IndexWriterConfig config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - return new IndexWriter(idx, config); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - @Test - public void between() { - assertThat(query.where(year.between(1950, 1990)).fetchCount()).isEqualTo(3); - } - - @Test - public void count_empty_where_clause() { - assertThat(query.fetchCount()).isEqualTo(4); - } - - @Test - public void exists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() > 0).isTrue(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() > 0).isFalse(); - } - - @Test - public void notExists() { - assertThat(query.where(title.eq("Jurassic Park")).fetchCount() == 0).isFalse(); - assertThat(query.where(title.eq("Jurassic Park X")).fetchCount() == 0).isTrue(); - } - - @Test - public void count() { - query.where(title.eq("Jurassic Park")); - assertThat(query.fetchCount()).isEqualTo(1); - } - - @Test(expected = QueryException.class) - @Ignore - public void count_index_problem() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchCount(); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void countDistinct() { - query.where(year.between(1900, 3000)); - assertThat(query.distinct().fetchCount()).isEqualTo(3); - } - - @Test - public void in() { - assertThat(query.where(title.in("Jurassic Park", "Nummisuutarit")).fetchCount()).isEqualTo(2); - } - - @Test - public void in2() { - assertThat(query.where(year.in(1990, 1864)).fetchCount()).isEqualTo(3); - } - - @Test - public void in_toString() { - assertThat(query.where(year.in(1990, 1864)).toString()).isEqualTo("year:`____F year:`____H"); - } - - @Test - public void list_sorted_by_year_ascending() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted() { - query.where(year.between(1800, 2000)); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - @Ignore - // FIXME - public void sorted_by_different_locales() throws Exception { - Document d1 = new Document(); - Document d2 = new Document(); - Document d3 = new Document(); - d1.add(new TextField("sort", "a\u00c4", Store.YES)); - d2.add(new TextField("sort", "ab", Store.YES)); - d3.add(new TextField("sort", "aa", Store.YES)); - writer = createWriter(idx); - writer.addDocument(d1); - writer.addDocument(d2); - writer.addDocument(d3); - writer.close(); - - IndexReader reader = DirectoryReader.open(writer, true); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.ENGLISH), searcher); - assertThat(query.fetch()).hasSize(3); - List results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results).hasSize(3); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("a\u00c4"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("ab"); - - query = new LuceneQuery(new LuceneSerializer(true, true, Locale.of("fi", "FI")), searcher); - results = query.where(sort.startsWith("a")).orderBy(sort.asc()).fetch(); - assertThat(results.getFirst().getField("sort").stringValue()).isEqualTo("aa"); - assertThat(results.get(1).getField("sort").stringValue()).isEqualTo("ab"); - assertThat(results.get(2).getField("sort").stringValue()).isEqualTo("a\u00c4"); - } - - @Test - public void list_not_sorted_limit_2() { - query.where(year.between(1800, 2000)); - query.limit(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_by_year_limit_1() { - query.where(year.between(1800, 2000)); - query.limit(1); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(1); - } - - @Test - public void list_not_sorted_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - } - - @Test - public void list_sorted_ascending_by_year_offset_2() { - query.where(year.between(1800, 2000)); - query.offset(2); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year_restrict_limit_2_offset_1() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(2); - assertThat(documents.getFirst().get("year")).isEqualTo("1954"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sorted_ascending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_sort() { - Sort sort = LuceneSerializer.DEFAULT.toSort(Collections.singletonList(year.asc())); - - query.where(year.between(1800, 2000)); - // query.orderBy(year.asc()); - query.sort(sort); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1864"); - assertThat(documents.get(1).get("year")).isEqualTo("1954"); - assertThat(documents.get(2).get("year")).isEqualTo("1990"); - assertThat(documents.get(3).get("year")).isEqualTo("1990"); - } - - @Test - public void list_distinct_property() { - assertThat(query.fetch()).hasSize(4); - assertThat(query.distinct(year).fetch()).hasSize(3); - } - - @Test - public void list_with_filter() { - Filter filter = new DuplicateFilter("year"); - assertThat(query.fetch()).hasSize(4); - assertThat(query.filter(filter).fetch()).hasSize(3); - } - - @Test - public void count_distinct_property() { - assertThat(query.fetchCount()).isEqualTo(4L); - assertThat(query.distinct(year).fetchCount()).isEqualTo(3L); - } - - @Test - public void list_sorted_descending_by_year() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.get(2).get("year")).isEqualTo("1954"); - assertThat(documents.get(3).get("year")).isEqualTo("1864"); - } - - @Test - public void list_sorted_descending_by_gross() { - query.where(gross.between(0.0, 1000.00)); - query.orderBy(gross.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("gross")).isEqualTo("90.0"); - assertThat(documents.get(1).get("gross")).isEqualTo("89.0"); - assertThat(documents.get(2).get("gross")).isEqualTo("30.5"); - assertThat(documents.get(3).get("gross")).isEqualTo("10.0"); - } - - @Test - public void list_sorted_descending_by_year_and_ascending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Introduction to Algorithms"); - assertThat(documents.get(1).get("title")).isEqualTo("Jurassic Park"); - } - - @Test - public void list_sorted_descending_by_year_and_descending_by_title() { - query.where(year.between(1800, 2000)); - query.orderBy(year.desc()); - query.orderBy(title.desc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - assertThat(documents.getFirst().get("year")).isEqualTo("1990"); - assertThat(documents.get(1).get("year")).isEqualTo("1990"); - assertThat(documents.getFirst().get("title")).isEqualTo("Jurassic Park"); - assertThat(documents.get(1).get("title")).isEqualTo("Introduction to Algorithms"); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetch(); - verify(searcher); - } - - @Ignore - @Test(expected = QueryException.class) - public void list_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IOException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.orderBy(title.asc()); - query.fetch(); - verify(searcher); - } - - @Test - public void offset() { - assertThat(query.where(title.eq("Jurassic Park")).offset(30).fetch()).isEmpty(); - } - - @Test - public void load_list() { - Document document = query.where(title.ne("")).load(title).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_list_fieldSelector() { - Document document = - query.where(title.ne("")).load(Collections.singleton("title")).fetch().get(0); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult() { - Document document = query.where(title.ne("")).load(title).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void load_singleResult_fieldSelector() { - Document document = query.where(title.ne("")).load(Collections.singleton("title")).fetchFirst(); - assertThat(document.get("title")).isNotNull(); - assertThat(document.get("year")).isNull(); - } - - @Test - public void singleResult() { - assertThat(query.where(title.ne("")).fetchFirst()).isNotNull(); - } - - @Test - public void single_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchFirst().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void single_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchFirst(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void single_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchFirst()).isNull(); - } - - @Test - public void single_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchFirst().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void single_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchFirst().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test(expected = NonUniqueResultException.class) - public void uniqueResult_contract() { - query.where(title.ne("")).fetchOne(); - } - - @Test - public void unique_result_takes_limit() { - assertThat(query.where(title.ne("")).limit(1).fetchOne().get("title")) - .isEqualTo("Jurassic Park"); - } - - @Test - public void unique_result_considers_limit_and_actual_result_size() { - query.where(title.startsWith("Nummi")); - final Document document = query.limit(3).fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void unique_result_returns_null_if_nothing_is_in_range() { - query.where(title.startsWith("Nummi")); - assertThat(query.offset(10).fetchOne()).isNull(); - } - - @Test - public void unique_result_considers_offset() { - assertThat(query.where(title.ne("")).offset(3).fetchOne().get("title")) - .isEqualTo("Introduction to Algorithms"); - } - - @Test - public void unique_result_considers_limit_and_offset() { - assertThat(query.where(title.ne("")).limit(1).offset(2).fetchOne().get("title")) - .isEqualTo("The Lord of the Rings"); - } - - @Test - public void uniqueResult() { - query.where(title.startsWith("Nummi")); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test - public void uniqueResult_with_param() { - final Param param = new Param(String.class, "title"); - query.set(param, "Nummi"); - query.where(title.startsWith(param)); - final Document document = query.fetchOne(); - assertThat(document.get("title")).isEqualTo("Nummisuutarit"); - } - - @Test(expected = ParamNotSetException.class) - public void uniqueResult_param_not_set() { - final Param param = new Param(String.class, "title"); - query.where(title.startsWith(param)); - query.fetchOne(); - } - - @Test(expected = QueryException.class) - public void uniqueResult_finds_more_than_one_result() { - query.where(year.eq(1990)); - query.fetchOne(); - } - - @Test - public void uniqueResult_finds_no_results() { - query.where(year.eq(2200)); - assertThat(query.fetchOne()).isNull(); - } - - @Test - @Ignore - public void uniqueResult_finds_no_results_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchOne()).isNull(); - verify(searcher); - } - - @Test(expected = QueryException.class) - @Ignore - public void uniqueResult_sorted_index_problem_in_max_doc() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andThrow(new IllegalArgumentException()); - replay(searcher); - query.where(title.eq("Jurassic Park")); - query.fetchOne(); - verify(searcher); - } - - @Test - @Ignore - public void count_returns_0_because_no_documents_in_index() throws IOException { - searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock(); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - expect(searcher.getIndexReader().maxDoc()).andReturn(0); - replay(searcher); - assertThat(query.where(year.eq(3000)).fetchCount()).isEqualTo(0); - verify(searcher); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinct() { - query.where(year.between(1900, 2000).or(title.startsWith("Jura"))); - query.orderBy(year.asc()); - final List documents = query.distinct().fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(3); - } - - @Test - public void listResults() { - query.where(year.between(1800, 2000)); - query.restrict(new QueryModifiers(2L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getResults().get(1).get("year")).isEqualTo("1990"); - assertThat(results.getLimit()).isEqualTo(2); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test(expected = UnsupportedOperationException.class) - public void listDistinctResults() { - query.where(year.between(1800, 2000).or(title.eq("The Lord of the Rings"))); - query.restrict(new QueryModifiers(1L, 1L)); - query.orderBy(year.asc()); - final QueryResults results = query.distinct().fetchResults(); - assertThat(results.isEmpty()).isFalse(); - assertThat(results.getResults().get(0).get("year")).isEqualTo("1954"); - assertThat(results.getLimit()).isEqualTo(1); - assertThat(results.getOffset()).isEqualTo(1); - assertThat(results.getTotal()).isEqualTo(4); - } - - @Test - public void list_all() { - final List results = - query.where(title.like("*")).orderBy(title.asc(), year.desc()).fetch(); - assertThat(results).hasSize(4); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_negative() { - query.where(year.between(1800, 2000)); - query.limit(-1); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_limit_0() { - query.where(year.between(1800, 2000)); - query.limit(0); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_sorted_ascending_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.orderBy(year.asc()); - query.fetch(); - } - - @Test(expected = IllegalArgumentException.class) - public void list_not_sorted_offset_negative() { - query.where(year.between(1800, 2000)); - query.offset(-1); - query.fetch(); - } - - @Test - public void list_sorted_ascending_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - query.orderBy(year.asc()); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void list_not_sorted_offset_0() { - query.where(year.between(1800, 2000)); - query.offset(0); - final List documents = query.fetch(); - assertThat(documents).isNotEmpty(); - assertThat(documents).hasSize(4); - } - - @Test - public void iterate() { - query.where(year.between(1800, 2000)); - final Iterator iterator = query.iterate(); - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - assertThat(count).isEqualTo(4); - } - - @Test - public void all_by_excluding_where() { - assertThat(query.fetch()).hasSize(4); - } - - @Test - public void empty_index_should_return_empty_list() throws Exception { - idx = new RAMDirectory(); - - writer = createWriter(idx); - writer.close(); - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - query = new LuceneQuery(new LuceneSerializer(true, true), searcher); - assertThat(query.fetch()).isEmpty(); - } - - @Test(expected = QueryException.class) - public void - list_results_throws_an_illegal_argument_exception_when_sum_of_limit_and_offset_is_negative() { - query.limit(1).offset(Integer.MAX_VALUE).fetchResults(); - } - - @Test - public void limit_max_value() { - assertThat(query.limit(Long.MAX_VALUE).fetch()).hasSize(4); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java deleted file mode 100644 index 85e6942296..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerNotTokenizedTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static com.querydsl.lucene5.QPerson.person; -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import java.time.LocalDate; -import java.util.Arrays; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.junit.Before; -import org.junit.Test; - -public class LuceneSerializerNotTokenizedTest { - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - private LuceneSerializer serializer; - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private final Person clooney = new Person("actor_1", "George Clooney", LocalDate.of(1961, 4, 6)); - private final Person pitt = new Person("actor_2", "Brad Pitt", LocalDate.of(1963, 12, 18)); - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - private Document createDocument(Person person) { - Document doc = new Document(); - doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); - doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); - doc.add( - new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); - return doc; - } - - @Before - public void before() throws Exception { - serializer = new LuceneSerializer(false, false); - idx = new RAMDirectory(); - IndexWriterConfig config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument(clooney)); - writer.addDocument(createDocument(pitt)); - - Document document = new Document(); - for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) { - document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED)); - } - writer.addDocument(document); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @Test - public void equals_by_id_matches() throws Exception { - testQuery(person.id.eq("actor_1"), "id:actor_1", 1); - } - - @Test - public void equals_by_id_does_not_match() throws Exception { - testQuery(person.id.eq("actor_8"), "id:actor_8", 0); - } - - @Test - public void equals_by_name_matches() throws Exception { - testQuery(person.name.eq("George Clooney"), "name:George Clooney", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_by_name_ignoring_case_does_not_match() throws Exception { - testQuery(person.name.equalsIgnoreCase("george clooney"), "name:george clooney", 0); - } - - @Test - public void equals_by_name_does_not_match() throws Exception { - testQuery(person.name.eq("George Looney"), "name:George Looney", 0); - } - - @Test - public void starts_with_name_should_match() throws Exception { - testQuery(person.name.startsWith("George C"), "name:George C*", 1); - } - - @Test - public void starts_with_name_should_not_match() throws Exception { - testQuery(person.name.startsWith("George L"), "name:George L*", 0); - } - - @Test - public void ends_with_name_should_match() throws Exception { - testQuery(person.name.endsWith("e Clooney"), "name:*e Clooney", 1); - } - - @Test - public void ends_with_name_should_not_match() throws Exception { - testQuery(person.name.endsWith("e Looney"), "name:*e Looney", 0); - } - - @Test - public void contains_name_should_match() throws Exception { - testQuery(person.name.contains("oney"), "name:*oney*", 1); - } - - @Test - public void contains_name_should_not_match() throws Exception { - testQuery(person.name.contains("bloney"), "name:*bloney*", 0); - } - - @Test - public void in_names_should_match_2() throws Exception { - testQuery( - person.name.in("Brad Pitt", "George Clooney"), "name:Brad Pitt name:George Clooney", 2); - } - - @Test - public void or_by_name_should_match_2() throws Exception { - testQuery( - person.name.eq("Brad Pitt").or(person.name.eq("George Clooney")), - "name:Brad Pitt name:George Clooney", - 2); - } - - @Test - public void equals_by_birth_date() throws Exception { - testQuery(person.birthDate.eq(clooney.getBirthDate()), "birthDate:1961-04-06", 1); - } - - @Test - public void between_phrase() throws Exception { - testQuery( - person.name.between("Brad Pitt", "George Clooney"), - "name:[Brad Pitt TO George Clooney]", - 2); - } - - @Test - public void not_equals_finds_the_actors_and_movies() throws Exception { - testQuery(person.name.ne("Michael Douglas"), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void not_equals_finds_only_clooney_and_movies() throws Exception { - testQuery(person.name.ne("Brad Pitt"), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void and_with_two_not_equals_doesnt_find_the_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").and(person.name.ne("George Clooney")), - "+(-name:Brad Pitt +*:*) +(-name:George Clooney +*:*)", - 1); - } - - @Test - public void or_with_two_not_equals_finds_movies_and_actors() throws Exception { - testQuery( - person.name.ne("Brad Pitt").or(person.name.ne("George Clooney")), - "(-name:Brad Pitt +*:*) (-name:George Clooney +*:*)", - 3); - } - - @Test - public void negation_of_equals_finds_movies_and_actors() throws Exception { - testQuery(person.name.eq("Michael Douglas").not(), "-name:Michael Douglas +*:*", 3); - } - - @Test - public void negation_of_equals_finds_pitt_and_movies() throws Exception { - testQuery(person.name.eq("Brad Pitt").not(), "-name:Brad Pitt +*:*", 2); - } - - @Test - public void multiple_field_search_from_movies() throws Exception { - StringPath movie = Expressions.stringPath("movie"); - testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); - testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java deleted file mode 100644 index eeb35d3b10..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/LuceneSerializerTest.java +++ /dev/null @@ -1,718 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.MatchingFiltersFactory; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.QuerydslModule; -import com.querydsl.core.StringConstant; -import com.querydsl.core.Target; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.CollectionPath; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.PathBuilder; -import com.querydsl.core.types.dsl.StringPath; -import java.io.StringReader; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoubleField; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.Field.Index; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.FloatField; -import org.apache.lucene.document.IntField; -import org.apache.lucene.document.LongField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.RAMDirectory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Tests for LuceneSerializer - * - * @author vema - */ -public class LuceneSerializerTest { - private LuceneSerializer serializer; - private PathBuilder entityPath; - private StringPath title; - private StringPath author; - private StringPath text; - private StringPath rating; - private StringPath publisher; - private NumberPath year; - private NumberPath gross; - private CollectionPath titles; - - private NumberPath longField; - private NumberPath shortField; - private NumberPath byteField; - private NumberPath floatField; - - private static final String YEAR_PREFIX_CODED = ""; - private static final String GROSS_PREFIX_CODED = ""; - private static final String LONG_PREFIX_CODED = ""; - private static final String SHORT_PREFIX_CODED = ""; - private static final String BYTE_PREFIX_CODED = ""; - private static final String FLOAT_PREFIX_CODED = ""; - - private IndexWriterConfig config; - private RAMDirectory idx; - private IndexWriter writer; - private IndexSearcher searcher; - - private static final Set UNSUPPORTED_OPERATORS = - Collections.unmodifiableSet( - EnumSet.of( - Ops.STARTS_WITH_IC, Ops.EQ_IGNORE_CASE, Ops.ENDS_WITH_IC, Ops.STRING_CONTAINS_IC)); - - private final QueryMetadata metadata = new DefaultQueryMetadata(); - - private Document createDocument() { - Document doc = new Document(); - - doc.add(new Field("title", new StringReader("Jurassic Park"))); - doc.add(new Field("author", new StringReader("Michael Crichton"))); - doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!"))); - doc.add(new Field("rating", new StringReader("Good"))); - doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED)); - doc.add(new IntField("year", 1990, Store.YES)); - doc.add(new DoubleField("gross", 900.0, Store.YES)); - - doc.add(new LongField("longField", 1, Store.YES)); - doc.add(new IntField("shortField", 1, Store.YES)); - doc.add(new IntField("byteField", 1, Store.YES)); - doc.add(new FloatField("floatField", 1, Store.YES)); - - return doc; - } - - @Before - public void setUp() throws Exception { - serializer = new LuceneSerializer(true, true); - entityPath = new PathBuilder(Object.class, "obj"); - title = entityPath.getString("title"); - author = entityPath.getString("author"); - text = entityPath.getString("text"); - publisher = entityPath.getString("publisher"); - year = entityPath.getNumber("year", Integer.class); - rating = entityPath.getString("rating"); - gross = entityPath.getNumber("gross", Double.class); - titles = entityPath.getCollection("title", String.class, StringPath.class); - - longField = entityPath.getNumber("longField", Long.class); - shortField = entityPath.getNumber("shortField", Short.class); - byteField = entityPath.getNumber("byteField", Byte.class); - floatField = entityPath.getNumber("floatField", Float.class); - - idx = new RAMDirectory(); - config = - new IndexWriterConfig(new StandardAnalyzer()) - .setOpenMode(IndexWriterConfig.OpenMode.CREATE); - writer = new IndexWriter(idx, config); - - writer.addDocument(createDocument()); - - writer.close(); - - IndexReader reader = DirectoryReader.open(idx); - searcher = new IndexSearcher(reader); - } - - @After - public void tearDown() throws Exception { - searcher.getIndexReader().close(); - } - - private void testQuery(Expression expr, int expectedHits) throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - } - - private void testQuery(Expression expr, String expectedQuery, int expectedHits) - throws Exception { - Query query = serializer.toQuery(expr, metadata); - TopDocs docs = searcher.search(query, 100); - assertThat(docs.totalHits).isEqualTo(expectedHits); - assertThat(query.toString()).isEqualTo(expectedQuery); - } - - @Test - public void queryElement() throws Exception { - Query query1 = serializer.toQuery(author.like("Michael"), metadata); - Query query2 = serializer.toQuery(text.like("Text"), metadata); - - BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2)); - testQuery(query, "author:michael text:text", 1); - } - - @Test - public void like() throws Exception { - testQuery(author.like("*ichael*"), "author:*ichael*", 1); - } - - @Test - public void like_custom_wildcard_single_character() throws Exception { - testQuery(author.like("Mi?hael"), "author:mi?hael", 1); - } - - @Test - public void like_custom_wildcard_multiple_character() throws Exception { - testQuery(text.like("*U*X*"), "text:*u*x*", 1); - } - - @Test - public void like_phrase() throws Exception { - testQuery(title.like("*rassic Par*"), "+title:**rassic* +title:*par**", 1); - } - - @Test - public void like_or_like() throws Exception { - testQuery(title.like("House").or(author.like("*ichae*")), "title:house author:*ichae*", 1); - } - - @Test - public void like_and_like() throws Exception { - testQuery(title.like("*assic*").and(rating.like("G?od")), "+title:*assic* +rating:g?od", 1); - } - - @Test - public void eq() throws Exception { - testQuery(rating.eq("good"), "rating:good", 1); - } - - @Test - public void eq_with_deep_path() throws Exception { - StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); - testQuery(deepPath.eq("good"), "property1.property2:good", 0); - } - - @Test - public void fuzzyLike() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good"), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2), "rating:Good~2", 1); - } - - @Test - public void fuzzyLike_with_similarity_and_prefix() throws Exception { - testQuery(LuceneExpressions.fuzzyLike(rating, "Good", 2, 0), "rating:Good~2", 1); - } - - @Test - @Ignore - public void eq_numeric_integer() throws Exception { - testQuery(year.eq(1990), "year:" + YEAR_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric_double() throws Exception { - testQuery(gross.eq(900.00), "gross:" + GROSS_PREFIX_CODED, 1); - } - - @Test - @Ignore - public void eq_numeric() throws Exception { - testQuery(longField.eq(1L), "longField:" + LONG_PREFIX_CODED, 1); - testQuery(shortField.eq((short) 1), "shortField:" + SHORT_PREFIX_CODED, 1); - testQuery(byteField.eq((byte) 1), "byteField:" + BYTE_PREFIX_CODED, 1); - testQuery(floatField.eq((float) 1.0), "floatField:" + FLOAT_PREFIX_CODED, 1); - } - - @Test - public void equals_ignores_case() throws Exception { - testQuery(title.eq("Jurassic"), "title:jurassic", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_or_year_equals() throws Exception { - testQuery( - title.equalsIgnoreCase("House").or(year.eq(1990)), - "title:house year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)), - "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED, - 1); - } - - @Test - @Ignore - public void eq_and_eq_and_eq() throws Exception { - testQuery( - title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")), - "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"", - 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void equals_ignore_case_and_or() throws Exception { - testQuery( - title - .equalsIgnoreCase("Jurassic Park") - .and(rating.equalsIgnoreCase("Bad")) - .or(author.equalsIgnoreCase("Michael Crichton")), - "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"", - 1); - } - - @Test - public void eq_or_eq_and_eq_does_not_find_results() throws Exception { - testQuery( - title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")), - "+(title:jeeves rating:superb) +author:\"michael crichton\"", - 0); - } - - @Test - public void eq_phrase() throws Exception { - testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); - } - - @Test - @Ignore("Not easily done in Lucene!") - public void publisher_equals_empty_string() throws Exception { - testQuery(publisher.eq(""), "publisher:", 1); - } - - @Test - public void eq_phrase_should_not_find_results_but_luceNe_semantics_differs_from_querydsls() - throws Exception { - testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); - } - - @Test - public void eq_phrase_does_not_find_results_because_word_in_middle() throws Exception { - testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); - } - - @Test - public void like_not_does_not_find_results() throws Exception { - testQuery(title.like("*H*e*").not(), "-title:*h*e* +*:*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void title_equals_ignore_case_negation_or_rating_equals_ignore_case() throws Exception { - testQuery( - title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")), - "-title:house rating:good", - 1); - } - - @Test - public void eq_not_does_not_find_results() throws Exception { - testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void title_equals_not_house() throws Exception { - testQuery(title.eq("house").not(), "-title:house +*:*", 1); - } - - @Test - public void eq_and_eq_not_does_not_find_results_because_second_expression_finds_nothing() - throws Exception { - testQuery( - rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); - } - - @Test - public void not_equals_finds_one() throws Exception { - testQuery(title.ne("house"), "-title:house +*:*", 1); - } - - @Test - public void not_equals_finds_none() throws Exception { - testQuery(title.ne("Jurassic Park"), "-title:\"jurassic park\" +*:*", 0); - } - - @Test - public void nothing_found_with_not_equals_or_equals() throws Exception { - testQuery( - title.ne("jurassic park").or(rating.eq("lousy")), - "(-title:\"jurassic park\" +*:*) rating:lousy", - 0); - } - - @Test - public void ne_and_eq() throws Exception { - testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); - } - - @Test - public void startsWith() throws Exception { - testQuery(title.startsWith("Jurassi"), "title:jurassi*", 1); - } - - @Test - public void startsWith_phrase() throws Exception { - testQuery(title.startsWith("jurassic par"), "+title:jurassic* +title:*par*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void starts_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0); - } - - @Test - public void endsWith() throws Exception { - testQuery(title.endsWith("ark"), "title:*ark", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Park"), "+title:*sic* +title:*park", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void ends_with_ignore_case_phrase_does_not_find_results() throws Exception { - testQuery(title.endsWithIgnoreCase("sic Par"), "+title:*sic* +title:*par", 0); - } - - @Test - public void contains() throws Exception { - testQuery(title.contains("rassi"), "title:*rassi*", 1); - } - - @Test(expected = UnsupportedOperationException.class) - public void contains_ignore_case_phrase() throws Exception { - testQuery(title.containsIgnoreCase("rassi Pa"), "+title:*rassi* +title:*pa*", 1); - } - - @Test - public void contains_user_inputted_wildcards_dont_work() throws Exception { - testQuery(title.contains("r*i"), "title:*r\\*i*", 0); - } - - @Test - public void between() throws Exception { - testQuery(title.between("Indiana", "Kundun"), "title:[indiana TO kundun]", 1); - } - - @Test - public void between_numeric_integer() throws Exception { - testQuery(year.between(1980, 2000), "year:[1980 TO 2000]", 1); - } - - @Test - public void between_numeric_double() throws Exception { - testQuery(gross.between(10.00, 19030.00), "gross:[10.0 TO 19030.0]", 1); - } - - @Test - public void between_numeric() throws Exception { - testQuery(longField.between(0L, 2L), "longField:[0 TO 2]", 1); - testQuery(shortField.between((short) 0, (short) 2), "shortField:[0 TO 2]", 1); - testQuery(byteField.between((byte) 0, (byte) 2), "byteField:[0 TO 2]", 1); - testQuery(floatField.between((float) 0.0, (float) 2.0), "floatField:[0.0 TO 2.0]", 1); - } - - @Test - public void between_is_inclusive_from_start() throws Exception { - testQuery(title.between("Jurassic", "Kundun"), "title:[jurassic TO kundun]", 1); - } - - @Test - public void between_is_inclusive_to_end() throws Exception { - testQuery(title.between("Indiana", "Jurassic"), "title:[indiana TO jurassic]", 1); - } - - @Test - public void between_does_not_find_results() throws Exception { - testQuery(title.between("Indiana", "Jurassib"), "title:[indiana TO jurassib]", 0); - } - - @Test - public void in() throws Exception { - testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1); - testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1); - testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1); - } - - @Test - public void lt() throws Exception { - testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1); - } - - @Test - public void lt_numeric_integer() throws Exception { - testQuery(year.lt(1991), "year:{* TO 1991}", 1); - } - - @Test - public void lt_numeric_double() throws Exception { - testQuery(gross.lt(10000.0), "gross:{* TO 10000.0}", 1); - } - - @Test - public void lt_not_in_range_because_equal() throws Exception { - testQuery(rating.lt("Good"), "rating:{* TO good}", 0); - } - - @Test - public void lt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.lt(1990), "year:{* TO 1990}", 0); - } - - @Test - public void lt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.lt(900.0), "gross:{* TO 900.0}", 0); - } - - @Test - public void loe() throws Exception { - testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1); - } - - @Test - public void loe_numeric_integer() throws Exception { - testQuery(year.loe(1991), "year:[* TO 1991]", 1); - } - - @Test - public void loe_numeric_double() throws Exception { - testQuery(gross.loe(903.0), "gross:[* TO 903.0]", 1); - } - - @Test - public void loe_equal() throws Exception { - testQuery(rating.loe("Good"), "rating:[* TO good]", 1); - } - - @Test - public void loe_numeric_integer_equal() throws Exception { - testQuery(year.loe(1990), "year:[* TO 1990]", 1); - } - - @Test - public void loe_numeric_double_equal() throws Exception { - testQuery(gross.loe(900.0), "gross:[* TO 900.0]", 1); - } - - @Test - public void loe_not_found() throws Exception { - testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0); - } - - @Test - public void loe_numeric_integer_not_found() throws Exception { - testQuery(year.loe(1989), "year:[* TO 1989]", 0); - } - - @Test - public void loe_numeric_double_not_found() throws Exception { - testQuery(gross.loe(899.9), "gross:[* TO 899.9]", 0); - } - - @Test - public void gt() throws Exception { - testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1); - } - - @Test - public void gt_numeric_integer() throws Exception { - testQuery(year.gt(1989), "year:{1989 TO *}", 1); - } - - @Test - public void gt_numeric_double() throws Exception { - testQuery(gross.gt(100.00), "gross:{100.0 TO *}", 1); - } - - @Test - public void gt_not_in_range_because_equal() throws Exception { - testQuery(rating.gt("Good"), "rating:{good TO *}", 0); - } - - @Test - public void gt_numeric_integer_not_in_range_because_equal() throws Exception { - testQuery(year.gt(1990), "year:{1990 TO *}", 0); - } - - @Test - public void gt_numeric_double_not_in_range_because_equal() throws Exception { - testQuery(gross.gt(900.00), "gross:{900.0 TO *}", 0); - } - - @Test - public void goe() throws Exception { - testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1); - } - - @Test - public void goe_numeric_integer() throws Exception { - testQuery(year.goe(1989), "year:[1989 TO *]", 1); - } - - @Test - public void goe_numeric_double() throws Exception { - testQuery(gross.goe(320.50), "gross:[320.5 TO *]", 1); - } - - @Test - public void goe_equal() throws Exception { - testQuery(rating.goe("Good"), "rating:[good TO *]", 1); - } - - @Test - public void goe_numeric_integer_equal() throws Exception { - testQuery(year.goe(1990), "year:[1990 TO *]", 1); - } - - @Test - public void goe_numeric_double_equal() throws Exception { - testQuery(gross.goe(900.00), "gross:[900.0 TO *]", 1); - } - - @Test - public void goe_not_found() throws Exception { - testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0); - } - - @Test - public void goe_numeric_integer_not_found() throws Exception { - testQuery(year.goe(1991), "year:[1991 TO *]", 0); - } - - @Test - public void goe_numeric_double_not_found() throws Exception { - testQuery(gross.goe(900.10), "gross:[900.1 TO *]", 0); - } - - @Test - public void equals_empty_string() throws Exception { - testQuery(title.eq(""), "title:", 0); - } - - @Test - public void not_equals_empty_string() throws Exception { - testQuery(title.ne(""), "-title: +*:*", 1); - } - - @Test - public void contains_empty_string() throws Exception { - testQuery(title.contains(""), "title:**", 1); - } - - @Test - public void like_empty_string() throws Exception { - testQuery(title.like(""), "title:", 0); - } - - @Test - public void starts_with_empty_string() throws Exception { - testQuery(title.startsWith(""), "title:*", 1); - } - - @Test - public void ends_with_empty_string() throws Exception { - testQuery(title.endsWith(""), "title:*", 1); - } - - @Test - public void between_empty_strings() throws Exception { - testQuery(title.between("", ""), "title:[ TO ]", 0); - } - - @Test - public void booleanBuilder() throws Exception { - testQuery(new BooleanBuilder(gross.goe(900.10)), "gross:[900.1 TO *]", 0); - } - - @Test - @Ignore - public void fuzzy() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void proximity() throws Exception { - fail("Not yet implemented!"); - } - - @Test - @Ignore - public void boost() throws Exception { - fail("Not yet implemented!"); - } - - @Test - public void pathAny() throws Exception { - testQuery(titles.any().eq("Jurassic"), "title:jurassic", 1); - } - - private boolean unsupportedOperation(Predicate filter) { - return UNSUPPORTED_OPERATORS.contains(((Operation) filter).getOperator()); - } - - @Test - public void various() throws Exception { - MatchingFiltersFactory filters = - new MatchingFiltersFactory(QuerydslModule.LUCENE, Target.LUCENE); - for (Predicate filter : filters.string(title, StringConstant.create("jurassic park"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(author, StringConstant.create("michael crichton"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 1); - } - - for (Predicate filter : filters.string(title, StringConstant.create("1990"))) { - if (unsupportedOperation(filter)) { - continue; - } - testQuery(filter, 0); - } - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java deleted file mode 100644 index 0577368fd8..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.annotations.QueryEntity; -import java.time.LocalDate; - -@QueryEntity -public class Person { - private final String id; - private final String name; - private final LocalDate birthDate; - - public Person(String id, String name, LocalDate birthDate) { - this.id = id; - this.name = name; - this.birthDate = birthDate; - } - - public String getId() { - return id; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public String getName() { - return name; - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java deleted file mode 100644 index 5e23bfc1fb..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/PhraseElementTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class PhraseElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, false); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:Hello World"); - assertThat(serializer.toQuery(title.eq(new PhraseElement("Hello World")), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - } - - @Test - public void equals() { - PhraseElement el1 = new PhraseElement("x"), - el2 = new PhraseElement("x"), - el3 = new PhraseElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - } - - @Test - public void hashCode_() { - PhraseElement el1 = new PhraseElement("x"), el2 = new PhraseElement("x"); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java deleted file mode 100644 index 83b7b4c8ab..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QDocument.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import com.querydsl.core.types.PathMetadataFactory; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import org.apache.lucene.document.Document; - -public class QDocument extends EntityPathBase { - - private static final long serialVersionUID = -4872833626508344081L; - - public QDocument(final String var) { - super(Document.class, PathMetadataFactory.forVariable(var)); - } - - public final NumberPath year = createNumber("year", Integer.class); - - public final StringPath title = createString("title"); - - public final NumberPath gross = createNumber("gross", Double.class); -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java deleted file mode 100644 index 9b3aec786c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/QueryElementTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.junit.Ignore; -import org.junit.Test; - -public class QueryElementTest { - - @Test - @Ignore - public void test() { - QueryElement element = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element.toString()).isEqualTo("str:text"); - // assertEquals(element.getQuery().hashCode(), element.hashCode()); - - QueryElement element2 = new QueryElement(new TermQuery(new Term("str", "text"))); - assertThat(element).isEqualTo(element2); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java b/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java deleted file mode 100644 index 005e4e7155..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/java/com/querydsl/lucene5/TermElementTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.lucene5; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.DefaultQueryMetadata; -import com.querydsl.core.QueryMetadata; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringPath; -import org.junit.Test; - -public class TermElementTest { - - @Test - public void test() { - StringPath title = Expressions.stringPath("title"); - LuceneSerializer serializer = new LuceneSerializer(false, true); - QueryMetadata metadata = new DefaultQueryMetadata(); - assertThat(serializer.toQuery(title.eq("Hello World"), metadata).toString()) - .isEqualTo("title:\"Hello World\""); - assertThat(serializer.toQuery(title.eq(new TermElement("Hello World")), metadata).toString()) - .isEqualTo("title:Hello World"); - } - - @Test - public void testEqualsAndHashCode() { - TermElement el1 = new TermElement("x"), el2 = new TermElement("x"), el3 = new TermElement("y"); - assertThat(el2).isEqualTo(el1); - assertThat(el1.equals(el3)).isFalse(); - assertThat(el2.hashCode()).isEqualTo(el1.hashCode()); - } -} diff --git a/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example b/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example deleted file mode 100644 index 0f193f333c..0000000000 --- a/querydsl-libraries/querydsl-lucene5/src/test/resources/log4j.properties.example +++ /dev/null @@ -1,9 +0,0 @@ -# Configure an appender that logs to console -log4j.rootLogger=info, A1 -log4j.threshold=debug -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -# Configuration of logging levels for different packages -log4j.logger.com.querydsl.lucene5=DEBUG diff --git a/querydsl-libraries/querydsl-mongodb/pom.xml b/querydsl-libraries/querydsl-mongodb/pom.xml index f3f85bb197..2115bebac1 100644 --- a/querydsl-libraries/querydsl-mongodb/pom.xml +++ b/querydsl-libraries/querydsl-mongodb/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-mongodb diff --git a/querydsl-libraries/querydsl-r2dbc/pom.xml b/querydsl-libraries/querydsl-r2dbc/pom.xml index f5be19d67b..d5fe7679ba 100644 --- a/querydsl-libraries/querydsl-r2dbc/pom.xml +++ b/querydsl-libraries/querydsl-r2dbc/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-r2dbc diff --git a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java index 0739944a74..2d2bc19b5e 100644 --- a/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java +++ b/querydsl-libraries/querydsl-r2dbc/src/test/java/com/querydsl/r2dbc/R2DBCMatchingFiltersFactory.java @@ -17,8 +17,20 @@ import com.querydsl.core.QuerydslModule; import com.querydsl.core.StringConstant; import com.querydsl.core.Target; -import com.querydsl.core.types.*; -import com.querydsl.core.types.dsl.*; +import com.querydsl.core.types.CollectionExpression; +import com.querydsl.core.types.Constant; +import com.querydsl.core.types.Expression; +import com.querydsl.core.types.MapExpression; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.ArrayExpression; +import com.querydsl.core.types.dsl.CollectionExpressionBase; +import com.querydsl.core.types.dsl.ComparableExpression; +import com.querydsl.core.types.dsl.ListExpression; +import com.querydsl.core.types.dsl.ListPath; +import com.querydsl.core.types.dsl.MapExpressionBase; +import com.querydsl.core.types.dsl.NumberExpression; +import com.querydsl.core.types.dsl.SimpleExpression; +import com.querydsl.core.types.dsl.StringExpression; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -86,7 +98,6 @@ public Collection date( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && !target.equals(Target.FIREBIRD) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { @@ -129,7 +140,6 @@ public Collection dateTime( rv.add(expr.dayOfMonth().eq(other.dayOfMonth())); if (!target.equals(Target.DERBY) - && !module.equals(QuerydslModule.JDO) && !target.equals(Target.ORACLE) && (!target.equals(Target.POSTGRESQL) || !module.equals(QuerydslModule.JPA))) { rv.add(expr.dayOfWeek().eq(other.dayOfWeek())); @@ -207,12 +217,10 @@ public > Collection numeric( public Collection string(StringExpression expr, StringExpression other) { HashSet rv = new HashSet(); - if (module != QuerydslModule.LUCENE) { - rv.addAll(comparable(expr, other)); + rv.addAll(comparable(expr, other)); - rv.add(expr.charAt(0).eq(other.charAt(0))); - rv.add(expr.charAt(1).eq(other.charAt(1))); - } + rv.add(expr.charAt(0).eq(other.charAt(0))); + rv.add(expr.charAt(1).eq(other.charAt(1))); rv.add(expr.contains(other)); rv.add(expr.contains(other.substring(0, 1))); @@ -241,58 +249,50 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.eq(other)); rv.add(expr.equalsIgnoreCase(other)); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.indexOf(other).eq(0)); - rv.add(expr.locate(other).eq(1)); - } + rv.add(expr.indexOf(other).eq(0)); + rv.add(expr.locate(other).eq(1)); - if (target != Target.DERBY && module != QuerydslModule.LUCENE) { + if (target != Target.DERBY) { rv.add(expr.indexOf(other.substring(1)).eq(1)); rv.add(expr.indexOf(other.substring(2)).eq(2)); } - if (module != QuerydslModule.LUCENE) { - rv.add(expr.isEmpty().not()); - rv.add(expr.isNotEmpty()); - } + rv.add(expr.isEmpty().not()); + rv.add(expr.isNotEmpty()); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.length().eq(other.length())); - rv.add(expr.like(other)); + rv.add(expr.length().eq(other.length())); + rv.add(expr.like(other)); - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.like(other.substring(0, 1).append("%"))); - rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); - rv.add(expr.like(other.substring(1).prepend("%"))); - rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); - } + if (other instanceof Constant) { + rv.add(expr.like(other.substring(0, 1).append("%"))); + rv.add(expr.like(other.substring(0, 1).append("%").append(other.substring(2)))); + rv.add(expr.like(other.substring(1).prepend("%"))); + rv.add(expr.like(other.substring(1, 2).append("%").prepend("%"))); } rv.add(expr.lower().eq(other.lower())); - if (module != QuerydslModule.LUCENE) { - if (!module.equals(QuerydslModule.SQL) - || (!target.equals(Target.HSQLDB) - && !target.equals(Target.FIREBIRD) - && !target.equals(Target.H2) - && !target.equals(Target.DB2) - && !target.equals(Target.DERBY) - && !target.equals(Target.SQLITE) - && !target.equals(Target.SQLSERVER))) { - - rv.add(expr.matches(other)); - - if (module != QuerydslModule.JDO || other instanceof Constant) { - rv.add(expr.matches(other.substring(0, 1).append(".*"))); - rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); - rv.add(expr.matches(other.substring(1).prepend(".*"))); - rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); - } + if (!module.equals(QuerydslModule.SQL) + || (!target.equals(Target.HSQLDB) + && !target.equals(Target.FIREBIRD) + && !target.equals(Target.H2) + && !target.equals(Target.DB2) + && !target.equals(Target.DERBY) + && !target.equals(Target.SQLITE) + && !target.equals(Target.SQLSERVER))) { + + rv.add(expr.matches(other)); + + if (other instanceof Constant) { + rv.add(expr.matches(other.substring(0, 1).append(".*"))); + rv.add(expr.matches(other.substring(0, 1).append(".").append(other.substring(2)))); + rv.add(expr.matches(other.substring(1).prepend(".*"))); + rv.add(expr.matches(other.substring(1, 2).prepend(".*").append(".*"))); } - - rv.add(expr.ne(other)); } + rv.add(expr.ne(other)); + rv.add(expr.startsWith(other)); rv.add(expr.startsWith(other.substring(0, 1))); rv.add(expr.startsWith(other.substring(0, 2))); @@ -301,13 +301,11 @@ public Collection string(StringExpression expr, StringExpression othe rv.add(expr.startsWithIgnoreCase(other.substring(0, 1))); rv.add(expr.startsWithIgnoreCase(other.substring(0, 2))); - if (module != QuerydslModule.LUCENE) { - rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); - rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); - rv.add(expr.substring(1).eq(other.substring(1))); + rv.add(expr.substring(0, 1).eq(other.substring(0, 1))); + rv.add(expr.substring(1, 2).eq(other.substring(1, 2))); + rv.add(expr.substring(1).eq(other.substring(1))); - rv.add(expr.trim().eq(other.trim())); - } + rv.add(expr.trim().eq(other.trim())); rv.add(expr.upper().eq(other.upper())); return Collections.unmodifiableSet(rv); diff --git a/querydsl-libraries/querydsl-scala/pom.xml b/querydsl-libraries/querydsl-scala/pom.xml index e075ff9507..4b62e6b8db 100644 --- a/querydsl-libraries/querydsl-scala/pom.xml +++ b/querydsl-libraries/querydsl-scala/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-scala diff --git a/querydsl-libraries/querydsl-spatial/pom.xml b/querydsl-libraries/querydsl-spatial/pom.xml index e9d9c1c4f8..8e02ca46f1 100644 --- a/querydsl-libraries/querydsl-spatial/pom.xml +++ b/querydsl-libraries/querydsl-spatial/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-spatial diff --git a/querydsl-libraries/querydsl-sql-spatial/pom.xml b/querydsl-libraries/querydsl-sql-spatial/pom.xml index 67d1c5d1b7..856e735a40 100644 --- a/querydsl-libraries/querydsl-sql-spatial/pom.xml +++ b/querydsl-libraries/querydsl-sql-spatial/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-spatial diff --git a/querydsl-libraries/querydsl-sql-spring/pom.xml b/querydsl-libraries/querydsl-sql-spring/pom.xml index 1520fce8b6..3ead123720 100644 --- a/querydsl-libraries/querydsl-sql-spring/pom.xml +++ b/querydsl-libraries/querydsl-sql-spring/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-spring diff --git a/querydsl-libraries/querydsl-sql/pom.xml b/querydsl-libraries/querydsl-sql/pom.xml index 5b34e61e22..efd4ad8708 100644 --- a/querydsl-libraries/querydsl-sql/pom.xml +++ b/querydsl-libraries/querydsl-sql/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-libraries - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql diff --git a/querydsl-tooling/pom.xml b/querydsl-tooling/pom.xml index c949d34cae..51ab75db2b 100644 --- a/querydsl-tooling/pom.xml +++ b/querydsl-tooling/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-root - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-tooling diff --git a/querydsl-tooling/querydsl-apt/pom.xml b/querydsl-tooling/querydsl-apt/pom.xml index 78ad16566c..2a216b74c1 100644 --- a/querydsl-tooling/querydsl-apt/pom.xml +++ b/querydsl-tooling/querydsl-apt/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-apt @@ -34,31 +34,6 @@ - - org.datanucleus - javax.jdo - provided - - - org.springframework.roo - org.springframework.roo.annotations - 1.3.2.RELEASE - provided - - - org.apache.commons - commons-lang3 - - - commons-io - commons-io - - - commons-codec - commons-codec - - - org.mongodb.morphia morphia @@ -160,10 +135,8 @@ src/main/general.xml src/main/hibernate.xml src/main/jakarta.xml - src/main/jdo.xml src/main/jpa.xml src/main/morphia.xml - src/main/roo.xml src/main/onejar.xml ${project.build.directory} @@ -189,8 +162,6 @@ com.querydsl.apt.QuerydslAnnotationProcessor com.querydsl.apt.hibernate.HibernateAnnotationProcessor - com.querydsl.apt.jdo.JDOAnnotationProcessor - com.querydsl.apt.roo.RooAnnotationProcessor diff --git a/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor b/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index ff511957d0..0000000000 --- a/querydsl-tooling/querydsl-apt/src/apt/jdo/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.querydsl.apt.jdo.JDOAnnotationProcessor \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor b/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 8ba591975e..0000000000 --- a/querydsl-tooling/querydsl-apt/src/apt/roo/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.querydsl.apt.roo.RooAnnotationProcessor \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java deleted file mode 100644 index 81088431b5..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOAnnotationProcessor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.apt.jdo; - -import com.querydsl.apt.AbstractQuerydslProcessor; -import com.querydsl.apt.Configuration; -import com.querydsl.core.annotations.QueryEmbedded; -import com.querydsl.core.annotations.QueryEntities; -import com.querydsl.core.annotations.QuerySupertype; -import java.lang.annotation.Annotation; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.jdo.annotations.EmbeddedOnly; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; - -/** - * AnnotationProcessor for JDO which takes {@link PersistenceCapable}, {@link EmbeddedOnly} and - * {@link NotPersistent} into account - * - * @author tiwe - */ -@SupportedAnnotationTypes({"com.querydsl.core.annotations.*", "javax.jdo.annotations.*"}) -public class JDOAnnotationProcessor extends AbstractQuerydslProcessor { - - @Override - protected Configuration createConfiguration(RoundEnvironment roundEnv) { - Class entities = QueryEntities.class; - Class entity = PersistenceCapable.class; - Class superType = QuerySupertype.class; - Class embeddable = EmbeddedOnly.class; - Class embedded = QueryEmbedded.class; - Class skip = NotPersistent.class; - return new JDOConfiguration( - processingEnv, roundEnv, entities, entity, superType, embeddable, embedded, skip); - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java deleted file mode 100644 index 02e28c513c..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/JDOConfiguration.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.apt.jdo; - -import com.querydsl.apt.DefaultConfiguration; -import com.querydsl.apt.VisitorConfig; -import com.querydsl.codegen.Keywords; -import com.querydsl.core.annotations.QueryInit; -import com.querydsl.core.annotations.QueryTransient; -import com.querydsl.core.annotations.QueryType; -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.RoundEnvironment; -import javax.jdo.annotations.Cacheable; -import javax.jdo.annotations.Column; -import javax.jdo.annotations.Columns; -import javax.jdo.annotations.Embedded; -import javax.jdo.annotations.Extension; -import javax.jdo.annotations.Extensions; -import javax.jdo.annotations.ForeignKey; -import javax.jdo.annotations.Index; -import javax.jdo.annotations.Join; -import javax.jdo.annotations.Key; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.Order; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; -import javax.jdo.annotations.Serialized; -import javax.jdo.annotations.Transactional; -import javax.jdo.annotations.Unique; -import javax.jdo.annotations.Value; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; - -/** - * Configuration for {@link JDOAnnotationProcessor} - * - * @author tiwe - * @see JDOAnnotationProcessor - */ -public class JDOConfiguration extends DefaultConfiguration { - - @SuppressWarnings("unchecked") - private static final Iterable> relevantAnnotations = - Collections.unmodifiableList( - Arrays.asList( - Cacheable.class, - Column.class, - Columns.class, - javax.jdo.annotations.Element.class, - Embedded.class, - Extension.class, - Extensions.class, - ForeignKey.class, - Index.class, - Join.class, - Key.class, - NotPersistent.class, - Order.class, - Persistent.class, - PrimaryKey.class, - QueryType.class, - QueryInit.class, - QueryTransient.class, - Serialized.class, - Transactional.class, - Unique.class, - Value.class)); - - public JDOConfiguration( - ProcessingEnvironment processingEnvironment, - RoundEnvironment roundEnv, - Class entitiesAnn, - Class entityAnn, - Class superTypeAnn, - Class embeddableAnn, - Class embeddedAnn, - Class skipAnn) { - super( - processingEnvironment, - roundEnv, - Keywords.JDO, - entitiesAnn, - entityAnn, - superTypeAnn, - embeddableAnn, - embeddedAnn, - skipAnn); - } - - @Override - public VisitorConfig getConfig(TypeElement e, List elements) { - boolean fields = false, methods = false; - for (Element element : elements) { - if (hasRelevantAnnotation(element)) { - fields |= element.getKind().equals(ElementKind.FIELD); - methods |= element.getKind().equals(ElementKind.METHOD); - } - } - return VisitorConfig.get(fields, methods, VisitorConfig.FIELDS_ONLY); - } - - private boolean hasRelevantAnnotation(Element element) { - for (Class relevantAnnotation : relevantAnnotations) { - if (element.getAnnotation(relevantAnnotation) != null) { - return true; - } - } - return false; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java deleted file mode 100644 index 92a33acd79..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/jdo/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** APT JDO support */ -package com.querydsl.apt.jdo; diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java deleted file mode 100644 index 17a7e0e0e6..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/RooAnnotationProcessor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.apt.roo; - -import com.querydsl.apt.AbstractQuerydslProcessor; -import com.querydsl.apt.Configuration; -import com.querydsl.apt.DefaultConfiguration; -import com.querydsl.apt.jpa.JPAConfiguration; -import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; -import jakarta.persistence.MappedSuperclass; -import jakarta.persistence.Transient; -import java.lang.annotation.Annotation; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; -import org.springframework.roo.addon.jpa.entity.RooJpaEntity; - -/** - * AnnotationProcessor for Spring Roo which takes {@link RooJpaEntity}, {@link RooJpaActiveRecord}, - * {@link MappedSuperclass}, {@link Embeddable} and {@link Transient} into account - * - * @author tiwe - */ -@SupportedAnnotationTypes({ - "com.querydsl.core.annotations.*", - "org.springframework.roo.addon.jpa.entity.*" -}) -public class RooAnnotationProcessor extends AbstractQuerydslProcessor { - - @Override - protected Configuration createConfiguration(RoundEnvironment roundEnv) { - Class entity = RooJpaEntity.class; - Class superType = MappedSuperclass.class; - Class embeddable = Embeddable.class; - Class embedded = Embedded.class; - Class skip = Transient.class; - DefaultConfiguration conf = - new JPAConfiguration( - roundEnv, processingEnv, entity, superType, embeddable, embedded, skip); - conf.setAlternativeEntityAnnotation(RooJpaActiveRecord.class); - return conf; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java b/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java deleted file mode 100644 index 839087dc87..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/java/com/querydsl/apt/roo/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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. - */ - -/** APT Roo support */ -package com.querydsl.apt.roo; diff --git a/querydsl-tooling/querydsl-apt/src/main/jdo.xml b/querydsl-tooling/querydsl-apt/src/main/jdo.xml deleted file mode 100644 index 016a08ac4d..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/jdo.xml +++ /dev/null @@ -1,19 +0,0 @@ - - jdo - - jar - - false - - - src/apt/jdo - / - - - ${project.build.outputDirectory} - / - - - \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/main/roo.xml b/querydsl-tooling/querydsl-apt/src/main/roo.xml deleted file mode 100644 index 6e56b67f02..0000000000 --- a/querydsl-tooling/querydsl-apt/src/main/roo.xml +++ /dev/null @@ -1,19 +0,0 @@ - - roo - - jar - - false - - - src/apt/roo - / - - - ${project.build.outputDirectory} - / - - - \ No newline at end of file diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java index f2e84de7a0..751d3a3857 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorTest.java @@ -13,12 +13,8 @@ */ package com.querydsl.apt; -import static org.assertj.core.api.Assertions.assertThat; - import com.querydsl.apt.hibernate.HibernateAnnotationProcessor; -import com.querydsl.apt.jdo.JDOAnnotationProcessor; import com.querydsl.apt.jpa.JPAAnnotationProcessor; -import com.querydsl.apt.roo.RooAnnotationProcessor; import java.io.File; import java.io.IOException; import java.util.Collections; @@ -33,69 +29,66 @@ public class QuerydslAnnotationProcessorTest extends AbstractProcessorTest { @Test public void process() throws IOException { - File file = new File(PACKAGE_PATH, "AbstractEntityTest.java"); + var file = new File(PACKAGE_PATH, "AbstractEntityTest.java"); process(QuerydslAnnotationProcessor.class, Collections.singletonList(file.getPath()), "qdsl"); } @Test public void process_monitoredCompany() throws IOException { - String path = new File(PACKAGE_PATH, "MonitoredCompany.java").getPath(); + var path = new File(PACKAGE_PATH, "MonitoredCompany.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "MonitoredCompany"); } @Test public void process_inheritance3() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/inheritance/Inheritance3Test.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "Inheritance3Test"); } @Test public void process_inheritance8() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/inheritance/Inheritance8Test.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "Inheritance8Test"); } @Test public void process_queryEmbedded3() throws IOException { - String path = - new File("src/test/java/com/querydsl/apt/domain/QueryEmbedded3Test.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/QueryEmbedded3Test.java").getPath(); process( QuerydslAnnotationProcessor.class, Collections.singletonList(path), "QueryEmbedded3Test"); } @Test public void process_queryEmbedded4() throws IOException { - String path = - new File("src/test/java/com/querydsl/apt/domain/QueryEmbedded4Test.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/QueryEmbedded4Test.java").getPath(); process( QuerydslAnnotationProcessor.class, Collections.singletonList(path), "QueryEmbedded4Test"); } @Test public void process_delegate() throws IOException { - String path = new File("src/test/java/com/querydsl/apt/domain/DelegateTest.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/DelegateTest.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "DelegateTest"); } @Test public void process_abstractClasses() throws IOException { - String path = - new File("src/test/java/com/querydsl/apt/domain/AbstractClassesTest.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/AbstractClassesTest.java").getPath(); process(JPAAnnotationProcessor.class, Collections.singletonList(path), "AbstractClassesTest"); } @Test public void process_abstractClasses2() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/domain/AbstractClasses2Test.java").getPath(); process(JPAAnnotationProcessor.class, Collections.singletonList(path), "abstractClasses2"); } @Test public void process_genericSignature() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/domain/GenericSignatureTest.java").getPath(); process( QuerydslAnnotationProcessor.class, Collections.singletonList(path), "GenericSignatureTest"); @@ -103,7 +96,7 @@ public void process_genericSignature() throws IOException { @Test public void process_abstractProperties2Test() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/domain/AbstractProperties2Test.java").getPath(); process( QuerydslAnnotationProcessor.class, @@ -113,35 +106,34 @@ public void process_abstractProperties2Test() throws IOException { @Test public void process_inheritance2Test() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/inheritance/Inheritance2Test.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "InheritanceTest2"); } @Test public void process_entityInheritanceTest() throws IOException { - String path = + var path = new File("src/test/java/com/querydsl/apt/domain/EntityInheritanceTest.java").getPath(); process(JPAAnnotationProcessor.class, Collections.singletonList(path), "EntityInheritanceTest"); } @Test public void process_enum2Test() throws IOException { - String path = new File("src/test/java/com/querydsl/apt/domain/Enum2Test.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/Enum2Test.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "Enum2Test"); } @Test public void process_externalEntityTest() throws IOException { - String path = - new File("src/test/java/com/querydsl/apt/domain/ExternalEntityTest.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/ExternalEntityTest.java").getPath(); process( QuerydslAnnotationProcessor.class, Collections.singletonList(path), "ExternalEntityTest"); } @Test public void process_generic13Test() throws IOException { - String path = new File("src/test/java/com/querydsl/apt/domain/Generic13Test.java").getPath(); + var path = new File("src/test/java/com/querydsl/apt/domain/Generic13Test.java").getPath(); process(QuerydslAnnotationProcessor.class, Collections.singletonList(path), "Generic13Test"); } @@ -159,16 +151,4 @@ public void jpaAnnotationProcessor() throws IOException { public void hibernateAnnotationProcessor() throws IOException { process(HibernateAnnotationProcessor.class, CLASSES, "hibernate"); } - - @Test - public void jdoAnnotationProcessor() throws IOException { - process(JDOAnnotationProcessor.class, CLASSES, "jdo"); - } - - @Test - public void rooAnnotationProcessor() throws IOException { - process(RooAnnotationProcessor.class, CLASSES, "roo"); - - assertThat(new File("target/roo/com/querydsl/apt/domain/QRooEntities_MyEntity.java")).exists(); - } } diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java index baf4275d22..d7ac5595b8 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/JDOTest.java @@ -13,75 +13,14 @@ */ package com.querydsl.apt.domain; -import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.StringPath; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; -import javax.jdo.annotations.Persistent; -import javax.jdo.annotations.PrimaryKey; -import org.junit.Test; +public class JDOTest { -public class JDOTest extends AbstractTest { - - @PersistenceCapable public static class JDOEntity { String prop; - @NotPersistent String skipped; - - @NotPersistent JDOEntity skippedEntity; - } - - @PersistenceCapable - public static class JDOEntity2 { - - private String stringField1; - - private String stringField2; - - public String getStringfield1() { - return stringField1; - } - - public String getStringField2() { - return stringField2; - } - } - - @PersistenceCapable - public static class JDOEntity3 { - - private Integer integerField; - - private String stringField; - - @PrimaryKey - public Integer getId() { - return integerField; - } - - @Persistent - public String getName() { - return stringField; - } - } - - @Test - public void test() throws IllegalAccessException, NoSuchFieldException { - start(QJDOTest_JDOEntity.class, QJDOTest_JDOEntity.jDOEntity); - match(StringPath.class, "prop"); - assertMissing("skipped"); - assertMissing("skippedEntity"); - - start(QJDOTest_JDOEntity2.class, QJDOTest_JDOEntity2.jDOEntity2); - match(StringPath.class, "stringField1"); - assertMissing("stringfield1"); - match(StringPath.class, "stringField2"); + String skipped; - start(QJDOTest_JDOEntity3.class, QJDOTest_JDOEntity3.jDOEntity3); - match(NumberPath.class, "id"); - matchType(Integer.class, "id"); - match(StringPath.class, "name"); + JDOEntity skippedEntity; } } diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/KeywordsTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/KeywordsTest.java index 3bacfe6c9b..3f4a40d0bf 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/KeywordsTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/KeywordsTest.java @@ -16,7 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat; import jakarta.persistence.Entity; -import javax.jdo.annotations.PersistenceCapable; import org.junit.Test; public class KeywordsTest { @@ -33,17 +32,10 @@ public static class From { @Entity public static class NonKeyword {} - @PersistenceCapable - public static class Distinct { - - String distinct; - } - @Test public void test() { assertThat(QKeywordsTest_Order.order.toString()).isEqualTo("order1"); assertThat(QKeywordsTest_From.from.toString()).isEqualTo("from1"); assertThat(QKeywordsTest_NonKeyword.nonKeyword.toString()).isEqualTo("nonKeyword"); - assertThat(QKeywordsTest_Distinct.distinct1.toString()).isEqualTo("distinct1"); } } diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java index 6189c97890..c3e459c2a9 100644 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java +++ b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QueryProjectionTest.java @@ -22,7 +22,6 @@ import com.querydsl.core.types.dsl.StringExpression; import jakarta.persistence.Entity; import java.util.Map; -import javax.jdo.annotations.PersistenceCapable; import org.junit.Test; public class QueryProjectionTest { @@ -30,7 +29,6 @@ public class QueryProjectionTest { // all three annotations are needed, because all are used as entity annotations @QueryEntity @Entity - @PersistenceCapable public static class EntityWithProjection { public EntityWithProjection(long id) {} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java deleted file mode 100644 index 29fa750c01..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/QuerySuperTypeTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.querydsl.apt.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.querydsl.core.annotations.QuerySupertype; -import java.util.Set; -import javax.jdo.annotations.PersistenceCapable; -import org.junit.Test; - -public class QuerySuperTypeTest { - - @QuerySupertype - public static class Supertype {} - - @PersistenceCapable - public static class JdoEntity { - Set references; - } - - @Test - public void jdoEntity() { - assertThat(QQuerySuperTypeTest_JdoEntity.jdoEntity.references.any().getClass()) - .isEqualTo(QQuerySuperTypeTest_Supertype.class); - } -} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java deleted file mode 100644 index e164ba2899..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntities.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.querydsl.apt.domain; - -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; -import org.springframework.roo.addon.jpa.entity.RooJpaEntity; - -public class RooEntities { - - @RooJpaEntity - public static class MyEntity { - - @Id Long id; - - String name; - - @ManyToOne MyEntity entity; - } - - @RooJpaActiveRecord - public static class MyEntity2 { - - @Id Long id; - - String name; - - @ManyToOne MyEntity entity; - } -} diff --git a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java b/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java deleted file mode 100644 index 19b4cfb8cc..0000000000 --- a/querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/domain/RooEntitiesTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.querydsl.apt.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class RooEntitiesTest { - - @Test - public void rooJpaEntity() { - assertThat(QRooEntities_MyEntity.myEntity).isNotNull(); - } - - @Test - public void rooJpaActiveRecord() { - assertThat(QRooEntities_MyEntity2.myEntity2).isNotNull(); - } -} diff --git a/querydsl-tooling/querydsl-codegen-utils/pom.xml b/querydsl-tooling/querydsl-codegen-utils/pom.xml index 946f79c820..250c88db79 100644 --- a/querydsl-tooling/querydsl-codegen-utils/pom.xml +++ b/querydsl-tooling/querydsl-codegen-utils/pom.xml @@ -6,7 +6,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-codegen-utils diff --git a/querydsl-tooling/querydsl-codegen/pom.xml b/querydsl-tooling/querydsl-codegen/pom.xml index d0d85e7184..4730893479 100644 --- a/querydsl-tooling/querydsl-codegen/pom.xml +++ b/querydsl-tooling/querydsl-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-codegen diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java index 83d8579b39..e35ca699b5 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/Keywords.java @@ -109,33 +109,4 @@ private Keywords() {} "VALUE", "WHEN", "WHERE")); - - public static final Collection JDO = - Collections.unmodifiableList( - Arrays.asList( - "AS", - "ASC", - "ASCENDING", - "AVG", - "BY", - "COUNT", - "DESC", - "DESCENDING", - "DISTINCT", - "EXCLUDE", - "FROM", - "GROUP", - "HAVING", - "INTO", - "MAX", - "MIN", - "ORDER", - "PARAMETERS", - "RANGE", - "SELECT", - "SUBCLASSES", - "SUM", - "UNIQUE", - "VARIABLES", - "WHERE")); } diff --git a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java index 30a6c8ba9a..745ac0a4a7 100644 --- a/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java +++ b/querydsl-tooling/querydsl-codegen/src/main/java/com/querydsl/codegen/PropertyHandling.java @@ -50,21 +50,6 @@ public Config getConfig(Class type) { return Config.NONE; } }, - /** JDO compatibility */ - JDO { - @Override - public Config getConfig(Class type) { - boolean fields = false; - boolean methods = false; - for (Field field : type.getDeclaredFields()) { - fields |= hasAnnotations(field, "javax.jdo.annotations."); - } - for (Method method : type.getDeclaredMethods()) { - methods |= hasAnnotations(method, "javax.jdo.annotations."); - } - return Config.of(fields, methods, Config.FIELDS); - } - }, /** JPA compatibility */ JPA { @Override diff --git a/querydsl-tooling/querydsl-jpa-codegen/pom.xml b/querydsl-tooling/querydsl-jpa-codegen/pom.xml index aab2751bae..a18eaefc4e 100644 --- a/querydsl-tooling/querydsl-jpa-codegen/pom.xml +++ b/querydsl-tooling/querydsl-jpa-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-jpa-codegen diff --git a/querydsl-tooling/querydsl-kotlin-codegen/pom.xml b/querydsl-tooling/querydsl-kotlin-codegen/pom.xml index c8630e74fa..ed2976550f 100644 --- a/querydsl-tooling/querydsl-kotlin-codegen/pom.xml +++ b/querydsl-tooling/querydsl-kotlin-codegen/pom.xml @@ -4,7 +4,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-kotlin-codegen diff --git a/querydsl-tooling/querydsl-maven-plugin/pom.xml b/querydsl-tooling/querydsl-maven-plugin/pom.xml index 6ef0179fc4..425b6f1cc9 100644 --- a/querydsl-tooling/querydsl-maven-plugin/pom.xml +++ b/querydsl-tooling/querydsl-maven-plugin/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-maven-plugin @@ -80,11 +80,6 @@ - - org.datanucleus - javax.jdo - provided - jakarta.persistence jakarta.persistence-api diff --git a/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java b/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java deleted file mode 100644 index 967c59f55f..0000000000 --- a/querydsl-tooling/querydsl-maven-plugin/src/main/java/com/querydsl/maven/JDOExporterMojo.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) - * - * 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.querydsl.maven; - -import com.querydsl.codegen.GenericExporter; -import com.querydsl.codegen.PropertyHandling; -import jakarta.persistence.Embedded; -import javax.jdo.annotations.EmbeddedOnly; -import javax.jdo.annotations.NotPersistent; -import javax.jdo.annotations.PersistenceCapable; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.ResolutionScope; - -/** - * {@code JDOExporterMojo} calls {@link GenericExporter} using the classpath of the module - * - * @author tiwe - */ -@Mojo(name = "jdo-export", requiresDependencyResolution = ResolutionScope.TEST) -public class JDOExporterMojo extends AbstractExporterMojo { - - @Override - protected void configure(GenericExporter exporter) { - super.configure(exporter); - exporter.setEmbeddableAnnotation(EmbeddedOnly.class); - exporter.setEmbeddedAnnotation(Embedded.class); - exporter.setEntityAnnotation(PersistenceCapable.class); - exporter.setSkipAnnotation(NotPersistent.class); - exporter.setPropertyHandling(PropertyHandling.JDO); - } -} diff --git a/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml index f4fbbca00b..67ddc7d06b 100644 --- a/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml +++ b/querydsl-tooling/querydsl-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -5,7 +5,6 @@ generic-export - jdo-export jpa-export export test-export diff --git a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java index ee6c8dc5a7..ef7d827f55 100644 --- a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java +++ b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/Entity.java @@ -4,9 +4,7 @@ import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; import java.util.Date; -import javax.jdo.annotations.PersistenceCapable; -@PersistenceCapable @jakarta.persistence.Entity @QueryEntity public class Entity { diff --git a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java b/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java deleted file mode 100644 index 4e82847a2b..0000000000 --- a/querydsl-tooling/querydsl-maven-plugin/src/test/java/com/querydsl/maven/JDOExporterMojoTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.querydsl.maven; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; -import org.apache.maven.project.MavenProject; -import org.junit.Test; - -public class JDOExporterMojoTest { - - @Test - public void execute() throws Exception { - MavenProject mavenProject = new MavenProject(); - mavenProject.getBuild().setOutputDirectory("target/classes"); - mavenProject.getBuild().setTestOutputDirectory("target/test-classes"); - - JDOExporterMojo mojo = new JDOExporterMojo(); - mojo.setTargetFolder(new File("target/generated-test-data3")); - mojo.setPackages(new String[] {"com.querydsl.maven"}); - mojo.setProject(mavenProject); - mojo.setTestClasspath(true); - mojo.execute(); - - File file = new File("target/generated-test-data3/com/querydsl/maven/QEntity.java"); - assertThat(file).exists(); - } -} diff --git a/querydsl-tooling/querydsl-sql-codegen/pom.xml b/querydsl-tooling/querydsl-sql-codegen/pom.xml index 1716106c08..67acc6bdd6 100644 --- a/querydsl-tooling/querydsl-sql-codegen/pom.xml +++ b/querydsl-tooling/querydsl-sql-codegen/pom.xml @@ -5,7 +5,7 @@ io.github.openfeign.querydsl querydsl-tooling - 6.6-SNAPSHOT + 7.0-SNAPSHOT querydsl-sql-codegen