I work with a search engine called Lucene.net that is nothing more than a search engine.
I need to insert the following phrases within the indexer separated by ;
:
"bedside lamp"; "lampshade"; "table lamp"
It is necessary to have the double quotes ( "
) because it understands that it is a phrase, so it will only recover something if the sentence is written in full, as it says in this manual :
A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.
A single term is a single word such as "test" or "hello".
A Phrase is a group of words surrounded by double quotes such as "hello dolly".
But when I use PadLeft it returns a string like this :
\"bedside lamp\";\"lampshade\";\"table lamp\"
Follow the example:
PhraseIndex translation = new PhraseIndex()//Objeto que eu vou armazenar no buscador
{
PT_BR = "abajur;luminária",
EN_US = "bedside lamp;lampshade;table lamp",
ES = "pantalla;lámpara;claraboya"
};
translation.InsertOnLucene();//Método que armazena(o modo como armazena nao afeta a pergunta, então é desnecessário)
List<String> phrases = translation.EN_US.Split(';').ToList(); //Separo todas as frases da variável EN_US dentro de uma lista
foreach(string p in translation.EN_US)
{
translation.EN_US = translation.EN_US +p.PadLeft(p.Length+1,'"').PadRight(p.Length+1,'"') + ";"; //Aqui eu insiro uma aspas dupla no inicio e no fim de cada frase e insiro novamente dentro de EN_US separadas por ;
}
Console.WriteLine(translation.EN_US); //\"bedside lamp\";\"lampshade\";\"table lamp\" o c# insere automaticamente o " para \" sendo assim quando eu passar essa string no Lucene, ele não irá encontrar nada que tenha \"
The problem is that Lucene understands \"
to be \"
and not "
so much so that in the same document mentioned above, in the Escaping Special Characters session it says that it should use \
to create these exceptions.
The question is: I can send a string to the search engine
"bedside lamp";"lampshade";"table lamp"
instead of
\"bedside lamp\";\"lampshade\";\"table lamp\"
If I search for lamp
it returns me bedside lamp
because it is not looking for phrases but terms.