Solr / Lucene: Index Face Values

For example, let's say I have the following facet:

Colors

  • Red (7825)
  • Orange (2343)
  • Green (843)
  • Blue (5412)

In my database, the colors will be a table, and each color will have a primary key and a name / value.

When indexing with Solr / Lucene in all the examples I saw, the value is indexed, not the primary key. Therefore, if I filter by red, I would get something like the following:

http://www.example.com/search?color=Red

I am wondering if it is advisable to index the primary key instead and retrieve values ​​from the database when displaying face values? So I would instead get something like this:

http://www.example.com/search?color=1

"1" representing the primary key is red. I am wondering if I should use this approach, since the meanings of many of my aspects often change, but the primary keys remain unchanged. In addition, the index must be synchronized with the database.

Do you have more experience? Do you think this will affect performance?

Thanks in advance!

+4
source share
1 answer

If you expect your entities to change frequently, it’s easier to index identifiers, and when you get facet results, search the database to get the color names. Thus, changes in colors will not require updating indexed documents in the index.

In our system, we index the ID of Lucene instead of the name of the entities precisely for the reasons you specified. In addition, our entities have a bunch of related properties that are not indexed, so we have to hit the database to get them anyway.

In terms of performance, the face of the identifier will not be noticeably slower or faster. As for database searches, this should not be a big problem, especially if you are only dropping dozens of facets at a time. You can always use caching to speed it up if this becomes a problem.

+1
source

Source: https://habr.com/ru/post/1302095/


All Articles