# Question about queries on SearchVectorField

**URL:** <https://forum.djangoproject.com/t/question-about-queries-on-searchvectorfield/43629>\
**Category:** Using the ORM\
**Created:** [December 4, 2025, 10:34pm UTC](https://forum.djangoproject.com/t/question-about-queries-on-searchvectorfield/43629 "2025-12-04T22:34:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dougharris](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dougharris/32/16538_2.png) [@dougharris](https://forum.djangoproject.com/u/dougharris)\
**Post date:** [December 4, 2025, 10:34pm UTC](https://forum.djangoproject.com/t/question-about-queries-on-searchvectorfield/43629/1 "2025-12-04T22:34:16Z")

</div>

I’m experimenting with a [SearchVectorField](https://docs.djangoproject.com/en/4.2/ref/contrib/postgres/search/#searchvectorfield) in order to speed up searching in the Django Admin for a very large table. I’ve added a SearchVectorField and a [GinIndex](https://docs.djangoproject.com/en/4.2/ref/contrib/postgres/indexes/#django.contrib.postgres.indexes.GinIndex) to the model, along with a trigger to automatically update the field when the relevant columns change.

My question is about the query generated when searching this table.

Using the Django Debug Toolbar, if I search for a string `foo` in the admin, I see this query:

```sql
SELECT COUNT(*) AS "__count"
  FROM "mymodel"
 WHERE "mymodel"."search_vector"::text LIKE '%foo%';

```

PostgreSQL [documentation for queries](https://www.postgresql.org/docs/15/textsearch-tables.html#TEXTSEARCH-TABLES-SEARCH) using `tsvector` column types look more like this:

```sql
SELECT count(*)
FROM mymodel
WHERE search_vector @@ to_tsquery('foo');

```

I also tried running these queries in `psql` and the difference between the two is staggering. The Django-generated takes about 2.1 seconds but the query using `@@` takes about 3 _milliseconds_.

Running `explain`, I see a similar difference in magnitude in the cost reported for each query.

I’m curious to know if anybody who has worked with PostgreSQL full text search, and particularly SearchVectorFields, has explored this and found better results.

Thanks

(Django 4.2 LTS, PostgreSQL 15.13, python 3.12.11, psycopg2 2.9.3)

---

<div class="post-metadata">

**Author:** ![sevdog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sevdog/32/20692_2.png) [@sevdog](https://forum.djangoproject.com/u/sevdog)\
**Post date:** [December 5, 2025, 8:50am UTC](https://forum.djangoproject.com/t/question-about-queries-on-searchvectorfield/43629/2 "2025-12-05T08:50:54Z")

</div>

Hi @dougharris, the problem you are facing is caused by django admin defaulf behaviour for search.

When you want the search to use `SearchVectorField` capabilities you sould put `'@search_vector'` instead of `'search_vector'` in yours `search_fields`. This tells to django admin site to use the `search` database lookup instead of the default `icontaints`. You may also set `'search_vector __search'` or `'search_vector__ exact'` to be sure what lookup is used.

See [The Django admin site | Django documentation | Django](https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields) for further details.

---

<div class="post-metadata">

**Author:** ![dougharris](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dougharris/32/16538_2.png) [@dougharris](https://forum.djangoproject.com/u/dougharris)\
**Post date:** [December 5, 2025, 3:37pm UTC](https://forum.djangoproject.com/t/question-about-queries-on-searchvectorfield/43629/3 "2025-12-05T15:37:28Z")

</div>

Aha! Thanks.

In my specific case, I had overriden `get_search_results()` for some number-entry special cases.

My (incorrect) usage had been:

```python
queryset = self.model.objects.filter(search_vector__contains=search_term)

```

Using `__search` didn’t work for my column. Properly reading the SearchVectorField documentation (again), I realize that simply using `=` is the way to go:

```python
queryset = self.model.objects.filter(search_vector=search_term)

```

and the debug toolbar confirms that the generated query uses the `@@` syntax.
