Okay, this is the second version of the patch. It is much more simpler,
only add locale to search fields and perform searches with current locale
(or without if locale is not set)

Now when search is performed from:
http://localhost:8083/roller/test/ - search in all languages and return
links without locale
http://localhost:8083/roller/test/de - search in German language (de) and
return links with de locale (post from other languages will not be shown)

WDYT?

Maciej

PS.: Do You get attachments? I attached patch to this message and first one
in the Thread. If not I am pasting it below:

Index:
app/src/main/java/org/apache/roller/weblogger/business/search/FieldConstants.java
===================================================================
---
app/src/main/java/org/apache/roller/weblogger/business/search/FieldConstants.java
(wersja 1508340)
+++
app/src/main/java/org/apache/roller/weblogger/business/search/FieldConstants.java
(kopia robocza)
@@ -47,4 +47,5 @@
                                                  // the transform rules of
                                                  // the analyzer
     public static final String WEBSITE_HANDLE = "handle";
+    public static final String LOCALE = "locale";
 }
Index:
app/src/main/java/org/apache/roller/weblogger/business/search/operations/SearchOperation.java
===================================================================
---
app/src/main/java/org/apache/roller/weblogger/business/search/operations/SearchOperation.java
(wersja 1508340)
+++
app/src/main/java/org/apache/roller/weblogger/business/search/operations/SearchOperation.java
(kopia robocza)
@@ -54,7 +54,7 @@

     private static String[] SEARCH_FIELDS = new String[] {
             FieldConstants.CONTENT, FieldConstants.TITLE,
-            FieldConstants.C_CONTENT, FieldConstants.CATEGORY };
+            FieldConstants.C_CONTENT, FieldConstants.CATEGORY,
FieldConstants.LOCALE };

     // private static BooleanClause.Occur[] SEARCH_FLAGS = new
     // BooleanClause.Occur[] {
@@ -73,6 +73,7 @@
     private String term;
     private String websiteHandle;
     private String category;
+    private String locale;
     private String parseError;

     private int nMax = 500; // Limit documents.
@@ -144,6 +145,16 @@
                 query = bQuery;
             }

+            Term tLocale = IndexUtil.getTerm(FieldConstants.LOCALE,
+                    locale);
+
+            if (tLocale != null) {
+                BooleanQuery bQuery = new BooleanQuery();
+                bQuery.add(query, BooleanClause.Occur.MUST);
+                bQuery.add(new TermQuery(tLocale),
BooleanClause.Occur.MUST);
+                query = bQuery;
+            }
+
             searchresults = searcher.search(query, null/* Filter */, nMax,
                     SORTER);

@@ -227,4 +238,14 @@
         this.category = category;
     }

+    /**
+     * Sets the locale.
+     *
+     * @param locale
+     *            the new locale
+     */
+    public void setLocale(String locale) {
+        this.locale = locale;
+    }
+
 }
Index:
app/src/main/java/org/apache/roller/weblogger/business/search/operations/IndexOperation.java
===================================================================
---
app/src/main/java/org/apache/roller/weblogger/business/search/operations/IndexOperation.java
(wersja 1508340)
+++
app/src/main/java/org/apache/roller/weblogger/business/search/operations/IndexOperation.java
(kopia robocza)
@@ -125,6 +125,10 @@
         doc.add(new Field(FieldConstants.TITLE, data.getTitle(),
                 Field.Store.YES, Field.Index.ANALYZED));

+        // text
+        doc.add(new Field(FieldConstants.LOCALE, data.getLocale(),
+                Field.Store.YES, Field.Index.ANALYZED));
+
         // index the entry text, but don't store it - moved to end of block
         // unstored
         doc.add(new Field(FieldConstants.CONTENT, data.getText(),
Index:
app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/SearchResultsModel.java
===================================================================
---
app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/SearchResultsModel.java
(wersja 1508340)
+++
app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/SearchResultsModel.java
(kopia robocza)
@@ -121,6 +121,10 @@
             search.setCategory(searchRequest.getWeblogCategoryName());
         }

+        if (searchRequest.getLocale() != null) {
+            search.setLocale(searchRequest.getLocale());
+        }
+
         // execute search
         indexMgr.executeIndexOperationNow(search);



2013/7/30 Maciej Rumianowski <maciej.rumianow...@gmail.com>

>
>
>
> 2013/7/29 Glen Mazza <glen.ma...@gmail.com>
>
>> Oh, um, never mind on one point -- I was complaining below about having
>> URLs like 
>> http://www.jroller.com/gmazza/**en/entry/myblogentry<http://www.jroller.com/gmazza/en/entry/myblogentry>and
>> http://www.jroller.com/gmazza/**entry/myblogentry<http://www.jroller.com/gmazza/entry/myblogentry>splitting
>>  Google Analytics results, I just realized *I* can turn off the
>> multiple languages option myself, and then "/en/" version no longer is a
>> valid URL, so that problem is solved for me (I thought it was JRoller that
>> specified at an admin-level the multiple languages option, and so I was
>> stuck with duplicate URLs as a result.)
>>
> Yes there are  settings for i18n and the first one is responsible for
> locale to be added to path.
> Internationalization Settings  I publish my weblog in multiple languages
>  Show my weblog entries from all languages on my homepage
>
>>
>> I guess we can keep adding the /lang/ portion then, the idea is that you
>> can tell people to go to 
>> http://www.jroller.com/gmazza/**en/entry<http://www.jroller.com/gmazza/en/entry>to
>>  see English articles and
>> http://www.jroller.com/gmazza/**de/entry<http://www.jroller.com/gmazza/de/entry>to
>>  see German ones.
>
> And to see translated UI. I am considering making the patch simpler and
> strip out the part which enables choosing language. Searches will be always
> made based on current locale or lack of locale.
>
>  I personally would rather do separate blogs http://www.jroller.com/gmazzaand
>> http://www.jroller.com/gmazza_**de <http://www.jroller.com/gmazza_de> to
>> keep the URLs simpler.  What do you expect to be doing for your own blog?
>>
> I am thinking about this one also but first I saw the options in Weblog
> settings and tried to make it works. The design for a site/blog is not yet
> finished, but whatever solution I choose the site will be up and running in
> two weeks. So you can see it online.
>
>>
>>
>>> I think it's also a poor idea to blog in different languages within the
>>> same blog (instead of having two blogs in two different languages, as
>>> Roller fully supports individual users creating multiple blogs) because
>>> with a blog you're trying to create a warm friendly connection with your
>>> readers, but it's off-putting to your readers when you're blogging
>>> frequently in a language they can't understand.  WDYT?
>>>
>> That's why I want to separate languages on site and have translated UI.
>
> Maciej
>
>

Reply via email to