Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight issue when negative operator is used #1674

Open
SanthoshVeerabathiran opened this issue Apr 15, 2024 · 1 comment
Open

Highlight issue when negative operator is used #1674

SanthoshVeerabathiran opened this issue Apr 15, 2024 · 1 comment
Labels

Comments

@SanthoshVeerabathiran
Copy link

Description

I encountered an issue with negative queries in Typesense. Even when using a negative query term with a '-' prefix to exclude certain results, the exclusion does not seem to be functioning correctly. This issue is affecting the accuracy of search results in our application.

Steps to reproduce

Search Parameters:

{
  q: '8 -erteiouteriuiiruw',
  query_by: [ 'id_1', 'id_2' ],
  filter_by: 'id_4:=23456',
  limit: 2
}

Response:

{
  facet_counts: [],
  found: 51,
  hits: [
    {
      document: {
        id: '50',
        id_1: '82237e7b23c8d00c10',
        id_2: '822352dd4972780d06',
        id_3: '82237e7b98c8d01919',
        id_4: '23456',
        id_5: '8345937493845',
        id_6: '947693749839',
        id_7: '9834758374587',
        id_8: '822399482342',
        id_9: '893745876231'
      },
      highlight: {
        id_1: {
          matched_tokens: [ '82237e7b23c8d00c1' ],
          snippet: '<mark>82237e7b23c8d00c1</mark>0'
        },
        id_2: {
          matched_tokens: [ '822352dd4972780d0' ],
          snippet: '<mark>822352dd4972780d0</mark>6'
        }
      },
      highlights: [
        {
          field: 'id_1',
          matched_tokens: [ '82237e7b23c8d00c1' ],
          snippet: '<mark>82237e7b23c8d00c1</mark>0'
        },
        {
          field: 'id_2',
          matched_tokens: [ '822352dd4972780d0' ],
          snippet: '<mark>822352dd4972780d0</mark>6'
        }
      ],
      text_match: 578730089005449300,
      text_match_info: {
        best_field_score: '1108074561536',
        best_field_weight: 15,
        fields_matched: 1,
        num_tokens_dropped: 0,
        score: '578730089005449337',
        tokens_matched: 1,
        typo_prefix_score: 1
      }
    },
    {
      document: {
        id: '49',
        id_1: '82237e7b23c8d00c10',
        id_2: '822352dd4972780d06',
        id_3: '82237e7b98c8d01919',
        id_4: '23456',
        id_5: '8345937493845',
        id_6: '947693749839',
        id_7: '9834758374587',
        id_8: '822399482342',
        id_9: '893745876231'
      },
      highlight: {
        id_1: {
          matched_tokens: [ '82237e7b23c8d00c1' ],
          snippet: '<mark>82237e7b23c8d00c1</mark>0'
        },
        id_2: {
          matched_tokens: [ '822352dd4972780d0' ],
          snippet: '<mark>822352dd4972780d0</mark>6'
        }
      },
      highlights: [
        {
          field: 'id_1',
          matched_tokens: [ '82237e7b23c8d00c1' ],
          snippet: '<mark>82237e7b23c8d00c1</mark>0'
        },
        {
          field: 'id_2',
          matched_tokens: [ '822352dd4972780d0' ],
          snippet: '<mark>822352dd4972780d0</mark>6'
        }
      ],
      text_match: 578730089005449300,
      text_match_info: {
        best_field_score: '1108074561536',
        best_field_weight: 15,
        fields_matched: 1,
        num_tokens_dropped: 0,
        score: '578730089005449337',
        tokens_matched: 1,
        typo_prefix_score: 1
      }
    }
  ],
  out_of: 51,
  page: 1,
  request_params: {
    collection_name: 'sample',
    first_q: '8 -erteiouteriuiiruw',
    per_page: 2,
    q: '8 -erteiouteriuiiruw'
  },
  search_cutoff: false,
  search_time_ms: 0
}
  1. Send a search request to Typesense with a negative query term.
  2. Include a negative query term with a '-' prefix, such as '8 -erteiouteriuiiruw', in the search parameters.
  3. Execute the search request and observe the results.

Expected Behavior

The search results should exclude any documents containing the negative query term ('erteiouteriuiiruw').

Actual Behavior

There are matches to words that were not specified in the query, leading to incorrect results.

Metadata

Typesense Version: 26.0

@kishorenc kishorenc changed the title Negative query is not working correctly Highlight issue when negative operator is used Apr 17, 2024
@kishorenc
Copy link
Member

Instead of <mark>82237e7b23c8d00c1</mark>0 it should be highlighted as <mark>8</mark>2237e7b23c8d00c10.

@kishorenc kishorenc added the bug label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants