Solr & Elasticsearch -- Modeling Signals to Build Real Semantic Search
When it comes to Solr and Elasticsearch, there are many misconceptions. Learn why you have to establish relevance when using Elasticsearch and Solr.
Join the DZone community and get the full member experience.Join For Free
perhaps the biggest relevance mistake you can make is to take content, straight from its source, and plop it directly into elasticsearch or solr. trying to search fields that directly reflect attributes from your data's source indexed with default settings won’t give you great results.
why is this? unmodified relevance scores from field searches likely don’t correspond to meaningful business or domain ranking criteria. you need to get at criteria like "does a searched for actor star in this movie?", "is this restaurant nearby?", "is this product well reviewed?". yet data from apis, databases, and filesystems are often subdivided into attributes ill equiped to answer these questions with default search settings.
you almost always have to manipulate your data to answer these questions with a search engine. luckily, with open source search, you are in control! you can to craft relevance scores to reflect needed criteria numerically. you control what terms end up in fields to form the basis of a relevance score. you deeply manipulate lucene to control scoring and searching! when you understand this, you begin to express relevance in terms of quantifiable business criteria instead of surrendering to default scoring and field structure. you see your fields as built to be searched and scored to measure important relevance signals -- numbers that correspond meaningfully to valuable criteria such as “the likeliness the user is searching this type of restaurant”, “the proximity of the user to the restaurant”, “how well rated the restaurant is”, or “how much is the body text about the search terms” -- or whatever your users deem relevant.
what do i mean? why can’t a search engine just figure out how to rank results by this criteria automatically? let’s take text fields as an example. recall the default text relevance score in solr or elasticsearch is tf*idf. this means a strong bias towards fields that mention more of the search terms (tf or term frequency) multiplied by how rare those terms are in the corpus (idf or inverse document frequency). tf*idf has proven a reasonable, general-purpose measure of relevance for searching text.
users have their own expectations that have nothing to do with how your database or source system organizes data! failing to model signals they care about is the biggest failing of most search solutions.
however, the specifics of your use case may mean default tf*idf is way off the mark for measuring the criteria you need. we saw this when we dug into title search in a previous article. odd terms like “who” turned out to be strikingly rare in title fields. this greatly disrupted the results ranking, causing searches like “who is socrates” to return search results like “who is plato” ranked much higher than simple, on-topic, titles like “socrates”. the rareness (idf) of terms like “who” wasn’t helpful in creating a signal associated with “the article’s title describes topics in the user’s search terms”. therefore, we had to eliminate many of these strikingly rare terms. this and a number of other measures turned title search from a rather dumb search into a smarter experience closely resembling perusing shelves in a book store to find a good book on “socrates”.
in other words, we improved the quality of the information associated with the title field’s relevance score. we turned the relevance score into a signal that more precisely measures when “the article’s title describes topics in the user’s search terms” . this is criteria more meaningfully tied to what the user intends, and how our business wants to construct ranking rules.
the process of turning relevance scores into smarter, domain specific signals that quantifiably measure important criteria to you and your data is known as signal modeling . when signal modeling , we deeply manipulate fields to be scored more precisely to measure criteria. it’s what differentiates high quality ranking solutions from those that don’t really try that hard. this is a key idea in relevant search and fundamental to how osc approaches relevance problems.
when you think about all the ways you can manipulate fields in a search engine, you see how lucene-based solutions can really enable signal modeling to capture important signals. the strength of open source search solutions is how deeply you can manipulate how terms makeup a field and how they’re scored through features such as:
- analysis to control the composition of terms in an index. enabling domain-specific synonyms, stopwords, indexing of bigrams, or whatever tokens you can derive from your content!
- disabling/enabling scoring features such as fieldnorms (tied to field length), term frequency, idf, etc to control various aspects of text-based relevance
- copyfields to copy finer-grained fields into a larger field to generate a more general relevance signal, when users don’t care to differentiate between arbitrarily subdivided fields like an article’s “abstract” and “body”
- modifying the scoring or similarity through lucene plugins to directly control relevance scoring
- leveraging value fields such as user ratings, profitability, sales
- using geographical information
indeed, once you realize that fields are not storage and retrieval mechanisms, but rather they’re containers to enable scoring, you can begin to use them and the features above to build truly robust and precise relevance signals. you need not take fields from your source system at face value. instead, you can manipulate them and their scoring to the nth degree to perfect the measurement they deliver at search time. don’t fall into the trap of not mastering the tools at your disposal, instead understand that fields exist to be manipulated -- truly modelled -- to create a relevance signal that satisfies important ranking criteria to your users. as their precision increases, these signals have meaning -- and enable real “semantic” search that expresses ranking in terms both the user and business can associate with meaningful information.
this may seem abstract. the examples of signal modeling can be found throughout our blog as we reflect on how fields are composed and scored. it’s a skill that permeates our relevance philosophy -- to the point that we’re writing a book that features it highly.
if you’d like to get beyond your own basic search solution, to build something more robust. please contact us ! we’d love to help you with your search problems!
reminder! pick up the book associated with these ideas! buy relevant search -- enter code turnbullmu to get 38% off!
Opinions expressed by DZone contributors are their own.