-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: treating untagged words or phrases as "full text search" across multiple (or all) fields #39
Comments
Hi @seandavi You're right this is not a supported scenario, but it is an interesting one. Two solutions:
If you help in some way, just ask ! |
For the time being, I'm going the cheap route and specifying If I have a little time, I may play with the As usual, thanks for taking the time to answer and clarify. |
I know it has been a while on this one. I noticed a per-field version of |
Just leaving a note here that to do this right would involve bare |
After a little playing with class BareTextTransformer(luqum.utils.LuceneTreeTransformer):
"""Convert bare Words or Phrases to full text search
In cases where a query string has bare text (no field
association), we want to construct a DSL query that includes
all fields in an OR configuration to perform the full
text search against all fields.
This class can walk the tree and convert bare Word
nodes into the required set of SearchField objects. Note
that this is entirely equivalent to `multi_match` in terms
of performance, etc.
"""
def __init__(self, fields=['title','abstract']):
"""Create a new BareTextTransformer
Parameters
----------
fields: list of str
This is the list of fields that will used to
create the composite SearchField objects that
will be OR'ed together to simulate full text
search.
Returns
-------
None. The tree is modified in place.
"""
super()
self.fields = fields
def visit_word(self, node, parent):
if(len(parent)>0 and (
isinstance(parent[-1], luqum.tree.SearchField) or
isinstance(parent[-1], luqum.tree.Range))):
return node
else:
search_list = [SearchField(f, node) for f in self.fields]
return Group(OrOperation(*search_list))
def visit_phrase(self, node, parent):
if(len(parent)>0 and (
isinstance(parent[-1], luqum.tree.SearchField) or
isinstance(parent[-1], luqum.tree.Range))):
return node
else:
search_list = [SearchField(f, node) for f in self.fields]
return Group(OrOperation(*search_list)) And, to use: tree = parser.parse(q)
transformer = BareTextTransformer()
# tree below now has expanded Group(OrOperations....) for each
# field in the BareTextTransformer `fields`
tree = transformer.visit(tree) |
Using a es_query_builder = ElasticsearchQueryBuilder(
**schema_analyzer.query_builder_options(),
field_options={"*": {"match_type": "multi_match"}},
) |
Luqum is working great for me and my test users, but one thing that the test users miss is the behavior of query_string to do a full-text search across all fields when no field is specified (eg., "
London
") . I see the ability to specify a default fields, but this results in a simplematch
query. I guess I am looking to convert these tomulti-match
with all available text fields? Any suggestions?The text was updated successfully, but these errors were encountered: