Skip to content

Commit 60e878f

Browse files
authored
Merge pull request #381 from MITLibraries/use-493
Add feature to enable semantic search
2 parents d3ff02f + 4f3492b commit 60e878f

14 files changed

Lines changed: 1142 additions & 133 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ may have unexpected consequences if applied to other TIMDEX UI apps.
106106
- `FEATURE_TAB_TIMDEX_ALL`: Display a tab for displaying the combined TIMDEX data. `TIMDEX_INDEX` affects which data appears in this tab.
107107
- `FEATURE_TAB_TIMDEX_ALMA`: Display a tab for displaying Alma data from TIMDEX. `TIMDEX_INDEX` must include `Alma` data or no results will return.
108108
- `FEATURE_TIMDEX_FULLTEXT`: Activate fulltext searching for sources in TIMDEX that support it
109+
- `FEATURE_TIMDEX_SEMANTIC_SEARCH`: Enables semantic query mode (`queryMode: semantic`) for TIMDEX searches. When disabled, TIMDEX defaults to lexical search behavior.
109110
- `FEATURE_PRIMO_NDE_LINKS`: Enables all Primo UI links to target the NDE version of Primo. When enabled, links will use `/nde/search` and `/nde/fulldisplay` paths along with the NDE view ID from `PRIMO_NDE_VID`.
110111
- `FILTER_ACCESS_TO_FILES`: The name to use instead of "Access to files" for that filter / aggregation.
111112
- `FILTER_CONTENT_TYPE`: The name to use instead of "Content type" for that filter / aggregation.

app/controllers/search_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ def query_primo(per_page, offset)
217217
end
218218

219219
def execute_geospatial_query(query)
220+
query = query.except('queryMode')
221+
220222
if query['geobox'] == 'true' && query[:geodistance] == 'true'
221223
TimdexBase::Client.query(TimdexSearch::AllQuery, variables: query)
222224
elsif query['geobox'] == 'true'

app/models/feature.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class Feature
3535
# List of all valid features in the application
3636
VALID_FEATURES = %i[bot_detection geodata boolean_picker oa_always primo_nde_links simulate_search_latency tab_primo_all tab_timdex_all
37-
tab_timdex_alma record_link timdex_fulltext].freeze
37+
tab_timdex_alma record_link timdex_fulltext timdex_semantic_search].freeze
3838

3939
# Check if a feature is enabled by name
4040
#

app/models/query_builder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def initialize(enhanced_query)
2020
extract_query(enhanced_query)
2121
extract_geosearch(enhanced_query)
2222
extract_filters(enhanced_query)
23+
@query['queryMode'] = 'semantic' if Feature.enabled?(:timdex_semantic_search)
2324
@query['index'] = ENV.fetch('TIMDEX_INDEX', nil)
2425
@query['booleanType'] = enhanced_query[:booleanType]
2526
@query.compact!

app/models/timdex_search.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TimdexSearch < TimdexBase
1515
$index: String
1616
$from: String
1717
$booleanType: String
18+
$queryMode: String
1819
$fulltext: Boolean
1920
$perPage: Int
2021
$accessToFilesFilter: [String!]
@@ -39,6 +40,7 @@ class TimdexSearch < TimdexBase
3940
index: $index
4041
from: $from
4142
booleanType: $booleanType
43+
queryMode: $queryMode
4244
fulltext: $fulltext
4345
perPage: $perPage
4446
accessToFilesFilter: $accessToFilesFilter

config/schema/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,16 @@
13601360
},
13611361
"defaultValue": "\"OR\""
13621362
},
1363+
{
1364+
"name": "queryMode",
1365+
"description": "Search mode to use. Defaults to \"lexical\". Options include: \"lexical\", \"semantic\"",
1366+
"type": {
1367+
"kind": "SCALAR",
1368+
"name": "String",
1369+
"ofType": null
1370+
},
1371+
"defaultValue": "\"lexical\""
1372+
},
13631373
{
13641374
"name": "accessToFilesFilter",
13651375
"description": "Filter results by access type. Use the `AccessToFiles` aggregation for a list of possible values. Multiple values are ORed.",

test/models/query_builder_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,16 @@ class QueryBuilderTest < ActiveSupport::TestCase
120120
}
121121
assert_equal expected, QueryBuilder.new(search).query
122122
end
123+
124+
test 'query builder defaults to lexical mode by omitting queryMode' do
125+
search = { q: 'blah' }
126+
refute_includes(QueryBuilder.new(search).query.keys, 'queryMode')
127+
end
128+
129+
test 'query builder adds semantic queryMode when feature flag is enabled' do
130+
ClimateControl.modify FEATURE_TIMDEX_SEMANTIC_SEARCH: 'true' do
131+
search = { q: 'blah' }
132+
assert_equal('semantic', QueryBuilder.new(search).query['queryMode'])
133+
end
134+
end
123135
end

test/vcr_cassettes/data.yml

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/data_from_ridiculous_start.yml

Lines changed: 17 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/data_page_2.yml

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)