Spring data Mongo db sort based on substring - mongodb

I have data like
John Willis Tampa, FL
Jane El Orlando, FL
Rick Manning Chicago, IL
Jason Woods Miami, FL
If a user searches for residents in Orlando, I would like to select all residents in Orlando and later append all residents living in Florida. So the result set should be like
Jane El Orlando FL
John Willis Tampa, Florida
Jason Woods Miami, FL
Last two records could be in any order but Orlando, FL should be first since user is searching for Orlando, FL
I can use the following criteria
criteria = Criteria.where("cityState").regex(", FL")
But how to sort is such that all the records with cityState = Orlando, FL will first.

Related

Tableau Calculation with a Filter in place

I'm trying to get the count of calls received by an individuals, both initial answer and any possible transferred over by another person.
My workbook has a filter based on the individual who first answers the phone. Now I need to add in any calls that were transferred over. These calls are usually answered by another individual.
This is what I would like to see
John: #calls =3 | #calls Transferred to =1
Where the data would show this:
Incoming | Transferred to
John | James
John | NUll
John | NUll
James | John
Does anybody have a way to get in the last call to be attribute it to John with the filter in place?
My filter of John would give me the three calls, but would remove the transferred call.
Try creating two calculated fields using the following formulas and then use them as filters.
Filter - John
if contains([Incoming], "John") then "John"
ELSEif
CONTAINS([Transferred to], "John") then "John"
END
Filter - James
if contains([Incoming], "James") then "James"
ELSEif
CONTAINS([Transferred to], "James") then "James"
END

Count Number of Rows with Condition

I have a document names.csv with two columns. I want to count the number of rows that have the same values and modify the document to display the count using Powershell. For example:
Joe Florida
Joe California
Joe Florida
Bob Texas
Joe Texas
Joe Florida
Joe Florida
Bob Minnesota
Joe California
I want the output to be:
Bob Minnesota 1
Bob Texas 1
Joe California 2
Joe Florida 4
Joe Texas 1
This needs to be generic because column 1 will contain an arbitrary number of names. I really do not know where to begin. Please only answer with full names (do not say gc for Get-Content).
You can use the Group-Object cmdlet here like below.
If csv is like below
Name,Place
Joe,Florida
Joe,California
Joe,Florida,
Bob,Texas
Joe,Texas
Joe,Florida
Joe,Florida
Bob,Minnesota
Joe,California
Import-Csv -Path C:\Temp\Temp.csv | Group-Object -Property Name,Place
You can put your own logic to write it to new csv.

Utilizing City and County Data Together

I have a bunch of people related data where the only geographical field is "City, State":
Client | Location | Salesperson
Company A | Albany, NY | Joe
Company B | Atlanta, GA | Steve
Company C | Baltimore, MD | Lisa
Company D | Wichita, KS | Suzy
Company E | Portland, OR | Steve
Company F | Spokane, WA | Suzy
Company G | Mobile, AL | Joe
Company H | Elizabeth, NJ | Lisa
That third row is the salesperson. The problem is, each territory is defined by customized regions based off of counties. For example, the New York metropolitan area is defined by the counties listed here.
So a couple questions. First, how do I add in that data to Tableau (where I have all cities and counties). The second is, how can I create somewhere say, I wanted to see performance based on salesperson by region. So like, say I wanted a breakdown of how each sales person performed in the New York Metro area. That would involve me evaluating based on the cities within a customized region based off counties. So in the above table, Lisa's sale in Elizabeth, NJ would be credited as a sale in the New York Metro area.
You'll have to forgive me, I'm a bit of a neophyte in Tableau.

Sphins Regexp maps to only single words

I am trying to map regexp so when a user enters a specific word I force them to choose a specific other term in the table.
For instance I have as simple example fields:
Bob
Bob Smith
Bob Jones
Sally
Sally Smith
Sally Jones
If I do
regexp_filter=Bob>Bob Smith to make sure when a user simply enters Bob I push Bob Smith instead and then do a sphinql search:
Select * from Index where MATCH('Bob')
I still get all the Bob records (in other words it did not interpret as Bob Smith
However if I dod
regexp_filter=Bob=>Sally
Then Select * from Index where MATCH('Bob') returns all the Sally records.
I am "simply" trying to force the index to return the Bob Jones record should a user simply search on Bob.
FYI I did try
Select * from Index where MATCH('^Bob$')
and that returned NULL
I still get all the Bob records (in other words it did not interpret as Bob Smith
Because the regex is applied to BOTH the query text and document text during indexing. So becomes MATCH('Bob Smith'), but your documents also become
Bob Smith
Bob Smith Smith
Bob Smith Jones
... so your query, matches all three documents, same if didnt have the regex!
I am "simply" trying to force the index to return the Bob Jones record should a user simply search on Bob.
Wonder if you meaning should NOT return ?
... in which case can use MATCH('^Bob$') but rememeber to remove the regex. Or could perhaps use MATCH('"^Bob$"') an extra set of quotes to use phrase mode.
Try also MATCH('^Bob$ ') with a space! some versions of sphinx has a bug unless a space after the $!

Search a dataframe using another dataframe or RDD

I have 2 dataframes in apache spark.
df 1 has the show number and descriptions... the data looks like
show_no | descrip
a | this is mikey
b | here comes donald
c | mary and george go home
d | mary and george come to town
and the second data frame has the characters
characters
george
donald
mary
minnie
I need to search the the show description one to find out which shows feature which characters...
the final output should look like
character | showscharacterisin
george | c,d
donald | b
mary | c.d
minnie | No show
these data sets are contrived and simple but it expresses the search functionality I am trying to implement. I basically need to search the text of 1 dataframe using the values from another dataframe.
This would be easy to do in a udf inside of sql server, I would basically loop through the show descrip each time and return the show no using a "contains" search on the description.
the problem I have is that I see no way to do this using a data frame.
1) I think you should further breakdown the first dataset so that show_no is mapped to each word in the description.
For e.g first row could be broken down like
show_no | descrip
a | this
a | is
a | mikey
2) You can filter out the stopwords from this if needed.
3) After this you can join it with "characters" to get the final desired output.
Hope this helps.
Amit