Queries are limited to 4000 characters.

zequion 446 Reputation points
2024-09-19T04:19:40.1633333+00:00

I am working on a semantic search engine and I need to be able to search for synonyms and inflections of the words in the phrase that the user enters.

I have encountered the problem that the parameter “contains_search_condition” of the Contains or ContainsTable command is limited to 4000 characters.

Just by searching for the synonyms and inflections of a word, this limit can be exceeded. It is not solved even if the words are entered into a Varchar(max) variable and passed to the parameter.

Several years ago I reported this problem and others that I have found in writing to Microsoft Spain, who reported it to Microsoft USA. They told me that "they were going to work on these problems."

I have not heard anything again and I need a solution, because I am stuck on this problem.

I can't write the text of the query because it says "violation of the code of conduct" and deletes the post.

SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 31,576 Reputation points
    2024-09-19T06:55:32.63+00:00

    Hi @zequion

    Have you tried split the search conditions into multiple smaller conditions that fit with the 4000-character limit?

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. zequion 446 Reputation points
    2024-09-20T04:21:22.9733333+00:00

    Can you contact someone who can fix this? I've already tried and they've been saying for years that "they'll fix it".


  3. Rodger Kong 365 Reputation points
    2024-09-22T05:52:40.1566667+00:00

    Our purpose is shrink the length of param, the only way is split it to multiple parts. The result of CONTAINSTABLE is a rowset like table, so it can JOIN with standard table. So it can runs UNION. That the reason we can resolve your requirement. We can split the condition to parts and execute them with CONTAINSTABLE mutiple times, at last stick each of results together by UNION.

    I split your code, cut line 2nd and 4th to 2 parts, because them looks longer. 

    I treated line 1st  3rd, 5th as one piece, because they are all connected by AND. It can be named A.

    Line 2nd was split to 2 parts, named B and C, so line 2nd = B | C.

    So did line 4th , named D and E, line 4th = D | E.

    Now, total condition string is simpfied to A & (B | C) & (D| E).

    Expanding the expression, it will be (A & B & D) | (A & B & E) | (A & C & D) | (A & C & E).

    UNION can be treated as OR, replace it in the expression, can get 

          (A & B & D)

          UNION

          (A & B & E) 

          UNION 

          (A & C & D) 

          UNION

          (A & C & E)

    Use this to process your condition, get the code as in the attachment, and it should be look like this

    SQL Split


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.