开发者

Force Lucene (in OpenCms) to show results in a specific Locale

I've a website mounted with OpenCms and it use "Lucene" as Search Engine. My website is available in two languages: Spanish (supported) and Gallegan (not supported). I've achieved my search proccess works well but results is always show in Spanish. Is it posible force Lucene to show results in a spec开发者_StackOverflow中文版ific locale?


When i build the search index (in the backoffice) i have an option called "Locale" where i can specify the locale of the index. I did it and created two separate index; one with locale "es" called "index-es" and other with locale "gl" called "index-gl".

I pass different index name with the function "setIndex" whether my user is using one language or other one but don't works. Always show contents in ES locale.

Do you refer to this or I didn't understand you?


When you build the search index, you could create a new Field called Language.
Use that Field to filter your search results.

EDIT

Document doc = new Document();
doc.Add(new Field("Language", "GL", Field.Store.NO,
            Field.Index.NOT_ANALYZED_NO_NORMS));
...

indexWriter.AddDocument(document);

Get top 10 documents in GL:

Directory dir = FSDirectory.open(new File("..."));
IndexSearcher searcher = new IndexSearcher(dir);
Query q = new TermQuery(new Term("Language", "GL"));
TopDocs hits = searcher.search(q, 10);
searcher.close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜