-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for query tokenization parameters #435
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
Draft
matt-bernhardt
wants to merge
2
commits into
main
Choose a base branch
from
use-636
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ class QueryBuilder | |
| GEO_PARAMS = %w[geoboxMinLongitude geoboxMinLatitude geoboxMaxLongitude geoboxMaxLatitude geodistanceLatitude | ||
| geodistanceLongitude geodistanceDistance].freeze | ||
| VALID_QUERY_MODES = %w[keyword semantic hybrid].freeze | ||
| TOKENIZATION_PARAMS = %w[semanticDropBoostThreshold semanticMustBoostThreshold semanticShortQueryMaxTokens].freeze | ||
|
|
||
| def initialize(enhanced_query) | ||
| @query = {} | ||
|
|
@@ -22,6 +23,7 @@ def initialize(enhanced_query) | |
| extract_geosearch(enhanced_query) | ||
| extract_filters(enhanced_query) | ||
| evaluate_query_mode(enhanced_query) | ||
| extract_tokenization_params(enhanced_query) | ||
| @query['index'] = ENV.fetch('TIMDEX_INDEX', nil) | ||
| @query['booleanType'] = enhanced_query[:booleanType] | ||
| @query.compact! | ||
|
|
@@ -59,9 +61,20 @@ def extract_filters(enhanced_query) | |
| end | ||
| end | ||
|
|
||
| # The GraphQL API requires that lat/long in geospatial fields be floats | ||
| def coerce_to_float?(geo_param) | ||
| geo_param.to_s.include?('Longitude') || geo_param.to_s.include?('Latitude') | ||
| # We treat the tokenization parameters separately because we need to ensure that floats and integers are formatted | ||
| # correctly. | ||
| def extract_tokenization_params(enhanced_query) | ||
| TOKENIZATION_PARAMS.each do |tp| | ||
| next unless enhanced_query[tp.to_sym].present? | ||
|
|
||
| @query[tp] = coerce_to_float?(tp) ? enhanced_query[tp.to_sym]&.strip.to_f : enhanced_query[tp.to_sym]&.strip.to_i | ||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| # The GraphQL API requires that some parameters - lat/long in geospatial fields and boost thresholds for tuning - be | ||
| # floats. | ||
| def coerce_to_float?(param) | ||
| param.to_s.include?('Longitude') || param.to_s.include?('Latitude') || param.to_s.include?('BoostThreshold') | ||
| end | ||
|
|
||
| # Determine the query mode from URL parameter or config, with fallback to 'keyword' | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1183,6 +1183,26 @@ def source_filter_count(controller) | |
| assert_select '.pagination-container .current', text: /21 - 40 of 800/ | ||
| end | ||
|
|
||
| # test 'results can include tuning parameters' do | ||
| # query = 'optical networks in space' | ||
| # must_default = 0.7 | ||
| # drop_default = 0.1 | ||
| # must_alt = 0.9 | ||
| # drop_alt = 0.4 | ||
|
|
||
| # VCR.use_cassette('default tuning for stock query') do | ||
| # get "/results?q=#{query}&semanticMustBoostThreshold=#{must_default}&semanticDropBoostThreshold=#{drop_default}&tab=timdex" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| # assert_response :success | ||
| # end | ||
|
|
||
| # VCR.use_cassette('alternate tuning for stock query') do | ||
| # get "/results?q=#{query}&semanticMustBoostThreshold=#{must_alt}&semanticDropBoostThreshold=#{drop_alt}&tab=timdex" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| # assert_response :success | ||
| # end | ||
|
|
||
| # # Assert result counts are different | ||
| # end | ||
|
|
||
| test 'results can be returned in JSON format when env is set and valid token is provided' do | ||
| secret_value = 'sooper_sekret' | ||
| quepid_ua = 'Quepid/1.0 (Web Scraper)' | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 2 issues:
1. Assignment Branch Condition size for
initializeis too high. [<7, 20, 5> 21.77/17] [rubocop:Metrics/AbcSize]2. Method has too many lines. [15/10] [rubocop:Metrics/MethodLength]