A search for “top kimchi near charlotte” asks for more than documents containing those words. Semantic parsing identifies known entities and interprets connecting words so the search engine can use popularity and location, rather than treating every term as a keyword. section 7.4.1 section 7.5
A domain-specific parser can turn the query into a structure the search pipeline can use:
- Build a lookup collection of known phrases, alternative spellings, entities, and semantic functions. An FST-backed Solr text tagger supports fast extraction from a large vocabulary. section 7.4.1
- Tag matching spans, then map each surface form to a canonical entity or function. Keep unmatched text as keywords; when a span has multiple candidates, the example parser selects the one with the highest popularity value. section 7.4.1
- Use the parsed entities to enrich and transform the query for the target search engine, while retaining a fallback for unknown keywords. section 7.5
From words to a typed query
For “top kimchi near charlotte,” extraction tags “top,” “near,” and “charlotte”; “kimchi” remains a keyword. The resulting tree assigns “top” a popularity function, “near” a location-distance function, and “Charlotte” a city entity with coordinates. This gives later query stages typed inputs instead of four undifferentiated strings. section 7.4.1
Listing 7.8 Generating a typed query tree from a user query
def generate_query_tree(extracted_entities):
query = extracted_entities["query"]
entities = {entity["id"]: entity for entity #1
in extracted_entities["entities"]} #1
query_tree = []
last_end = 0
for tag in extracted_entities["tags"]:
best_entity = entities[tag["ids"][0]] #2
for entity_id in tag["ids"]: #2
if (entities[entity_id]["popularity"] > #2
best_entity["popularity"]): #2
best_entity = entities[entity_id] #2
next_text = query[last_end:tag["startOffset"]].strip()
if next_text:
query_tree.append({"type": "keyword", #3
"surface_form": next_text, #3
"canonical_form": next_text}) #3
query_tree.append(best_entity) #4
last_end = tag["endOffset"]
if last_end < len(query): #5
final_text = query[last_end:len(query)].strip() #5
if final_text: #5
query_tree.append({"type": "keyword", #5
"surface_form": final_text, #5
"canonical_form": final_text}) #5
return query_tree
parsed_query = generate_query_tree(query_entities)
display(parsed_query)
The Python listing shows how tagged spans and intervening keywords become a typed query tree, including popularity-based selection among candidate entities. section 7.4.1
Explicit parsing offers control over domain vocabulary and words such as “top” and “near,” but it depends on what the entity collection knows. Unlisted phrases are harder to interpret, and a popularity-based choice between meanings is only a selection rule—not proof that the user intended that meaning. section 7.4.1 section 7.5
