Skip to content

Commit

Permalink
add benchmark phrase query (#1366)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
* In the benchmark, es client and quickwit client support phrase query
* Recover phrase query sqllogic test

### Type of change
- [x] New Feature
- [x] Refactoring
  • Loading branch information
Ma-cat authored Jun 21, 2024
1 parent b945c7c commit 47fa26f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/references/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Following are commands to issue a single query so that you can compare results a
```base
curl -X GET "http://localhost:9200/elasticsearch_enwiki/_search" -H 'Content-Type: application/json' -d'{"size":10,"_source":"doctitle","query": {"match": { "body": "wraysbury istorijos" }}}'
curl -X GET "http://localhost:7280/api/v1/_elastic/qucikwit_enwiki/_search" -H 'Content-Type: application/json' -d'{"query": {"query_string": {"query": "wraysbury istorijos", "fields": [ "body" ] } },"sort": ["_score"]}'
curl -X GET "http://localhost:7280/api/v1/_elastic/qucikwit_enwiki/_search" -H 'Content-Type: application/json' -d'{"query": {"query_string": {"query": "wraysbury istorijos", "fields": [ "body" ] } },"sort": ["_score"],"size":10}'
psql -h 0.0.0.0 -p 5432 -c "SELECT doctitle, ROW_ID(), SCORE() FROM infinity_enwiki SEARCH MATCH TEXT ('body', 'wraysbury istorijos', 'topn=10');"
```
Expand Down
9 changes: 8 additions & 1 deletion python/benchmark/clients/elasticsearch_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ def get_fulltext_query_content(self, query: str, is_and: bool = False) -> Any:
}
}
else:
ret = {"query": {"match": {"body": query}}}
is_phrase = False
query = query.lstrip()
if query.startswith('"'):
is_phrase = True
if is_phrase:
ret = {"query": {"match_phrase": {"body": query}}}
else:
ret = {"query": {"match": {"body": query}}}
return ret

def setup_clients(self, num_threads=1):
Expand Down
27 changes: 22 additions & 5 deletions python/benchmark/clients/quickwit_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,27 @@ def get_fulltext_query_content(self, query: str, is_and: bool = False) -> Any:
}
}
else:
ret = {
"query": {"query_string": {"query": query, "fields": ["body"]}},
"sort": ["_score"],
}
is_phrase = False
query = query.lstrip()
if query.startswith('"'):
is_phrase = True

if is_phrase:
ret = {
"query": {
"match_phrase": {"body": query}
},
"sort": ["_score"],
"size": self.data["topK"]
}
else:
ret = {
"query": {
"query_string": {"query": query, "fields": ["body"]}
},
"sort": ["_score"],
"size": self.data["topK"]
}
return ret

def setup_clients(self, num_threads=1):
Expand All @@ -202,7 +219,7 @@ def do_single_query(self, query_id, client_id) -> list[Any]:
query = self.queries[query_id]
client = self.clients[client_id]
if self.data["mode"] == "fulltext":
body = self.get_fulltext_query_content(query)
body = self.get_fulltext_query_content(query=query)
body["size"] = self.data["topK"]

result = client.search(
Expand Down
18 changes: 9 additions & 9 deletions test/sql/dql/fulltext/fulltext.slt
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ SELECT doctitle, docdate, ROW_ID(), SCORE() FROM enwiki SEARCH MATCH TEXT ('body
Anarchism 30-APR-2012 03:25:17.000 0 21.620300

# only phrase
# query TTI rowsort
# SELECT doctitle, docdate, ROW_ID(), SCORE() FROM enwiki SEARCH MATCH TEXT ('body^5', '"social customs"', 'topn=3;block_max=compare');
# ----
# Anarchism 30-APR-2012 03:25:17.000 6 20.881144
query TTI rowsort
SELECT doctitle, docdate, ROW_ID(), SCORE() FROM enwiki SEARCH MATCH TEXT ('body^5', '"social customs"', 'topn=3;block_max=compare');
----
Anarchism 30-APR-2012 03:25:17.000 6 20.881144

# phrase and term
# query TTI rowsort
# SELECT doctitle, docdate, ROW_ID(), SCORE() FROM enwiki SEARCH MATCH TEXT ('doctitle,body^5', '"social customs" harmful', 'topn=3');
# ----
# Anarchism 30-APR-2012 03:25:17.000 0 21.620300
# Anarchism 30-APR-2012 03:25:17.000 6 20.881144
query TTI rowsort
SELECT doctitle, docdate, ROW_ID(), SCORE() FROM enwiki SEARCH MATCH TEXT ('doctitle,body^5', '"social customs" harmful', 'topn=3');
----
Anarchism 30-APR-2012 03:25:17.000 0 21.620300
Anarchism 30-APR-2012 03:25:17.000 6 20.881144

# copy data from csv file
query I
Expand Down

0 comments on commit 47fa26f

Please sign in to comment.