I'm sending the following params to Typesense `/do...
# community-help
e
I'm sending the following params to Typesense `/documents/search`:
Copy code
%{
  "enable_highlight_v1" => "false",
  "facet_by" => "available_majors.area_of_study,available_majors.major_name,available_sports.sport_name",
  "facet_return_parent" => nil,
  "filter_by" => "is_main_campus:true && is_operating:true",
  "max_facet_values" => 1500,
  "page" => 1,
  "per_page" => 30,
  "q" => "Alabama Agricultural and Mechanical University",
  "query_by" => "name,alias",
  "sort_by" => "undergraduate_total_count:desc"
}
I have a document with
"name": "Alabama Agricultural and Mechanical University"
but the resulting set does not include it. It includes six documents with various partial matches:
Copy code
highlight: %{
  name: %{
    snippet: "<mark>University</mark> of South <mark>Alabama</mark>",
    matched_tokens: ["University", "Alabama"]
  }
}
...
highlight: %{
  name: %{
    snippet: "<mark>University</mark> of North <mark>Alabama</mark>",
    matched_tokens: ["University", "Alabama"]
  }
}
...
highlight: %{
  alias: %{
    snippet: "Northeast, NACC, Northeast <mark>Alabama</mark> State Junior College, Northeast <mark>Alabama</mark> State Community College",
    matched_tokens: ["Alabama", "Alabama"]
  },
  name: %{
    snippet: "Northeast <mark>Alabama</mark> Community College",
    matched_tokens: ["Alabama"]
  }
}
Can someone explain what's going on here? I'd expect the search engine to prioritize exact matches, followed by partial matches. Do I need to configure the parameters differently?
j
"sort_by" => "undergraduate_total_count:desc"
Essentially overrides the default sorting by text relevance, and uses this field to do a hard sort
You want to instead use something like this:
"sort_by" => "_text_match(buckets: 10):desc,undergraduate_total_count:desc"
Here's more context: https://typesense.org/docs/guide/ranking-and-relevance.html#ranking-based-on-relevance-and-popularity
e
@Jason Bosco I changed the
sort_by
but the result is the same:
Copy code
%{
  "enable_highlight_v1" => "false",
  "facet_by" => "available_majors.area_of_study,available_majors.major_name,available_sports.sport_name",
  "facet_return_parent" => nil,
  "filter_by" => "is_main_campus:true && is_operating:true",
  "max_facet_values" => 1500,
  "page" => 1,
  "per_page" => 30,
  "q" => "Alabama Agricultural and Mechanical University",
  "query_by" => "name,alias",
  "sort_by" => "_text_match(buckets: 10):desc,undergraduate_total_count:desc"
}
j
Could you share the full JSON document for the record with
"name": "Alabama Agricultural and Mechanical University"
?
e
Untitled
j
That record doesn't have a field called
is_main_campus
or
is_operating
which you've used in the
filter_by
expression. So it doesn't match the filter criteria provided and is not being returned because of that
Then when no results are found for the provided keywords and filter, Typesense starts dropping words in the
q
parameter one by one, which is why you're seeing results with partial matches, since they probably at least match the filter_by provided
e
Ah crap, nice catch. It turns out we had a bug earlier in the pipeline that resulted in these fields not getting added to some documents. Thanks!
👍 1