mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-01 09:53:56 +02:00
improve result highlighting #480
This commit is contained in:
@@ -12,7 +12,7 @@ const Charset = _Charset || (await import("../src/charset.js")).default;
|
||||
|
||||
if(!build_light) describe("Result Highlighting", function(){
|
||||
|
||||
it("Should have been indexed properly (tag)", function(){
|
||||
it("Should have been indexed properly", function(){
|
||||
|
||||
// some test data
|
||||
const data = [{
|
||||
@@ -61,4 +61,71 @@ if(!build_light) describe("Result Highlighting", function(){
|
||||
highlight: 'Le <b>clown</b> et ses chiens'
|
||||
}]);
|
||||
});
|
||||
|
||||
it("Should have been indexed properly (#480)", function(){
|
||||
|
||||
const index = new Document({
|
||||
document: {
|
||||
store: true,
|
||||
index: [{
|
||||
field: "title",
|
||||
tokenize: "forward",
|
||||
encoder: Charset.LatinDefault
|
||||
},{
|
||||
field: "text",
|
||||
tokenize: "forward",
|
||||
encoder: Charset.LatinDefault
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
let all_docs = [{
|
||||
id: "469",
|
||||
title: "Polygon",
|
||||
text: "A polygon is a two dimensional figure"
|
||||
},{
|
||||
id: "888",
|
||||
title: "Spain",
|
||||
text: "Spain is a country."
|
||||
},{
|
||||
id: "473",
|
||||
text: "Madrid (pronounced: “mah-drid or /məˈdrɪd/) is the capital and largest city of Spain. Madrid is in the middle of Spain, in the Community of Madrid. The Community is a large area that includes the city as well as small towns and villages outside the city. 7 million people live in the Community. More than 3 million live in the city itself. It is the largest city of Spain and, at 655 m (2,100 ft) above sea level, the second highest capital in Europe (after the Andorran capital Andorra la Vella). It is the second largest city in the European Union. As it is the capital city, Madrid is where the monarch lives and also where the government meets. Madrid is the financial centre of Spain. Many large businesses have their main offices there. It has four important footballs teams, Real Madrid, Atlético Madrid, Getafe, and Rayo Vallecano. People who live in Madrid are called madrileños. Madrid was ruled by the Romans from the 2nd century. After AD 711 it was occupied by the Moors. In 1083 Spain was ruled again by Spaniards. Catholic kings ruled the country. By the mid-16th century it had become the capital of a very large empire. Spain was ruled by monarchs from the House of Habsburg, then the House of Bourbon. After the Spanish Civil War it was ruled by a dictator until the mid-1970s when it became a democracy. Although it is a modern city, a lot of its history can be seen and felt as one walks along the streets and in the large squares of the city. There are beautiful parks, famous buildings, art galleries and concert halls. == History == During the history of Spain many different people have lived there. Madrid's name comes from the Arabic word magerit, meaning “place of many streams\\\". The Phoenicians came in 1100 BC, followed by Carthaginians, Romans, Vandals, Visigoths and Moors. It was not until 1492, when the Catholic Monarchs got power, that Spain became a united country. establishments in Europe Category:Establishments in Spain",
|
||||
title: "Madrid"
|
||||
}];
|
||||
|
||||
for(let i = 0; i < all_docs.length; i++){
|
||||
index.add(all_docs[i]);
|
||||
}
|
||||
|
||||
let result = index.search({
|
||||
query: "spain",
|
||||
suggest: true,
|
||||
enrich: true,
|
||||
highlight: "<b>$1</b>"
|
||||
});
|
||||
|
||||
|
||||
expect(result.length).to.equal(2);
|
||||
expect(result[0]).to.eql({
|
||||
field: "title",
|
||||
result: [{
|
||||
id: all_docs[1].id,
|
||||
doc: all_docs[1],
|
||||
highlight: '<b>Spain</b>'
|
||||
}]
|
||||
});
|
||||
|
||||
expect(result[1]).to.eql({
|
||||
field: "text",
|
||||
result: [{
|
||||
id: all_docs[1].id,
|
||||
doc: all_docs[1],
|
||||
highlight: all_docs[1].text.replace(/(spain)/gi, "<b>$1</b>")
|
||||
},{
|
||||
id: all_docs[2].id,
|
||||
doc: all_docs[2],
|
||||
highlight: all_docs[2].text.replace(/(spain)/gi, "<b>$1</b>")
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user