Skip to content

Commit

Permalink
Merge #748
Browse files Browse the repository at this point in the history
748: Add frequency matching strategy r=curquiza a=the-sinner

# Pull Request

## Related issue
Fixes #754 

## What does this PR do?
- Add feature matching strategy

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Shalabh Agarwal <shalabhagarwal1024@gmail.com>
  • Loading branch information
meili-bors[bot] and the-sinner authored Jul 6, 2024
2 parents 36a10b9 + 9d259c7 commit 452a00e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ search_parameter_guide_matching_strategy_1: |-
search_parameter_guide_matching_strategy_2: |-
SearchRequest searchRequest = SearchRequest.builder().q("big fat liar").matchingStrategy(MatchingStrategy.ALL).build();
client.index("movies").search(searchRequest);
search_parameter_guide_matching_strategy_3: |-
SearchRequest searchRequest = SearchRequest.builder().q("white shirt").matchingStrategy(MatchingStrategy.FREQUENCY).build();
client.index("movies").search(searchRequest);
search_parameter_guide_attributes_to_search_on_1: |-
SearchRequest searchRequest = SearchRequest.builder().q("adventure").attributesToSearchOn(new String[] {"overview"});
client.index("movies").searchRequest(searchRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public enum MatchingStrategy {
@SerializedName("all")
ALL("all"),
@SerializedName("last")
LAST("last");
LAST("last"),
@SerializedName("frequency")
FREQUENCY("frequency");

public final String matchingStrategy;

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/meilisearch/integration/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,28 @@ public void testSearchWithMatchingStrategy() throws Exception {
assertThat(searchResult.getEstimatedTotalHits(), is(equalTo(21)));
}

/** Test search with frequency matching strategy */
@Test
public void testSearchWithFrequencyMatchingStrategy() throws Exception {
String indexUid = "SearchFrequencyMatchingStrategy";
Index index = client.index(indexUid);

TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class);
TaskInfo task = index.addDocuments(testData.getRaw());

index.waitForTask(task.getTaskUid());

SearchRequest searchRequest =
SearchRequest.builder()
.q("white shirt")
.matchingStrategy(MatchingStrategy.FREQUENCY)
.build();

SearchResult searchResult = (SearchResult) index.search(searchRequest);

assertThat(searchResult.getHits(), hasSize(4));
}

/** Test search with show ranking score */
@Test
public void testSearchWithShowRankingScore() throws Exception {
Expand Down

0 comments on commit 452a00e

Please sign in to comment.