0
votes

I am searching for items that match a phrase exactly. After research I thought the best way to do this would be setting the field to NOT_ANALYSED and performing a TermQuery.

This works fine but when a term has a special character, such as "/" there are no results. I can see using Luke that the field contains the character. I construct my query like this.

BooleanQuery filterQuery = new BooleanQuery();
filterQuery.Add(new TermQuery(new Lucene.Net.Index.Term(customFieldFilter.Name, val)), Occur.MUST);
booleanQuery.Add(filterQuery, Occur.MUST);

The final query looks like this:

{+Type:Person +(+Expertise:Customer Care/Account Management)}

The API mentioned that "/" is a special character, so i tried to escape it

val = val.Replace("/", "\\/"); 
{+Type:Person +(+Expertise:Customer Care\/Account Management)}

But there are still no results. Searches without special characters are fine, What do i need to change?

2

2 Answers

0
votes

Not sure about C#, but in Java Lucene, forward slash (/) is not a special character. The backward slash (\), however, is.

What you have done with your code is you have used the escaping slash to escape a symbol which does not need escaping. This should have resulted no difference against the initial code, hence the result you're getting.

To answer your question fully, it would help if you could show exactly how are you indexing text. A short, self-contained example showing this problem would be ideal.

0
votes

I always want an exact match for this typer of search, so made a phraseQuery

PhraseQuery query = new PhraseQuery();
query.Add(new Term(customFieldFilter.Name, val));
booleanQuery.Add(query, Occur.MUST);