Skip to content

Apply search changes #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/main/java/com/meilisearch/sdk/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ String rawSearch(String uid, String q) throws MeilisearchException {
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filter Filter queries by an attribute value
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
* @return search results, as raw data
* @throws MeilisearchException Search Exception or Client Error
Expand All @@ -68,8 +68,8 @@ String rawSearch(
String highlightPostTag,
String[] attributesToHighlight,
String[] filter,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort)
throws MeilisearchException {
String requestQuery = "/indexes/" + uid + "/search";
Expand All @@ -86,8 +86,8 @@ String rawSearch(
highlightPostTag,
attributesToHighlight,
filter,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort);
return httpClient.post(requestQuery, sr, String.class);
}
Expand Down Expand Up @@ -131,9 +131,9 @@ SearchResult search(String uid, String q) throws MeilisearchException {
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filter Filter queries by an attribute value
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
* @return search results
* @throws MeilisearchException Search Exception or Client Error
Expand All @@ -151,8 +151,8 @@ SearchResult search(
String highlightPostTag,
String[] attributesToHighlight,
String[] filter,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort)
throws MeilisearchException {
return httpClient.jsonHandler.decode(
Expand All @@ -169,8 +169,8 @@ SearchResult search(
highlightPostTag,
attributesToHighlight,
filter,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort),
SearchResult.class);
}
Expand Down
82 changes: 41 additions & 41 deletions src/main/java/com/meilisearch/sdk/SearchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class SearchRequest {
private String[] attributesToHighlight;
private String[] filter;
private String[][] filterArray;
private boolean matches;
private String[] facetsDistribution;
private boolean showMatchesPosition;
private String[] facets;
private String[] sort;

/** Empty SearchRequest constructor */
Expand All @@ -32,7 +32,7 @@ public SearchRequest() {}
/**
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
* attributesToHighlight: null, filter: null, matches: false, facetsDistribution: null, sort:
* attributesToHighlight: null, filter: null, showMatchesPosition: false, facets: null, sort:
* null
*
* @param q Query String
Expand All @@ -44,7 +44,7 @@ public SearchRequest(String q) {
/**
* Constructor for SearchRequest for building search queries with the default values: limit: 20,
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
* null, filter: null, matches: false, facetsDistribution: null, sort: null
* null, filter: null, showMatchesPosition: false, facets: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
Expand All @@ -56,7 +56,7 @@ public SearchRequest(String q, int offset) {
/**
* Constructor for SearchRequest for building search queries with the default values:
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
* null, filter: null, matches: false, facetsDistribution: null, sort: null
* null, filter: null, showMatchesPosition: false, facets: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
Expand All @@ -68,8 +68,8 @@ public SearchRequest(String q, int offset, int limit) {

/**
* Constructor for SearchRequest for building search queries with the default values:
* attributesToCrop: null, cropLength: 200, attributesToHighlight: null, filter: null, matches:
* false, facetsDistribution: null, sort: null
* attributesToCrop: null, cropLength: 200, attributesToHighlight: null, filter: null,
* showMatchesPosition: false, facets: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
Expand Down Expand Up @@ -105,9 +105,9 @@ public SearchRequest(String q, int offset, int limit, String[] attributesToRetri
* @param cropLength Length used to crop field values
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filter Filter queries by an attribute value
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
*/
public SearchRequest(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm begging for this issue be closed someday #455 haha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think it could be closed! I don't think we should keep those constructors anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too! But I prefer to finish the update before

Expand All @@ -119,8 +119,8 @@ public SearchRequest(
int cropLength,
String[] attributesToHighlight,
String[] filter,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort) {
this(
q,
Expand All @@ -135,8 +135,8 @@ public SearchRequest(
attributesToHighlight,
filter,
null,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort);
}

Expand All @@ -154,9 +154,9 @@ public SearchRequest(
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filter Filter queries by an attribute value
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
*/
public SearchRequest(
Expand All @@ -171,8 +171,8 @@ public SearchRequest(
String highlightPostTag,
String[] attributesToHighlight,
String[] filter,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort) {
this(
q,
Expand All @@ -187,8 +187,8 @@ public SearchRequest(
attributesToHighlight,
filter,
null,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort);
}

Expand All @@ -203,9 +203,9 @@ public SearchRequest(
* @param cropLength Length used to crop field values
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filterArray String array that can take multiple nested filters
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
*/
public SearchRequest(
Expand All @@ -217,8 +217,8 @@ public SearchRequest(
int cropLength,
String[] attributesToHighlight,
String[][] filterArray,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort) {
this(
q,
Expand All @@ -233,8 +233,8 @@ public SearchRequest(
attributesToHighlight,
null,
filterArray,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort);
}

Expand All @@ -252,9 +252,9 @@ public SearchRequest(
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
* @param filterArray String array that can take multiple nested filters
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param showMatchesPosition Defines whether an object that contains information about the
* matches should be returned or not
* @param facets Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
*/
public SearchRequest(
Expand All @@ -269,8 +269,8 @@ public SearchRequest(
String highlightPostTag,
String[] attributesToHighlight,
String[][] filterArray,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort) {
this(
q,
Expand All @@ -285,8 +285,8 @@ public SearchRequest(
attributesToHighlight,
null,
filterArray,
matches,
facetsDistribution,
showMatchesPosition,
facets,
sort);
}

Expand All @@ -303,8 +303,8 @@ private SearchRequest(
String[] attributesToHighlight,
String[] filter,
String[][] filterArray,
boolean matches,
String[] facetsDistribution,
boolean showMatchesPosition,
String[] facets,
String[] sort) {
this.q = q;
this.offset = offset;
Expand All @@ -318,8 +318,8 @@ private SearchRequest(
this.attributesToHighlight = attributesToHighlight;
this.setFilter(filter);
this.setFilterArray(filterArray);
this.matches = matches;
this.facetsDistribution = facetsDistribution;
this.showMatchesPosition = showMatchesPosition;
this.facets = facets;
this.sort = sort;
}

Expand Down Expand Up @@ -352,8 +352,8 @@ public String toString() {
.put("cropMarker", this.cropMarker)
.put("highlightPreTag", this.highlightPreTag)
.put("highlightPostTag", this.highlightPostTag)
.put("matches", this.matches)
.put("facetsDistribution", this.facetsDistribution)
.put("showMatchesPosition", this.showMatchesPosition)
.put("facets", this.facets)
.put("sort", this.sort)
.putOpt("attributesToCrop", this.attributesToCrop)
.putOpt("attributesToHighlight", this.attributesToHighlight)
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/meilisearch/sdk/model/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public class SearchResult implements Serializable {
protected ArrayList<HashMap<String, Object>> hits;
protected int offset;
protected int limit;
protected int nbHits;
protected boolean exhaustiveNbHits;
protected Object facetsDistribution;
protected boolean exhaustiveFacetsCount;
protected int estimatedTotalHits;
protected Object facetDistribution;
protected int processingTimeMs;
protected String query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ final class Results {
int offset;
int limit;
int nbHits;
boolean exhaustiveNbHits;
int processingTimeMs;
String query;
}
Expand Down
18 changes: 8 additions & 10 deletions src/test/java/com/meilisearch/integration/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ final class Results {
Movie[] hits;
int offset;
int limit;
int nbHits;
boolean exhaustiveNbHits;
int estimatedTotalHits;
int processingTimeMs;
String query;
}
Expand Down Expand Up @@ -59,11 +58,11 @@ public void testBasicSearch() throws Exception {

SearchResult searchResult = index.search("batman");

assertNull(searchResult.getFacetsDistribution());
assertNull(searchResult.getFacetDistribution());
assertEquals(1, searchResult.getHits().size());
assertEquals(0, searchResult.getOffset());
assertEquals(20, searchResult.getLimit());
assertEquals(1, searchResult.getNbHits());
assertEquals(1, searchResult.getEstimatedTotalHits());
}

/** Test search offset */
Expand All @@ -81,7 +80,7 @@ public void testSearchOffset() throws Exception {
SearchResult searchResult = index.search(searchRequest);

assertEquals(10, searchResult.getHits().size());
assertEquals(30, searchResult.getNbHits());
assertEquals(30, searchResult.getEstimatedTotalHits());
}

/** Test search limit */
Expand All @@ -99,7 +98,7 @@ public void testSearchLimit() throws Exception {
SearchResult searchResult = index.search(searchRequest);

assertEquals(2, searchResult.getHits().size());
assertEquals(30, searchResult.getNbHits());
assertEquals(30, searchResult.getEstimatedTotalHits());
}

/** Test search attributesToRetrieve */
Expand Down Expand Up @@ -316,13 +315,12 @@ public void testSearchFacetsDistribution() throws Exception {
settings.setFilterableAttributes(new String[] {"title"});
index.waitForTask(index.updateSettings(settings).getUid());

SearchRequest searchRequest =
new SearchRequest("knight").setFacetsDistribution(new String[] {"*"});
SearchRequest searchRequest = new SearchRequest("knight").setFacets(new String[] {"*"});

SearchResult searchResult = index.search(searchRequest);

assertEquals(1, searchResult.getHits().size());
assertNotNull(searchResult.getFacetsDistribution());
assertNotNull(searchResult.getFacetDistribution());
}

/** Test search sort */
Expand Down Expand Up @@ -454,7 +452,7 @@ public void testSearchMatches() throws Exception {

index.waitForTask(task.getUid());

SearchRequest searchRequest = new SearchRequest("and").setMatches(true);
SearchRequest searchRequest = new SearchRequest("and").setShowMatchesPosition(true);
SearchResult searchResult = index.search(searchRequest);

assertEquals(20, searchResult.getHits().size());
Expand Down
Loading