Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored, created searchQuery interface based, NativeSearchQueryBui…
…lder support
- Loading branch information
Showing
13 changed files
with
252 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.data.elasticsearch.core.query; | ||
|
||
|
||
import org.elasticsearch.index.query.FilterBuilder; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.search.sort.SortBuilder; | ||
|
||
/** | ||
* NativeSearchQuery | ||
* | ||
* @author Rizwan Idrees | ||
* @author Mohsin Husen | ||
*/ | ||
public class NativeSearchQuery extends AbstractQuery implements SearchQuery { | ||
|
||
private QueryBuilder query; | ||
private FilterBuilder filter; | ||
private SortBuilder sort; | ||
|
||
public NativeSearchQuery(QueryBuilder query, FilterBuilder filter, SortBuilder sort) { | ||
this.query = query; | ||
this.filter = filter; | ||
this.sort = sort; | ||
} | ||
|
||
public QueryBuilder getQuery() { | ||
return query; | ||
} | ||
|
||
|
||
public FilterBuilder getFilter() { | ||
return filter; | ||
} | ||
|
||
public SortBuilder getElasticsearchSort() { | ||
return sort; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQueryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.data.elasticsearch.core.query; | ||
|
||
import org.elasticsearch.index.query.FilterBuilder; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.search.sort.SortBuilder; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
/** | ||
* NativeSearchQuery | ||
* | ||
* @author Rizwan Idrees | ||
* @author Mohsin Husen | ||
*/ | ||
|
||
public class NativeSearchQueryBuilder { | ||
|
||
private QueryBuilder queryBuilder; | ||
private FilterBuilder filterBuilder; | ||
private SortBuilder sortBuilder; | ||
private Pageable pageable; | ||
private String[] indices; | ||
private String[] types; | ||
private String[] fields; | ||
|
||
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder){ | ||
this.queryBuilder = queryBuilder; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withFilter(FilterBuilder filterBuilder){ | ||
this.filterBuilder = filterBuilder; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withSort(SortBuilder sortBuilder){ | ||
this.sortBuilder = sortBuilder; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withPageable(Pageable pageable){ | ||
this.pageable = pageable; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withIndices(String... indices){ | ||
this.indices = indices; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withTypes(String... types){ | ||
this.types = types; | ||
return this; | ||
} | ||
|
||
public NativeSearchQueryBuilder withFields(String... fields){ | ||
this.fields = fields; | ||
return this; | ||
} | ||
|
||
public NativeSearchQuery build(){ | ||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder,filterBuilder,sortBuilder); | ||
if(pageable != null){ | ||
nativeSearchQuery.setPageable(pageable); | ||
} | ||
if(indices != null) { | ||
nativeSearchQuery.addIndices(indices); | ||
} | ||
if(types != null) { | ||
nativeSearchQuery.addTypes(types); | ||
} | ||
if(fields != null) { | ||
nativeSearchQuery.addFields(fields); | ||
} | ||
return nativeSearchQuery; | ||
} | ||
} |
55 changes: 4 additions & 51 deletions
55
src/main/java/org/springframework/data/elasticsearch/core/query/SearchQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,11 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.data.elasticsearch.core.query; | ||
|
||
|
||
import org.elasticsearch.index.query.FilterBuilder; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.search.sort.SortBuilder; | ||
|
||
/** | ||
* SearchQuery | ||
* | ||
* @author Rizwan Idrees | ||
* @author Mohsin Husen | ||
*/ | ||
public class SearchQuery extends AbstractQuery{ | ||
|
||
private QueryBuilder elasticsearchQuery; | ||
private FilterBuilder elasticsearchFilter; | ||
private SortBuilder elasticsearchSort; | ||
|
||
public QueryBuilder getElasticsearchQuery() { | ||
return elasticsearchQuery; | ||
} | ||
|
||
public void setElasticsearchQuery(QueryBuilder elasticsearchQuery) { | ||
this.elasticsearchQuery = elasticsearchQuery; | ||
} | ||
|
||
public FilterBuilder getElasticsearchFilter() { | ||
return elasticsearchFilter; | ||
} | ||
|
||
public void setElasticsearchFilter(FilterBuilder elasticsearchFilter) { | ||
this.elasticsearchFilter = elasticsearchFilter; | ||
} | ||
|
||
public SortBuilder getElasticsearchSort() { | ||
return elasticsearchSort; | ||
} | ||
|
||
public void setElasticsearchSort(SortBuilder elasticsearchSort) { | ||
this.elasticsearchSort = elasticsearchSort; | ||
} | ||
public interface SearchQuery extends Query { | ||
QueryBuilder getQuery(); | ||
FilterBuilder getFilter(); | ||
SortBuilder getElasticsearchSort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.