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

ROOT-198: remove default field from queries, make autocomplete wildcard* configurable #29

Conversation

jesconstantine
Copy link
Collaborator

This PR implements latest updates to palantirnet/solr-faceted-search-react#7 which makes the search app un-opinionated about main + autocomplete query default / query fields. This allows flexibility with the default search, autocomplete, and enables field boosting to be set in solr config.

Queries now have the following structure:

  • main query: q=<mainQueryField.value> as opposed to q=tm_rendered_item:<mainQueryField.value>
  • autocomplete query when autocomplete.appendWildcard is true: q=<mainQueryField.value>+<mainQueryField.value>*&df=mainQueryField.field
  • autocomplete query when autocomplete.appendWildcard is false (default): q=<mainQueryField.value>

See the updates to the solr client repo tests for more details.

To accommodate these updates, this PR also updates the autocomplete config in the example config file.

To Test

Set up your drupals - if you're still set up from the last demo site PR, you should be good to go

  1. Make sure you follow the steps in Fix mapped terms indexing federated-search-demo#20 to fix your index and ensure that federated terms are added to the index

Get your local app environment set up

  1. Pull this branch down
  2. Update the version of the search app dependency with yarn install

Add new autocomplete config

  1. Observe updates to the src/env.local.js.example file
  2. Add configuration to set autocomplete.appendWildcard to true, here is what
    mine looks like:
module.exports = {
  // REQUIRED: The default solr backend.
  // url: "https://ss826806-us-east-1-aws.measuredsearch.com:443/solr/master/select",
  url: "http://federated-search-demo.local:8983/solr/drupal8/select",
  // userpass: btoa("palantir:palantirqauser"),
  // OPTIONAL: The text to display when a search returns no results.
  // noResults: "Sorry, your search yielded no results.",
  // OPTIONAL: The text to display when the app loads with no search term.
  searchPrompt: "Please enter a search term.",
  // OPTIONAL: The number of search results to show per page.
  rows: 20,
  // OPTIONAL: The number of page buttons to show for pagination.
  paginationButtons: 5,
  // OPTIONAL: Machine name of those search fields whose facets/filter and current values should be hidden in UI.
  hiddenSearchFields: [
    // 'sm_site_name',
    // 'ss_federated_type',
    // 'ds_federated_date',
    // 'sm_federated_terms',
  ],
  // OPTIONAL: Provides config for adding autocomplete functionality to text search
  autocomplete: {
    url: 'http://federated-search-demo.local:8983/solr/drupal8/select',
    appendWildcard: true,
    suggestionRows: 5,
    numChars: 2,
    mode: 'result',
    result: {
      titleText: 'What are you interested in?',
      showDirectionsText: true,
    },
  }
};

Verify when autocomplete.appendWildcard = true a wildcard query is sent

  1. Start the app with yarn start
  2. The search app should load in a new browser window
  3. Open your browser devTools (COMMAND + alt + i) for chrome / firefox
  4. Click the Network tab of your devtools
  5. Ensure that you aren't filtering any network requests by type, or at least ensure XHR is included in your filter
    • Chrome:
      image
    • Firefox:
      image
  6. Refresh the page to start logging network traffic

Confirm: Single word/chunks are sent with chunk+chunk*

  1. Type car into the search field
  2. Observe there are 5 results returned
  3. Click on the request for the autocomplete query request
  4. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  5. Observe the query q param is car car*
  6. Observe there is no default field param sent &df=
    image

Confirm: Single world/chunks ending in a space are trimmed

  1. Type car (note trailing space) into the search field
  2. Observe the same 5 results are returned
  3. Click on the request for the autocomplete query request
  4. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  5. Observe the query q param is still car car*
  6. Observe there is no default field param sent &df=
    image

Confirm multiple word/chunks are sent with word1+chunk2+chunk2*

  1. Type so m into the search field
  2. Click on the request for the autocomplete query request
  3. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  4. Observe the query q param is still so m m*
  5. Observe there is no default field param sent &df=
    image

Verify when autocomplete.appendWildcard is either false or not set, no wildcard is appended to the query

  1. Type car into the search field
  2. Observe there is only 1 result returned
  3. Click on the request for the autocomplete query request
  4. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  5. Observe the query q param is car
  6. Observe there is no default field param sent &df=
    image

Verify trailing spaces are still trimmed from the query

  1. Type car (note the trailing space) into the search field
  2. Observe there is only 1 result returned
  3. Click on the request for the autocomplete query request
  4. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  5. Observe the query q param is car
  6. Observe there is no default field param sent &df=
    image

Verify that when no autocomplete.suggestionRows value is set, it defaults to 5

  1. Comment out the line setting autocomplete.suggestionRows in your env.local.js file
  2. Set autocomplete.appendWildcard to true
  3. When the app reloads, type car into the search field
  4. Observe there are 5 results returned

Verify that the main search query no longer sets a default search field in the query: q=tm_rendered_item:<value>

  1. Search for carrot
  2. Click on the request for the search query request
  3. Browse to the params / form data (if you can view source vs parsed it will be most helpful)
  4. Observe the query q param is carrot and not tm_rendered_item:carrot
    image

* adds appendWildcard (defaults to false)
* makes suggestionRows optional  (defaults to 5)
* removes suggestQueryField (sets to mainQueryField)
Copy link
Contributor

@agentrickard agentrickard left a comment

Choose a reason for hiding this comment

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

Works as designed.

@agentrickard agentrickard merged commit b139db4 into root-198-autocomplete-component Mar 6, 2019
@jesconstantine jesconstantine deleted the root-198-remove-default-field-from-query branch March 13, 2019 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants