-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Escape() returns 0 results, when the Native query does #329
Comments
@AaronSadlerUK An escaped field search builds a "phrase query" and as such doesn't need to go through the query parser, whilst a native query will use the query parser to turn your string into an actual query and execute it "raw". The phrase query ensures an exact match for each term and not parts of each term. What "type" is your "colour" field in the index, and what format are you expecting the value it to be? The likelihood here is your value isn't indexed quite as you'd expect. e.g. "light-blue" would actually be indexed as "light" and "blue" by default – searching for Use a tool like Luke to inspect your index and find out what's happening. |
Thanks for that @callumbwhyte I am trying to open the indexes with like but having a nightmare 😅 Once I manage to get in I'll see what's happening in terms of the Indexed value. But if I do it using .Escape() it does not, I should know more if I can get Luke to work |
The backoffice is a whole different beast again ;-) |
@callumbwhyte Any ideas with this error? I've tried rebuilding etc... |
Finally found a version which can read the indexes... 5.2.0 Can be found here for anyone looking: |
@AaronSadlerUK If you right click on the value you can view the tokens, you should see 2 tokens: "light" and "green". If you're trying to match Rather than indexing your field as You could also modify the value at index time in the |
I was thinking about removing the space, but then I would need to create a whole thing to remove all the other different characters which are used such as I'll try the RAW way. Am I right in thinking what I'm trying to do here would normally be done as a faceted search? |
this seems quite similar to #325, which has my current workaround but I'd love to get rid of that one. options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>
{
[FIELD_DEFINITION_KEYWORD] = new DelegateFieldValueTypeFactory(name =>
new GenericAnalyzerFieldValueType(
name,
_loggerFactory,
new KeywordAnalyzer(),
false
)
)
}; |
@dealloc I'm also seeing native phrase query gives results as opposed to an escaped term? (examine 3.1)
both result in but only the nativequery coded example has a result set? |
I did notice there are tests for this.. that pass...
|
Actually seems that trying to develop a failing test it seems that native query also manipulates.. so I think the issue with Escape() is that it doesn't lowercase?
|
Hi all, I know this topic is old but will add some clarity: As @callumbwhyte notes, it creates a PhraseQuery, but this is not susceptible to the same tokenizing and analysis done by the default specified because it operates outside of the query parser and it creates an exact match. Here's an example: var analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion);
using (var luceneDir = new RandomIdRAMDirectory())
using (var indexer = GetTestIndex(luceneDir, analyzer))
{
indexer.IndexItems(new[] {
ValueSet.FromObject(1.ToString(), "content",
new { phrase = "If You Can't Stand the Heat, Get Out of the Kitchen" }),
ValueSet.FromObject(2.ToString(), "content",
new { phrase = "When the Rubber Hits the Road" }),
ValueSet.FromObject(3.ToString(), "content",
new { phrase = "A Fool and His Money Are Soon Parted" }),
ValueSet.FromObject(4.ToString(), "content",
new { spaphraseth = "A Hundred and Ten Percent" }),
});
var searcher = (BaseLuceneSearcher)indexer.Searcher;
var query = searcher
.CreateQuery(IndexTypes.Content)
.NativeQuery("+phrase:\"Get Out of the Kitchen\"");
Console.WriteLine(query);
var results = query.Execute();
Assert.AreEqual(1, results.TotalItemCount);
query = searcher
.CreateQuery(IndexTypes.Content)
.Field("phrase", "Get Out of the Kitchen".Escape());
Console.WriteLine(query);
results = query.Execute();
Assert.AreEqual(1, results.TotalItemCount);
} What does this yield?
Why?
I understand the confusion around 'Escape()' but it does essentially mean 'exact match', not phrase. So if you are using Escape() than you would need to declare your field type as 'Raw' which equates to using the KeywordAnalyzer under the hood. So where do we go from here?
|
My vote goes to having a Perhaps the terminology of |
My immediate thought was exactly the same as Callum, so that gets my vote. Makes things clearer and doesn’t break existing code, but prompts to move to the newer options. |
@callumbwhyte + @mattbrailsford Thanks! Escape was originally, a very long time ago, meant to ensure that reserved chars were escaped and didn't cause lucene issues, but then this evolved in various ways over the years because it turns out we didn't need to do that with phrase queries. I'm really not sure what the use case would be moving forward to introduce an 'Exact' method that would be the same as the current 'Escape' - because the value would need to match exactly to what the value is stored in the index based on what the field's analyzer is. I don't want to re-introduce more confusion and have to re-explain this all over again because we'll be back in the same boat. I'm leaning towards creating "Phrase" and then just obsoleting "Escape"? |
When using the Escape() query is brings back no results, but if I extract he RAW query and run it, then it returns the expected number of results
This brings back 0 results:
But if I extract the RAW query and run it... It works:
The text was updated successfully, but these errors were encountered: