manticoresoftware / manticoresoftware/manticoresearch

Search fails when two NEAR operators are used, and second proximity is less than the first

Open
#892 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
12k
Forks
642
Avg merge
3d 12h
Merged PRs (30d)
47

Description

**Describe the bug**
Consider the sentence: word2 something something word1 something word2 something word3
A search such as word1 NEAR/2 word2 NEAR/2 word3 will result in a match with the sentence
Similarly, word1 NEAR/3 word2 NEAR/3 word3 will also result in a match
word1 NEAR/3 word2 NEAR/2 word3 should also match this sentence but it does not.

A sentence without the first word2, such as: something something word1 something word2 something word3
will work for all the above proximity searches.

Search fails when two conditions are met:
1. Wherever there are two (and possibly more) NEAR operators, if the proximity distance of the second operator is less than the distance of the first
2. There are two instances of one of the words (word2) that satisfies the first proximity rule, but only one instance of the other word (word3).

**MRE**
Below python code creates the sentence and runs the 3 searches mentioned above. First search fails where as the rest work.
```
row = {'title': '

word2 something something word1 something word2 something word3

', 'contentid': '1'}
resp = indexApi.insert({"index" : "products", "doc" : row})
print(resp)

resp = utilsApi.sql(f"""SELECT * FROM products WHERE MATCH('word1 NEAR/3 word2 NEAR/2 word3')""")
print(resp)

resp = utilsApi.sql(f"""SELECT * FROM products WHERE MATCH('word1 NEAR/2 word2 NEAR/2 word3')""")
print(resp)

resp = utilsApi.sql(f"""SELECT * FROM products WHERE MATCH('word1 NEAR/2 word2 NEAR/3 word3')""")
print(resp)
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Python MRE against the SQL MATCH queries, especially word1 NEAR/3 word2 NEAR/2 word3. Trace the NEAR evaluation in the C++ search implementation and add regression coverage for repeated terms with decreasing proximity; done means the failing query matches the demonstrated sentence without breaking the other proximity cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python, sql
Domain
databases, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.