If I enter the query "apple" i wish to get the results like "xyzapplexyz","apple","applexyz" and NOT like "app" or "appl" . But what I am getting is "applexyz", "app" etc.
I have used EdgeNgram field and I have tried querying using the following :-
1-->> SearchQuerySet().all().autocomplete(authors=query)
2-->> SearchQuerySet().all().filter(authors=query)
3-->> SearchQuerySet().all().filter(content=query)
4-->> SearchQuerySet().all().autocomplete(content=query)
But none of them gives the required results. How can I resolve this issue?
If you want results like "xyzapplexyz"
, then you would need to use ngram analyzer instead of EdgeNGram
or you could use both depending on your requirements. EdgeNGram
generates tokens only from the beginning.
with NGram
apple will be one of the generated tokens for term xyzapplexyz assuming max_gram >=5
and you will get expected results, also search_analyzer
needs to be different or you will get weird results.
Also index size
might get pretty big with ngram
if you have huge chunk of text