Searches through text for a particular term and displays a table showing the cases that contain that search term. This is useful when you try to understand the context of a specific word or phrase in your text. The input text can be a Text variable, a character vector in an R Calculation Output, or the processed text from a variable created by How to Setup Text for Analysis. If you use processed text to search, the table will display both the original text input as well as the processed text.
Requirements
- Requires one of the following:
- A Setup Text Analysis object
- A Text variable, see Formatting text data below if you have more than one text variable.
- Or a character vector in a Calculation
Method - Create the search analysis
- From the toolbar, click Anything
> Advanced Analysis > Text Analysis > Advanced > Search.
- Under Data > Input select a Setup Text Analysis object, a Text variable, or a Calculation listing text.
- Enter a Search Term (in the below example, wine) and hit Enter. The output will display a table with results that include the search term.
Worked example:
In the example above, we have first processed the text from a survey question that asked people the first thought that comes to mind about France, using How to Setup Text for Analysis. Since the text has been pre-processed, the table shows both the original text and the results of the processing. If you use a text variable or character vector under Data > Input then the result will instead be a single column containing the text only. The search term that is used is the word wine, and it appears in bold when it is identified in the processed text.
Extract processed text
To get an output that contains only the processed text (i.e., the right column of keywords above), take these steps:
- From the toolbar or right click menu in the Report pane, go to Calculation
> Custom Code.
- Click onto the page to add the calculation.
- In the R Code editor, paste the code below, where text.search is the name of your Text Search output:
text.search$Processed.Text
Ensure that Calculate automatically is checked, or click Calculate.
Make the search widget interactive in View Mode
If you want viewers of your dashboard to be able to search text responses, you can create a Text Control and edit the R code of the Text Analysis - Search output to reference that instead of the field in the object inspector. To do so:
- First, create the Text Control. While on a Page, from the toolbar click Control
> Text.
- Click on the Page to place your Text Control.
- Optional - in the object inspector, you can use the Tooltip or Placeholder fields to add in helping or default text.
- Now edit the Text Analysis - Search R code to reference the text control. Select the search output and access the R code via the object inspector > Show Advanced Options > R Code > Edit Code.
- In the Code Editor press Ctrl+F and search for
formSearch
in the code. - Highlight
formSearch
and then click on the name that pops up on your Text Control to swap in the Text Control reference in the code. - Now you can type in your search term into the Text Control for searching.
Formatting text data
The feature is built to search one single variable/list of data, but sometimes you may have multiple variables you want to search at once. You can reformat your text into one variable/list to use in the tool. There are a couple of ways to do this depending on what you need.
To create a new variable in the data set that concatenates the text together
Create a new JavaScript text variable, and then in the Code Editor paste and modify the following code:
//change textVar1, textVar2 etc to the Names of your text variables
//you can additionally change " - " below to whatever you want to use to separate the responses
textVar1 + " - " + textVar2 + " - " + textVar3
To stack the text variables together in a R Calculation
You can reformat your variables into a "long" format where you stack all of the text variable data on top of one another.
- Optional: If the text variables to search are in individual sets, you need to first combine them into a single Variable Set:
- From the Data Sources tree, select the variables and right click > Duplicate.
- With the duplicates selected, right click > Combine > As a Variable Set. The Structure of the new variable set should be recognized as a Text-Multi.
- From the toolbar or right click menu in the Report pane, go to Calculation
> Custom Code.
- If using the toolbar, click on the Page to position the output.
- In the Code Editor, paste in the following code and modify as described
#specify the Text-Multi variable set to search
#put the label of the set within backticks below
textvar=`My Text Variable Set`
#make a vector
texts=unlist(textvar)
#remove names to make one column
names(texts) <- NULL
#show final text
texts - Use the output created above as the in the search output in the object inspector > Data > Input field.
Next
How to Setup Text for Analysis