Hey, this is an English text. I want you to translate it into the Tunisian dialect.…
- User
Hey, this is an English text. I want you to translate it into the Tunisian dialect. Please follow these steps:
- Translate step by step and highlight differences between Tunisian dialect and Modern Standard Arabic.
- Highlight sections you are confident translating into the Tunisian dialect. Translate this text into the Tunisian dialect, focusing on capturing the essence of the language nuances:
Q: Matching all columns with all search phrases I want to let a user search through all the columns in a table for a set of phrases defined in a textbox (split terms with whitespace). So what first came to mind is finding a way in SQL to concatenate all the columns and just use the LIKE operator (for each phrase) in this result. The other solution I thought of is writing an algorithm which takes all the phrases searched, and match them with all the columns. So I ended up with the following: String [] columns = {"col1", "col2", "col3", "col4"}; String [] phrases = textBox.Text.Split(' '); I then took all the possible combinations of columns and phrases, and put that into a where-clause-format for sql and then the result was "(col1 LIKE '%prase1%' AND col1 LIKE '%phrase2%') OR (col1 LIKE '%phrase1%' AND col2 LIKE '%phrase2%') OR (col1 LIKE '%phrase2%' AND col2 LIKE '%phrase1%') OR (col2 LIKE '%phrase1%' AND col3 LIKE '%phrase2%')" The above is just an example snippet of the output, the amount of conditions being created in this algorith is measured by conditions=columns^(phrases+1) So I observed that having 2 search phrases can still give good performance, but more than that will certainly decrease performance drastically. What is the best practise when searching all the columns for the same data? A: Edwin, I didn't know you was using ORACLE. My solution is using SQL Server. Hopefully you will get the gist of the solution and translate into PL/SQL. Hopefully this is useful to you. I am manually populating the #search temp table. You will need to somehow do that. Or look for some Split Function that will take the delimited string and return a Table. IF OBJECT_ID('tempdb..#keywords') IS NOT NULL DROP TABLE #keywords; IF OBJECT_ID('tempdb..#search') IS NOT NULL DROP TABLE #search; DECLARE @search_count INT -- Populate # search with all my search strings SELECT * INTO #search FROM ( SELECT '%ST%' AS Search UNION ALL SELECT '%CL%' ) T1 SELECT @search_count = COUNT(*) FROM #search; PRINT @search_count -- Populate my #keywords table with all column values from my table with table id and values -- I just did a select id, value union with all fields SELECT * INTO #keywords FROM ( SELECT client_id AS id ,First_name AS keyword FROM [CLIENT] UNION SELECT client_id ,last_name FROM [CLIENT] ) AS T1 -- see what is in there SELECT * FROM #search SELECT * FROM #keywords -- I am doing a count(distinct #search.Search). This will get me a count, --so if I put in 3 search values my count should equal 3 and that tells me all search strings have been found SELECT #keywords.id ,COUNT(DISTINCT #search.Search) FROM #keywords INNER JOIN #search ON #keywords.keyword LIKE #search.Search GROUP BY #keywords.id HAVING COUNT(DISTINCT #search.Search) = @search_count SELECT * FROM [CLIENT] WHERE [CLIENT].client_id IN ( SELECT #keywords.id FROM #keywords INNER JOIN #search ON #keywords.keyword LIKE #search.Search GROUP BY #keywords.id HAVING COUNT(DISTINCT #search.Search) = @search_count )
- Assistant