Skip to content
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

Fix Graph Filter Error in Search #5665

Merged
merged 9 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add check for GraphTokenStreamFiniteStrings is empty
Signed-off-by: Mingshi Liu <mingshl@amazon.com>
  • Loading branch information
mingshl committed Jan 6, 2023
commit 4f9858d889d757a4878283bd5a5e402255802668
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Apply cluster manager throttling settings during bootstrap ([#5524](https://github.com/opensearch-project/OpenSearch/pull/5524))
- Update thresholds map when cluster manager throttling setting is removed ([#5524](https://github.com/opensearch-project/OpenSearch/pull/5524))
- Fix backward compatibility for static cluster manager throttling threshold setting ([#5633](https://github.com/opensearch-project/OpenSearch/pull/5633))
- Fix index exclusion behavior in snapshot restore and clone APIs ([#5626](https://github.com/opensearch-project/OpenSearch/pull/5626))
- Fix graph filter error in search ([#5665](https://github.com/opensearch-project/OpenSearch/pull/5665))

### Security

[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.4...HEAD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
import static org.opensearch.common.lucene.search.Queries.newLenientFieldQuery;
import static org.opensearch.common.lucene.search.Queries.newUnmappedFieldQuery;

import java.util.logging.Logger;

/**
* Foundation match query
*
Expand Down Expand Up @@ -135,11 +133,6 @@ public void writeTo(StreamOutput out) throws IOException {
}
}

/**
* logging function
*/
private static final Logger logger = Logger.getLogger((MatchQuery.class.getName()));

/**
* Query with zero terms
*
Expand Down Expand Up @@ -760,17 +753,13 @@ private Query analyzeGraphBoolean(String field, TokenStream source, BooleanClaus
final Query queryPos;
boolean usePrefix = isPrefix && end == -1;
/**
* comment out the fix and mimic the error in unit test from MatchQueryBuilderTests.java
* check if the GraphTokenStreamFiniteStrings graph is empty
* return empty BooleanQuery result
*/

// boolean graphHasSidePath = false;
// try {
// graphHasSidePath = graph.hasSidePath(start);
// } catch (AssertionError e) {
// logger.info("GraphTokenStreamFiniteStrings has no path. Catch assertion error: \n" + e);
// return zeroTermsQuery();
// }
// if (graphHasSidePath) {
Iterator<TokenStream> graphIt = graph.getFiniteStrings();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks much better, thanks @mingshl !

if(!graphIt.hasNext()){
return builder.build();
}
if (graph.hasSidePath(start)) {
final Iterator<TokenStream> it = graph.getFiniteStrings(start, end);
Iterator<Query> queries = new Iterator<Query>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.index.query;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.tests.analysis.CannedBinaryTokenStream;
import org.apache.lucene.tests.analysis.MockSynonymAnalyzer;
import org.apache.lucene.index.Term;
Expand Down Expand Up @@ -68,11 +69,7 @@
import org.hamcrest.Matcher;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;

import static org.hamcrest.CoreMatchers.either;
import static org.hamcrest.CoreMatchers.instanceOf;
Expand Down Expand Up @@ -333,9 +330,13 @@ public void testMatchQueryWithNoSidePath() throws Exception {
MockGraphAnalyzer mockAnalyzer = new MockGraphAnalyzer(createGiantGraphWithNoSide());
testMatchQuery.setAnalyzer(mockAnalyzer);
testMatchQuery.setAutoGenerateSynonymsPhraseQuery(true);
testMatchQuery.setZeroTermsQuery(ZeroTermsQuery.NONE);
GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(mockAnalyzer.getTokenStream());
AssertionError e = expectThrows(AssertionError.class, () -> graph.hasSidePath(0));
assertEquals("state=0 nextState=0", e.getMessage());
Iterator<TokenStream> graphIt = graph.getFiniteStrings();
assertEquals(graphIt.hasNext(),false);
String testField = "Gas Lift Storage Bed Frame with Arched Bed Head in King";
String testValue = "head board, bed head, bedhead, headboard";
testMatchQuery.parse(Type.BOOLEAN,testField,testValue); // no exception
}

public void testDefaultFuzziness() {
Expand Down Expand Up @@ -503,6 +504,7 @@ public void testAutoGenerateSynonymsPhraseQuery() throws Exception {
}
}


public void testMultiWordSynonymsPhrase() throws Exception {
final MatchQuery matchQuery = new MatchQuery(createShardContext());
matchQuery.setAnalyzer(new MockSynonymAnalyzer());
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.