diff --git a/src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java b/src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java index ffdd57665..b7166df35 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java @@ -81,6 +81,7 @@ public class AdminBackupAction extends FessAdminAction { if (logger.isDebugEnabled()) { logger.debug("Bulk Response:\n" + response.getContentAsString()); } + systemHelper.reloadConfiguration(); } catch (final Exception e) { logger.warn("Failed to process bulk file: " + form.bulkFile.getFileName(), e); } diff --git a/src/main/java/org/codelibs/fess/app/web/login/LoginAction.java b/src/main/java/org/codelibs/fess/app/web/login/LoginAction.java index 801061a15..a1bf17317 100644 --- a/src/main/java/org/codelibs/fess/app/web/login/LoginAction.java +++ b/src/main/java/org/codelibs/fess/app/web/login/LoginAction.java @@ -30,17 +30,23 @@ public class LoginAction extends FessLoginAction { @Execute public HtmlResponse index() { + return asIndexPage(null).useForm(LoginForm.class); + } + + private HtmlResponse asIndexPage(final LoginForm form) { + if (form != null) { + form.clearSecurityInfo(); + } return asHtml(path_Login_IndexJsp).renderWith(data -> { RenderDataUtil.register(data, "notification", fessConfig.getNotificationLogin()); - }).useForm(LoginForm.class); + saveToken(); + }); } @Execute public HtmlResponse login(final LoginForm form) { - validate(form, messages -> {}, () -> { - form.clearSecurityInfo(); - return asHtml(path_Login_IndexJsp); - }); + validate(form, messages -> {}, () -> asIndexPage(form)); + verifyToken(() -> asIndexPage(form)); final String username = form.username; final String password = form.password; form.clearSecurityInfo(); @@ -50,9 +56,7 @@ public class LoginAction extends FessLoginAction { return getHtmlResponse(); }); } catch (final LoginFailureException lfe) { - throwValidationError(messages -> messages.addErrorsLoginError(GLOBAL), () -> { - return asHtml(path_Login_IndexJsp); - }); + throwValidationError(messages -> messages.addErrorsLoginError(GLOBAL), () -> asIndexPage(form)); } return redirect(getClass()); } diff --git a/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java b/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java index a466b38fd..ab34989ee 100644 --- a/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java +++ b/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java @@ -347,8 +347,20 @@ public class FessXpathTransformer extends XpathTransformer implements FessTransf protected String getCanonicalUrl(final ResponseData responseData, final Document document) { final String canonicalUrl = getSingleNodeValue(document, fessConfig.getCrawlerDocumentHtmlCannonicalXpath(), false); - if (StringUtil.isNotBlank(canonicalUrl)) { - return canonicalUrl; + if (StringUtil.isBlank(canonicalUrl)) { + return null; + } + if (canonicalUrl.startsWith("/")) { + return normalizeCanonicalUrl(responseData.getUrl(), canonicalUrl); + } + return canonicalUrl; + } + + protected String normalizeCanonicalUrl(final String baseUrl, final String canonicalUrl) { + try { + return new URL(new URL(baseUrl), canonicalUrl).toString(); + } catch (MalformedURLException e) { + logger.warn("Invalid canonical url: " + baseUrl + " : " + canonicalUrl, e); } return null; } diff --git a/src/main/java/org/codelibs/fess/helper/LabelTypeHelper.java b/src/main/java/org/codelibs/fess/helper/LabelTypeHelper.java index 59a72a2f1..6370f1c2f 100644 --- a/src/main/java/org/codelibs/fess/helper/LabelTypeHelper.java +++ b/src/main/java/org/codelibs/fess/helper/LabelTypeHelper.java @@ -48,13 +48,9 @@ public class LabelTypeHelper { protected volatile List labelTypePatternList; - protected LabelTypeService getLabelTypeService() { - return ComponentUtil.getComponent(LabelTypeService.class); - } - @PostConstruct public void init() { - final List labelTypeList = getLabelTypeService().getLabelTypeList(); + final List labelTypeList = ComponentUtil.getComponent(LabelTypeService.class).getLabelTypeList(); buildLabelTypeItems(labelTypeList); } @@ -112,7 +108,7 @@ public class LabelTypeHelper { if (labelTypePatternList == null) { synchronized (this) { if (labelTypePatternList == null) { - final List labelTypeList = getLabelTypeService().getLabelTypeList(); + final List labelTypeList = ComponentUtil.getComponent(LabelTypeService.class).getLabelTypeList(); final List list = new ArrayList<>(); for (final LabelType labelType : labelTypeList) { final String includedPaths = labelType.getIncludedPaths(); diff --git a/src/main/java/org/codelibs/fess/helper/SystemHelper.java b/src/main/java/org/codelibs/fess/helper/SystemHelper.java index 1b9ad3c07..6939cf972 100644 --- a/src/main/java/org/codelibs/fess/helper/SystemHelper.java +++ b/src/main/java/org/codelibs/fess/helper/SystemHelper.java @@ -290,4 +290,12 @@ public class SystemHelper { return type + name; } + public void reloadConfiguration() { + ComponentUtil.getLabelTypeHelper().init(); + ComponentUtil.getPathMappingHelper().init(); + ComponentUtil.getSuggestHelper().init(); + ComponentUtil.getPopularWordHelper().init(); + // TODO restart jobs + } + } diff --git a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java index 1918e201e..ebf89e387 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java @@ -761,6 +761,72 @@ public class FessLabels extends UserMessages { /** The key of the message: TAR Archive */ public static final String LABELS_facet_filetype_tar = "{labels.facet_filetype_tar}"; + /** The key of the message: RAR Archive */ + public static final String LABELS_facet_filetype_rar = "{labels.facet_filetype_rar}"; + + /** The key of the message: 3gp Video */ + public static final String LABELS_facet_filetype_3gp = "{labels.facet_filetype_3gp}"; + + /** The key of the message: 3g2 Video */ + public static final String LABELS_facet_filetype_3g2 = "{labels.facet_filetype_3g2}"; + + /** The key of the message: AVI Video */ + public static final String LABELS_facet_filetype_avi = "{labels.facet_filetype_avi}"; + + /** The key of the message: FLV Video */ + public static final String LABELS_facet_filetype_flv = "{labels.facet_filetype_flv}"; + + /** The key of the message: MPEG Video */ + public static final String LABELS_facet_filetype_mpeg = "{labels.facet_filetype_mpeg}"; + + /** The key of the message: MP4 Video */ + public static final String LABELS_facet_filetype_mp4 = "{labels.facet_filetype_mp4}"; + + /** The key of the message: OGV Video */ + public static final String LABELS_facet_filetype_ogv = "{labels.facet_filetype_ogv}"; + + /** The key of the message: QuickTime Video */ + public static final String LABELS_facet_filetype_qt = "{labels.facet_filetype_qt}"; + + /** The key of the message: M4V Video */ + public static final String LABELS_facet_filetype_m4v = "{labels.facet_filetype_m4v}"; + + /** The key of the message: WAV Audio */ + public static final String LABELS_facet_filetype_wav = "{labels.facet_filetype_wav}"; + + /** The key of the message: AIF Audio */ + public static final String LABELS_facet_filetype_aif = "{labels.facet_filetype_aif}"; + + /** The key of the message: MIDI Audio */ + public static final String LABELS_facet_filetype_mid = "{labels.facet_filetype_mid}"; + + /** The key of the message: MPGA Audio */ + public static final String LABELS_facet_filetype_mpga = "{labels.facet_filetype_mpga}"; + + /** The key of the message: MP4A Audio */ + public static final String LABELS_facet_filetype_mp4a = "{labels.facet_filetype_mp4a}"; + + /** The key of the message: OGA Audio */ + public static final String LABELS_facet_filetype_oga = "{labels.facet_filetype_oga}"; + + /** The key of the message: WEBP Image */ + public static final String LABELS_facet_filetype_wepb = "{labels.facet_filetype_wepb}"; + + /** The key of the message: BMP Image */ + public static final String LABELS_facet_filetype_bmp = "{labels.facet_filetype_bmp}"; + + /** The key of the message: ICO Image */ + public static final String LABELS_facet_filetype_ico = "{labels.facet_filetype_ico}"; + + /** The key of the message: PNG Image */ + public static final String LABELS_facet_filetype_png = "{labels.facet_filetype_png}"; + + /** The key of the message: SVG Image */ + public static final String LABELS_facet_filetype_svg = "{labels.facet_filetype_svg}"; + + /** The key of the message: TIFF Image */ + public static final String LABELS_facet_filetype_tiff = "{labels.facet_filetype_tiff}"; + /** The key of the message: Others */ public static final String LABELS_facet_filetype_others = "{labels.facet_filetype_others}"; diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index 3b2f63573..0047f5977 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -469,16 +469,16 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ String QUERY_LANGUAGE_MAPPING = "query.language.mapping"; - /** The key of the configuration. e.g. 1.6 */ + /** The key of the configuration. e.g. 0.2 */ String QUERY_BOOST_TITLE = "query.boost.title"; - /** The key of the configuration. e.g. 2.0 */ + /** The key of the configuration. e.g. 1.0 */ String QUERY_BOOST_TITLE_LANG = "query.boost.title.lang"; - /** The key of the configuration. e.g. 1.0 */ + /** The key of the configuration. e.g. 0.1 */ String QUERY_BOOST_CONTENT = "query.boost.content"; - /** The key of the configuration. e.g. 1.3 */ + /** The key of the configuration. e.g. 0.5 */ String QUERY_BOOST_CONTENT_LANG = "query.boost.content.lang"; /** The key of the configuration. e.g. true */ @@ -2278,7 +2278,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** * Get the value for the key 'query.boost.title'.
- * The value is, e.g. 1.6
+ * The value is, e.g. 0.2
* comment: boost * @return The value of found property. (NotNull: if not found, exception but basically no way) */ @@ -2286,7 +2286,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** * Get the value for the key 'query.boost.title' as {@link java.math.BigDecimal}.
- * The value is, e.g. 1.6
+ * The value is, e.g. 0.2
* comment: boost * @return The value of found property. (NotNull: if not found, exception but basically no way) * @throws NumberFormatException When the property is not decimal. @@ -2295,14 +2295,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** * Get the value for the key 'query.boost.title.lang'.
- * The value is, e.g. 2.0
+ * The value is, e.g. 1.0
* @return The value of found property. (NotNull: if not found, exception but basically no way) */ String getQueryBoostTitleLang(); /** * Get the value for the key 'query.boost.title.lang' as {@link java.math.BigDecimal}.
- * The value is, e.g. 2.0
+ * The value is, e.g. 1.0
* @return The value of found property. (NotNull: if not found, exception but basically no way) * @throws NumberFormatException When the property is not decimal. */ @@ -2310,14 +2310,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** * Get the value for the key 'query.boost.content'.
- * The value is, e.g. 1.0
+ * The value is, e.g. 0.1
* @return The value of found property. (NotNull: if not found, exception but basically no way) */ String getQueryBoostContent(); /** * Get the value for the key 'query.boost.content' as {@link java.math.BigDecimal}.
- * The value is, e.g. 1.0
+ * The value is, e.g. 0.1
* @return The value of found property. (NotNull: if not found, exception but basically no way) * @throws NumberFormatException When the property is not decimal. */ @@ -2325,14 +2325,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** * Get the value for the key 'query.boost.content.lang'.
- * The value is, e.g. 1.3
+ * The value is, e.g. 0.5
* @return The value of found property. (NotNull: if not found, exception but basically no way) */ String getQueryBoostContentLang(); /** * Get the value for the key 'query.boost.content.lang' as {@link java.math.BigDecimal}.
- * The value is, e.g. 1.3
+ * The value is, e.g. 0.5
* @return The value of found property. (NotNull: if not found, exception but basically no way) * @throws NumberFormatException When the property is not decimal. */ diff --git a/src/main/resources/app.xml b/src/main/resources/app.xml index 29075ea41..5f28b9029 100644 --- a/src/main/resources/app.xml +++ b/src/main/resources/app.xml @@ -68,6 +68,28 @@ "filetype:bz", "filetype:bz2", "filetype:tar", + "filetype:rar", + "filetype:3gp", + "filetype:3g2", + "filetype:avi", + "filetype:flv", + "filetype:mpeg", + "filetype:mp4", + "filetype:ogv", + "filetype:qt", + "filetype:m4v", + "filetype:aif", + "filetype:mid", + "filetype:mpga", + "filetype:mp4a", + "filetype:oga", + "filetype:wav", + "filetype:webp", + "filetype:bmp", + "filetype:ico", + "filetype:png", + "filetype:svg", + "filetype:tiff", "filetype:others" ] @@ -210,10 +232,95 @@ "labels.facet_filetype_tar" "filetype:tar" + + "labels.facet_filetype_rar" + "filetype:rar" + + + "labels.facet_filetype_3gp" + "filetype:3gp" + + + "labels.facet_filetype_3g2" + "filetype:3g2" + + + "labels.facet_filetype_avi" + "filetype:avi" + + + "labels.facet_filetype_flv" + "filetype:flv" + + + "labels.facet_filetype_mpeg" + "filetype:mpeg" + + + "labels.facet_filetype_mp4" + "filetype:mp4" + + + "labels.facet_filetype_ogv" + "filetype:ogv" + + + "labels.facet_filetype_qt" + "filetype:qt" + + + "labels.facet_filetype_m4v" + "filetype:m4v" + + + "labels.facet_filetype_aif" + "filetype:aif" + + + "labels.facet_filetype_mid" + "filetype:mid" + + + "labels.facet_filetype_mpga" + "filetype:mpga" + + + "labels.facet_filetype_ogg" + "filetype:ogg" + + + "labels.facet_filetype_wav" + "filetype:wav" + + + "labels.facet_filetype_webp" + "filetype:webp" + + + "labels.facet_filetype_bmp" + "filetype:bmp" + + + "labels.facet_filetype_ico" + "filetype:ico" + + + "labels.facet_filetype_png" + "filetype:png" + + + "labels.facet_filetype_svg" + "filetype:svg" + + + "labels.facet_filetype_tiff" + "filetype:tiff" + "labels.facet_filetype_others" "filetype:others" + diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index 0f98b3645..a25915f71 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -250,10 +250,10 @@ zh-tw=zh-tw\n\ # boost -query.boost.title=1.6 -query.boost.title.lang=2.0 -query.boost.content=1.0 -query.boost.content.lang=1.3 +query.boost.title=0.2 +query.boost.title.lang=1.0 +query.boost.content=0.1 +query.boost.content.lang=0.5 # acl smb.role.from.file=true diff --git a/src/main/resources/fess_label.properties b/src/main/resources/fess_label.properties index 5e83beebd..89c08acc9 100644 --- a/src/main/resources/fess_label.properties +++ b/src/main/resources/fess_label.properties @@ -244,6 +244,28 @@ labels.facet_filetype_7z=7z Archive labels.facet_filetype_bz=Bz Archive labels.facet_filetype_bz2=Bz2 Archive labels.facet_filetype_tar=TAR Archive +labels.facet_filetype_rar=RAR Archive +labels.facet_filetype_3gp=3gp Video +labels.facet_filetype_3g2=3g2 Video +labels.facet_filetype_avi=AVI Video +labels.facet_filetype_flv=FLV Video +labels.facet_filetype_mpeg=MPEG Video +labels.facet_filetype_mp4=MP4 Video +labels.facet_filetype_ogv=OGV Video +labels.facet_filetype_qt=QuickTime Video +labels.facet_filetype_m4v=M4V Video +labels.facet_filetype_wav=WAV Audio +labels.facet_filetype_aif=AIF Audio +labels.facet_filetype_mid=MIDI Audio +labels.facet_filetype_mpga=MPGA Audio +labels.facet_filetype_mp4a=MP4A Audio +labels.facet_filetype_oga=OGA Audio +labels.facet_filetype_wepb=WEBP Image +labels.facet_filetype_bmp=BMP Image +labels.facet_filetype_ico=ICO Image +labels.facet_filetype_png=PNG Image +labels.facet_filetype_svg=SVG Image +labels.facet_filetype_tiff=TIFF Image labels.facet_filetype_others=Others labels.facet_label_reset=Reset labels.searchoptions_all=All diff --git a/src/main/resources/fess_label_en.properties b/src/main/resources/fess_label_en.properties index 56fe92c1d..6d2772483 100644 --- a/src/main/resources/fess_label_en.properties +++ b/src/main/resources/fess_label_en.properties @@ -244,6 +244,28 @@ labels.facet_filetype_7z=7z Archive labels.facet_filetype_bz=Bz Archive labels.facet_filetype_bz2=Bz2 Archive labels.facet_filetype_tar=TAR Archive +labels.facet_filetype_rar=RAR Archive +labels.facet_filetype_3gp=3gp Video +labels.facet_filetype_3g2=3g2 Video +labels.facet_filetype_avi=AVI Video +labels.facet_filetype_flv=FLV Video +labels.facet_filetype_mpeg=MPEG Video +labels.facet_filetype_mp4=MP4 Video +labels.facet_filetype_ogv=OGV Video +labels.facet_filetype_qt=QuickTime Video +labels.facet_filetype_m4v=M4V Video +labels.facet_filetype_wav=WAV Audio +labels.facet_filetype_aif=AIF Audio +labels.facet_filetype_mid=MIDI Audio +labels.facet_filetype_mpga=MPGA Audio +labels.facet_filetype_mp4a=MP4A Audio +labels.facet_filetype_oga=OGA Audio +labels.facet_filetype_wepb=WEBP Image +labels.facet_filetype_bmp=BMP Image +labels.facet_filetype_ico=ICO Image +labels.facet_filetype_png=PNG Image +labels.facet_filetype_svg=SVG Image +labels.facet_filetype_tiff=TIFF Image labels.facet_filetype_others=Others labels.facet_label_reset=Reset labels.searchoptions_all=All diff --git a/src/main/resources/fess_label_ja.properties b/src/main/resources/fess_label_ja.properties index a20a0173e..7036d3b9c 100644 --- a/src/main/resources/fess_label_ja.properties +++ b/src/main/resources/fess_label_ja.properties @@ -240,6 +240,28 @@ labels.facet_filetype_7z=7z\u30a2\u30fc\u30ab\u30a4\u30d6 labels.facet_filetype_bz=Bz\u30a2\u30fc\u30ab\u30a4\u30d6 labels.facet_filetype_bz2=Bz2\u30a2\u30fc\u30ab\u30a4\u30d6 labels.facet_filetype_tar=TAR\u30a2\u30fc\u30ab\u30a4\u30d6 +labels.facet_filetype_rar=RAR Archive +labels.facet_filetype_3gp=3gp Video +labels.facet_filetype_3g2=3g2 Video +labels.facet_filetype_avi=AVI Video +labels.facet_filetype_flv=FLV Video +labels.facet_filetype_mpeg=MPEG Video +labels.facet_filetype_mp4=MP4 Video +labels.facet_filetype_ogv=OGV Video +labels.facet_filetype_qt=QuickTime Video +labels.facet_filetype_m4v=M4V Video +labels.facet_filetype_wav=WAV Audio +labels.facet_filetype_aif=AIF Audio +labels.facet_filetype_mid=MIDI Audio +labels.facet_filetype_mpga=MPGA Audio +labels.facet_filetype_mp4a=MP4A Audio +labels.facet_filetype_oga=OGA Audio +labels.facet_filetype_wepb=WEBP Image +labels.facet_filetype_bmp=BMP Image +labels.facet_filetype_ico=ICO Image +labels.facet_filetype_png=PNG Image +labels.facet_filetype_svg=SVG Image +labels.facet_filetype_tiff=TIFF Image labels.facet_filetype_others=\u305d\u306e\u4ed6 labels.facet_label_reset=\u30ea\u30bb\u30c3\u30c8 labels.searchoptions_all=\u3059\u3079\u3066 diff --git a/src/main/resources/fess_label_ko.properties b/src/main/resources/fess_label_ko.properties index d573074c5..879f8679d 100644 --- a/src/main/resources/fess_label_ko.properties +++ b/src/main/resources/fess_label_ko.properties @@ -236,6 +236,28 @@ labels.facet_filetype_7z=7z Archive labels.facet_filetype_bz=Bz Archive labels.facet_filetype_bz2=Bz2 Archive labels.facet_filetype_tar=TAR Archive +labels.facet_filetype_rar=RAR Archive +labels.facet_filetype_3gp=3gp Video +labels.facet_filetype_3g2=3g2 Video +labels.facet_filetype_avi=AVI Video +labels.facet_filetype_flv=FLV Video +labels.facet_filetype_mpeg=MPEG Video +labels.facet_filetype_mp4=MP4 Video +labels.facet_filetype_ogv=OGV Video +labels.facet_filetype_qt=QuickTime Video +labels.facet_filetype_m4v=M4V Video +labels.facet_filetype_wav=WAV Audio +labels.facet_filetype_aif=AIF Audio +labels.facet_filetype_mid=MIDI Audio +labels.facet_filetype_mpga=MPGA Audio +labels.facet_filetype_mp4a=MP4A Audio +labels.facet_filetype_oga=OGA Audio +labels.facet_filetype_wepb=WEBP Image +labels.facet_filetype_bmp=BMP Image +labels.facet_filetype_ico=ICO Image +labels.facet_filetype_png=PNG Image +labels.facet_filetype_svg=SVG Image +labels.facet_filetype_tiff=TIFF Image labels.facet_filetype_others = \uae30\ud0c0 labels.facet_label_reset = \uc7ac\uc124\uc815 labels.searchoptions_all = \ubaa8\ub4e0 diff --git a/src/main/resources/fess_label_ru.properties b/src/main/resources/fess_label_ru.properties index 4a9212e85..ce51392c8 100644 --- a/src/main/resources/fess_label_ru.properties +++ b/src/main/resources/fess_label_ru.properties @@ -242,6 +242,28 @@ labels.facet_filetype_7z=7z Архив labels.facet_filetype_bz=Bz Архив labels.facet_filetype_bz2=Bz2 Архив labels.facet_filetype_tar=TAR Архив +labels.facet_filetype_rar=RAR Archive +labels.facet_filetype_3gp=3gp Video +labels.facet_filetype_3g2=3g2 Video +labels.facet_filetype_avi=AVI Video +labels.facet_filetype_flv=FLV Video +labels.facet_filetype_mpeg=MPEG Video +labels.facet_filetype_mp4=MP4 Video +labels.facet_filetype_ogv=OGV Video +labels.facet_filetype_qt=QuickTime Video +labels.facet_filetype_m4v=M4V Video +labels.facet_filetype_wav=WAV Audio +labels.facet_filetype_aif=AIF Audio +labels.facet_filetype_mid=MIDI Audio +labels.facet_filetype_mpga=MPGA Audio +labels.facet_filetype_mp4a=MP4A Audio +labels.facet_filetype_oga=OGA Audio +labels.facet_filetype_wepb=WEBP Image +labels.facet_filetype_bmp=BMP Image +labels.facet_filetype_ico=ICO Image +labels.facet_filetype_png=PNG Image +labels.facet_filetype_svg=SVG Image +labels.facet_filetype_tiff=TIFF Image labels.facet_filetype_others=Другие labels.facet_label_reset=Сброс labels.searchoptions_all=Все diff --git a/src/main/webapp/WEB-INF/crawler/resources/app.xml b/src/main/webapp/WEB-INF/crawler/resources/app.xml index c10dc22e1..7c0278c7a 100644 --- a/src/main/webapp/WEB-INF/crawler/resources/app.xml +++ b/src/main/webapp/WEB-INF/crawler/resources/app.xml @@ -137,6 +137,98 @@ "application/x-tar" "tar" + + "application/x-rar-compressed" + "rar" + + + "video/3gp" + "3gp" + + + "video/3g2" + "3g2" + + + "video/x-msvideo" + "avi" + + + "video/x-flv" + "flv" + + + "video/mpeg" + "mpeg" + + + "video/mp4" + "mp4" + + + "video/ogv" + "ogv" + + + "video/quicktime" + "qt" + + + "video/x-m4v" + "m4v" + + + "audio/x-aif" + "aif" + + + "audio/midi" + "midi" + + + "audio/mpga" + "mpga" + + + "audio/mp4" + "mp4a" + + + "audio/ogg" + "oga" + + + "audio/x-wav" + "wav" + + + "image/webp" + "webp" + + + "image/bmp" + "bmp" + + + "image/x-icon" + "ico" + + + "image/x-icon" + "ico" + + + "image/png" + "png" + + + "image/svg+xml" + "svg" + + + "image/tiff" + "tiff" + diff --git a/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java b/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java index 192b167f3..3ff2be279 100644 --- a/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java +++ b/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java @@ -297,4 +297,30 @@ public class FessXpathTransformerTest extends UnitFessTestCase { value = transformer.getSingleNodeValue(document, "//META[@name='keywords']/@content|//BODY", false); assertEquals("bbb aaa", value); } + + public void test_normalizeCanonicalUrl() throws Exception { + final FessXpathTransformer transformer = new FessXpathTransformer(); + String value; + + value = transformer.normalizeCanonicalUrl("http://hoge.com/", "a"); + assertEquals("http://hoge.com/a", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/", "aaa"); + assertEquals("http://hoge.com/aaa", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/", "/aaa"); + assertEquals("http://hoge.com/aaa", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/bbb", "aaa"); + assertEquals("http://hoge.com/aaa", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/bbb/", "aaa"); + assertEquals("http://hoge.com/bbb/aaa", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/bbb/", "/aaa"); + assertEquals("http://hoge.com/aaa", value); + + value = transformer.normalizeCanonicalUrl("http://hoge.com/bbb", "/aaa"); + assertEquals("http://hoge.com/aaa", value); + } } diff --git a/src/test/java/org/codelibs/fess/helper/QueryHelperTest.java b/src/test/java/org/codelibs/fess/helper/QueryHelperTest.java index 31c4f9cca..0910a7ec2 100644 --- a/src/test/java/org/codelibs/fess/helper/QueryHelperTest.java +++ b/src/test/java/org/codelibs/fess/helper/QueryHelperTest.java @@ -22,6 +22,10 @@ import org.codelibs.fess.Constants; import org.codelibs.fess.mylasta.direction.FessConfig; import org.codelibs.fess.unit.UnitFessTestCase; import org.codelibs.fess.util.ComponentUtil; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; public class QueryHelperTest extends UnitFessTestCase { @@ -32,7 +36,11 @@ public class QueryHelperTest extends UnitFessTestCase { super.setUp(); queryHelper = new QueryHelper() { protected QueryParser getQueryParser() { - return new ExtendableQueryParser(Constants.DEFAULT_FIELD, new WhitespaceAnalyzer()); + ExtendableQueryParser queryParser = new ExtendableQueryParser(Constants.DEFAULT_FIELD, new WhitespaceAnalyzer()); + queryParser.setLowercaseExpandedTerms(false); + queryParser.setAllowLeadingWildcard(true); + queryParser.setDefaultOperator(QueryParser.Operator.AND); + return queryParser; } }; final FessConfig fessConfig = ComponentUtil.getFessConfig(); @@ -43,1675 +51,58 @@ public class QueryHelperTest extends UnitFessTestCase { } public void test_build() { - assertEquals(answer_basic("QUERY"), build_helper("QUERY")); - assertEquals(answer_basic("QUERY"), build_helper("QUERY ")); - assertEquals(answer_basic("QUERY"), build_helper(" QUERY")); + float titleBoost = 0.2f; + float contentBoost = 0.1f; - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper("QUERY1 QUERY2")); - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper("QUERY1 QUERY2 ")); - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper(" QUERY1 QUERY2")); + assertQuery(functionScoreQuery(simpleQuery("QUERY", titleBoost, contentBoost)), buildQuery("QUERY")); + assertQuery(functionScoreQuery(simpleQuery("QUERY", titleBoost, contentBoost)), buildQuery(" QUERY")); + assertQuery(functionScoreQuery(simpleQuery("QUERY", titleBoost, contentBoost)), buildQuery("QUERY ")); - assertEquals(answer_basic("QUERY1 QUERY2"), build_helper("\"QUERY1 QUERY2\"")); - assertEquals(answer_basic("QUERY1 QUERY2"), build_helper("\"QUERY1 QUERY2\" ")); - assertEquals(answer_basic("QUERY1 QUERY2"), build_helper(" \"QUERY1 QUERY2\"")); + assertQuery( + functionScoreQuery(andQuery(simpleQuery("QUERY1", titleBoost, contentBoost), + simpleQuery("QUERY2", titleBoost, contentBoost))), buildQuery("QUERY1 QUERY2")); + assertQuery( + functionScoreQuery(andQuery(simpleQuery("QUERY1", titleBoost, contentBoost), + simpleQuery("QUERY2", titleBoost, contentBoost))), buildQuery("QUERY1 AND QUERY2")); - assertEquals(answer_and("QUERY1 QUERY2", "QUERY3"), build_helper("\"QUERY1 QUERY2\" QUERY3")); + assertQuery( + functionScoreQuery(orQuery(simpleQuery("QUERY1", titleBoost, contentBoost), simpleQuery("QUERY2", titleBoost, contentBoost))), + buildQuery("QUERY1 OR QUERY2")); } - public void test_build_fullwidthSpace() { - - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper("QUERY1\u3000QUERY2")); - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper("QUERY1\u3000QUERY2\u3000")); - assertEquals(answer_and("QUERY1", "QUERY2"), build_helper("\u3000QUERY1\u3000QUERY2")); - - assertEquals(answer_basic("QUERY1 QUERY2"), build_helper("\"QUERY1\u3000QUERY2\"")); - - assertEquals(answer_and("QUERY1 QUERY2", "QUERY3"), build_helper("\"QUERY1\u3000QUERY2\"\u3000QUERY3")); + private QueryBuilder andQuery(QueryBuilder... queries) { + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + for (QueryBuilder query : queries) { + boolQuery.must(query); + } + return boolQuery; } - public void test_build_term_field() { - final String[] ans = - { - "{ \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }", - "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"term\" : { \"mimetype\" : { \"value\" : \"QUERY1\", \"boost\" : 1.0 } } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" }; - assertEquals(answer_query(ans[0]), build_helper("mimetype:QUERY1")); - assertEquals(answer_query(ans[1]), build_helper("mimetype:QUERY1 QUERY2")); - assertEquals(answer_query(ans[2]), build_helper("mimetype:QUERY1 QUERY2 QUERY3")); - assertEquals(answer_query(ans[3]), build_helper("mimetype:QUERY1 host:QUERY2 QUERY3")); - assertEquals(answer_query(ans[4]), build_helper("mimetype:\"QUERY1 QUERY2\" QUERY3")); + private QueryBuilder orQuery(QueryBuilder... queries) { + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + for (QueryBuilder query : queries) { + boolQuery.should(query); + } + return boolQuery; } - public void test_build_match_field() { - final String[] ans = - { - "{ \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }", - "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" }; - assertEquals(answer_query(ans[0]), build_helper("title:QUERY1")); - assertEquals(answer_query(ans[1]), build_helper("title:QUERY1 QUERY2")); - assertEquals(answer_query(ans[2]), build_helper("title:QUERY1 QUERY2 QUERY3")); - assertEquals(answer_query(ans[3]), build_helper("title:QUERY1 host:QUERY2 QUERY3")); - assertEquals(answer_query(ans[4]), build_helper("title:\"QUERY1 QUERY2\" QUERY3")); + private QueryBuilder simpleQuery(String query, float titleBoost, float contentBoost) { + return QueryBuilders.boolQuery().should(QueryBuilders.matchPhraseQuery("title", query).boost(titleBoost)) + .should(QueryBuilders.matchPhraseQuery("content", query).boost(contentBoost)); } - public void test_build_unknown_field() { - final String[] ans = - { - "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"foo:QUERY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"term\" : { \"host\" : { \"value\" : \"QUERY2\", \"boost\" : 1.0 } } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }", - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY1 QUERY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"QUERY3\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }" }; - assertEquals(answer_query(ans[0]), build_helper("foo:QUERY1")); - assertEquals(answer_query(ans[1]), build_helper("foo:QUERY1 QUERY2")); - assertEquals(answer_query(ans[2]), build_helper("foo:QUERY1 QUERY2 QUERY3")); - assertEquals(answer_query(ans[3]), build_helper("foo:QUERY1 host:QUERY2 QUERY3")); - assertEquals(answer_query(ans[4]), build_helper("foo:\"QUERY1 QUERY2\" QUERY3")); + private QueryBuilder functionScoreQuery(QueryBuilder queryBuilder) { + return QueryBuilders.functionScoreQuery(queryBuilder).add(ScoreFunctionBuilders.fieldValueFactorFunction("boost")); } - private String answer_query(String q) { - return "{ \"function_score\" : { \"query\" : " + q - + ", \"functions\" : [ { \"field_value_factor\" : { \"field\" : \"boost\" } } ] } }"; + private void assertQuery(QueryBuilder query1, QueryBuilder query2) { + assertEquals(query1.toString(), query2.toString()); } - private String answer_basic(String q) { - final String template = - "{ \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"DUMMY\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"DUMMY\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }"; - return answer_query(template.replaceAll("DUMMY", q)); - } - - private String answer_and(String q1, String q2) { - final String template = - "{ \"bool\" : { \"should\" : [ { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"DUMMY1\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"DUMMY1\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } }, { \"bool\" : { \"should\" : [ { \"match\" : { \"title\" : { \"query\" : \"DUMMY2\", \"type\" : \"phrase\", \"boost\" : 1.6 } } }, { \"match\" : { \"content\" : { \"query\" : \"DUMMY2\", \"type\" : \"phrase\", \"boost\" : 1.0 } } } ] } } ] } }"; - return answer_query(template.replaceAll("DUMMY1", q1).replaceAll("DUMMY2", q2)); - } - - private String build_helper(String query) { + private QueryBuilder buildQuery(String query) { return queryHelper.build(query, context -> { context.skipRoleQuery(); - }).getQueryBuilder().toString().replaceAll("[\n ]+", " "); + }).getQueryBuilder(); } - // public void test_build_roleType() { - // for (final String op : new String[] { "AND", "OR" }) { - // queryHelper.roleQueryHelper = new RoleQueryHelper() { - // @Override - // public Set build() { - // final Set list = new LinkedHashSet<>(); - // list.add("guest"); - // return list; - // } - // }; - // - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("", queryHelper.build("", true).getQuery()); - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.build("QUERY", true).getQuery()); - // assertEquals("role:guest", queryHelper.build("QUERY", true).getFilterQueries()[0]); - // - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.build("QUERY1 QUERY2", true).getQuery()); - // assertEquals("role:guest", queryHelper.build("QUERY1 QUERY2", true).getFilterQueries()[0]); - // - // queryHelper.roleQueryHelper = new RoleQueryHelper() { - // @Override - // public Set build() { - // final Set list = new LinkedHashSet<>(); - // list.add("guest"); - // list.add("admin"); - // return list; - // } - // }; - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.build("QUERY", true).getQuery()); - // assertEquals("role:guest OR role:admin", queryHelper.build("QUERY", true).getFilterQueries()[0]); - // - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.build("QUERY1 QUERY2", true).getQuery()); - // assertEquals("role:guest OR role:admin", queryHelper.build("QUERY1 QUERY2", true).getFilterQueries()[0]); - // } - // } - // - // public void test_sortField() { - // String query; - // QueryContext queryContext; - // - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // query = ""; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(0, queryContext.getSortFields().length); - // - // query = "sort:content_length"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // - // query = "sort:content_length.desc"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.DESC, queryContext.getSortFields()[0].getOrder()); - // - // query = "sort:content_length.asc,last_modified"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(2, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // assertEquals("last_modified", queryContext.getSortFields()[1].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[1].getOrder()); - // - // query = "QUERY sort:content_length"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("title:QUERY OR content:QUERY", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // - // query = "QUERY sort:content_length.desc"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("title:QUERY OR content:QUERY", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.DESC, queryContext.getSortFields()[0].getOrder()); - // - // query = "QUERY sort:content_length.asc,last_modified"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("title:QUERY OR content:QUERY", queryContext.getQuery()); - // assertEquals(2, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // assertEquals("last_modified", queryContext.getSortFields()[1].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[1].getOrder()); - // - // query = "QUERY mimetype:QUERY1 sort:content_length"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // - // query = "QUERY sort:content_length.desc mimetype:QUERY1"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.DESC, queryContext.getSortFields()[0].getOrder()); - // - // query = "QUERY sort:content_length.asc,last_modified mimetype:QUERY1"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", queryContext.getQuery()); - // assertEquals(2, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // assertEquals("last_modified", queryContext.getSortFields()[1].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[1].getOrder()); - // } - // } - // - // public void test_sortField_invalid() { - // String query; - // QueryContext queryContext; - // - // query = "sort:hoge"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(0, queryContext.getSortFields().length); - // - // query = "sort:content_length.hoge"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(0, queryContext.getSortFields().length); - // - // query = "sort:content_length.asc,hoge"; - // queryContext = queryHelper.buildQuery(query); - // assertEquals("", queryContext.getQuery()); - // assertEquals(1, queryContext.getSortFields().length); - // assertEquals("content_length", queryContext.getSortFields()[0].getField()); - // assertEquals(Constants.ASC, queryContext.getSortFields()[0].getOrder()); - // } - // - // public void test_wildcardSearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // * - // - // assertEquals("title:\\* OR content:\\*", queryHelper.buildQuery("*").getQuery()); - // assertEquals("title:QUERY* OR content:QUERY*", queryHelper.buildQuery("QUERY* ").getQuery()); - // assertEquals("title:Q*ERY OR content:Q*ERY", queryHelper.buildQuery(" Q*ERY").getQuery()); - // - // assertEquals("(title:Q*ERY1 OR content:Q*ERY1) " + op + " (title:Q*ERY2 OR content:Q*ERY2)", - // queryHelper.buildQuery("Q*ERY1 Q*ERY2").getQuery()); - // - // assertEquals("title:Q*ERY1\\ Q*ERY2 OR content:Q*ERY1\\ Q*ERY2", queryHelper.buildQuery("\"Q*ERY1 Q*ERY2\"").getQuery()); - // - // assertEquals("(title:Q*ERY1\\ Q*ERY2 OR content:Q*ERY1\\ Q*ERY2) " + op + " (title:Q*ERY3 OR content:Q*ERY3)", - // queryHelper.buildQuery("\"Q*ERY1 Q*ERY2\" Q*ERY3").getQuery()); - // - // assertEquals("mimetype:QUERY1*", queryHelper.buildQuery("mimetype:QUERY1*").getQuery()); - // assertEquals("mimetype:QUERY1* " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1* QUERY2").getQuery()); - // - // // ? - // - // assertEquals("title:\\? OR content:\\?", queryHelper.buildQuery("?").getQuery()); - // assertEquals("title:QUERY? OR content:QUERY?", queryHelper.buildQuery("QUERY? ").getQuery()); - // assertEquals("title:Q?ERY OR content:Q?ERY", queryHelper.buildQuery(" Q?ERY").getQuery()); - // - // assertEquals("(title:Q?ERY1 OR content:Q?ERY1) " + op + " (title:Q?ERY2 OR content:Q?ERY2)", - // queryHelper.buildQuery("Q?ERY1 Q?ERY2").getQuery()); - // - // assertEquals("title:Q?ERY1\\ Q?ERY2 OR content:Q?ERY1\\ Q?ERY2", queryHelper.buildQuery("\"Q?ERY1 Q?ERY2\"").getQuery()); - // - // assertEquals("(title:Q?ERY1\\ Q?ERY2 OR content:Q?ERY1\\ Q?ERY2) " + op + " (title:Q?ERY3 OR content:Q?ERY3)", - // queryHelper.buildQuery("\"Q?ERY1 Q?ERY2\" Q?ERY3").getQuery()); - // - // assertEquals("mimetype:QUERY1?", queryHelper.buildQuery("mimetype:QUERY1?").getQuery()); - // assertEquals("mimetype:QUERY1? " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1? QUERY2").getQuery()); - // } - // } - // - // public void test_fuzzySearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~ - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildQuery("QUERY~").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1~ QUERY2").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1~ QUERY2~").getQuery()); - // - // assertEquals("mimetype:QUERY1~", queryHelper.buildQuery("mimetype:QUERY1~").getQuery()); - // assertEquals("mimetype:QUERY1~ " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1~ QUERY2").getQuery()); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildQuery("\"QUERY1 QUERY2\"~").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildQuery("\"QUERY1~\"").getQuery()); - // - // // ~0.8 - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildQuery("QUERY~0.8").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1~0.8 QUERY2").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1~0.5 QUERY2~0.8").getQuery()); - // - // assertEquals("mimetype:QUERY1~0.8", queryHelper.buildQuery("mimetype:QUERY1~0.8").getQuery()); - // assertEquals("mimetype:QUERY1~0.8 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1~0.8 QUERY2").getQuery()); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildQuery("\"QUERY1 QUERY2\"~0.8").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildQuery("\"QUERY1~0.8\"").getQuery()); - // - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildQuery("\"QUERY1~0.8a\"").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildQuery("\"QUERY1~a\"").getQuery()); - // } - // - // getMockRequest().setLocale(Locale.JAPANESE); - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~ - // - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY~", queryHelper.buildQuery("QUERY~").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("QUERY1~ QUERY2").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2~)", - // queryHelper.buildQuery("QUERY1~ QUERY2~").getQuery()); - // - // assertEquals("mimetype:QUERY1~", queryHelper.buildQuery("mimetype:QUERY1~").getQuery()); - // assertEquals("mimetype:QUERY1~ " + op + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1~ QUERY2").getQuery()); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2 OR content_ja:QUERY1\\ QUERY2~", - // queryHelper.buildQuery("\"QUERY1 QUERY2\"~").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~", queryHelper.buildQuery("\"QUERY1~\"").getQuery()); - // - // // ~0.8 - // - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY~0.8", queryHelper.buildQuery("QUERY~0.8").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("QUERY1~0.8 QUERY2").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.5) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2~0.8)", - // queryHelper.buildQuery("QUERY1~0.5 QUERY2~0.8").getQuery()); - // - // assertEquals("mimetype:QUERY1~0.8", queryHelper.buildQuery("mimetype:QUERY1~0.8").getQuery()); - // assertEquals("mimetype:QUERY1~0.8 " + op + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1~0.8 QUERY2").getQuery()); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2 OR content_ja:QUERY1\\ QUERY2~0.8", - // queryHelper.buildQuery("\"QUERY1 QUERY2\"~0.8").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8", queryHelper.buildQuery("\"QUERY1~0.8\"").getQuery()); - // - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8", queryHelper.buildQuery("\"QUERY1~0.8a\"").getQuery()); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~", queryHelper.buildQuery("\"QUERY1~a\"").getQuery()); - // } - // } - // - // public void test_proximitySearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~10 - // assertEquals("title:\"QUERY\"~10 OR content:\"QUERY\"~10", queryHelper.buildQuery("QUERY~10").getQuery()); - // assertEquals("title:\"QUERY\"~1 OR content:\"QUERY\"~1", queryHelper.buildQuery("QUERY~1").getQuery()); - // assertEquals("title:\"QUERY\"~5 OR content:\"QUERY\"~5", queryHelper.buildQuery("QUERY~5.5").getQuery()); - // assertEquals("(title:\"QUERY1\"~10 OR content:\"QUERY1\"~10) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1~10 QUERY2").getQuery()); - // assertEquals("(title:\"QUERY1\"~5 OR content:\"QUERY1\"~5) " + op + " (title:\"QUERY2\"~10 OR content:\"QUERY2\"~10)", - // queryHelper.buildQuery("QUERY1~5 QUERY2~10").getQuery()); - // - // assertEquals("mimetype:\"QUERY1\"~10", queryHelper.buildQuery("mimetype:QUERY1~10").getQuery()); - // assertEquals("mimetype:\"QUERY1\"~10 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1~10 QUERY2").getQuery()); - // - // assertEquals("title:\"QUERY1\\ QUERY2\"~10 OR content:\"QUERY1\\ QUERY2\"~10", - // queryHelper.buildQuery("\"QUERY1 QUERY2\"~10").getQuery()); - // assertEquals("title:\"QUERY1\"~10 OR content:\"QUERY1\"~10", queryHelper.buildQuery("\"QUERY1~10\"").getQuery()); - // - // assertEquals("title:\"QUERY1\"~10 OR content:\"QUERY1\"~10", queryHelper.buildQuery("\"QUERY1~10a\"").getQuery()); - // } - // } - // - // public void test_rangeSearches() { - // String rangeQuery; - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // mod_date:[20020101 TO 20030101] - // assertEquals("title:[20020101 TO 20030101] OR content:[20020101 TO 20030101]", - // queryHelper.buildQuery("[20020101 TO 20030101]").getQuery()); - // assertEquals("last_modified:[20020101 TO 20030101]", queryHelper.buildQuery("last_modified:[20020101 TO 20030101]").getQuery()); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " last_modified:[20020101 TO 20030101]", - // queryHelper.buildQuery("QUERY last_modified:[20020101 TO 20030101]").getQuery()); - // assertEquals("title:{Aida TO Carmen} OR content:{Aida TO Carmen}", queryHelper.buildQuery("{Aida TO Carmen}").getQuery()); - // assertEquals("last_modified:{Aida TO Carmen}", queryHelper.buildQuery("last_modified:{Aida TO Carmen}").getQuery()); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " title:{Aida TO Carmen}", - // queryHelper.buildQuery("QUERY title:{Aida TO Carmen}").getQuery()); - // assertEquals("last_modified:[20020101 TO abc]", queryHelper.buildQuery("last_modified:[20020101 TO abc]").getQuery()); - // assertEquals("last_modified:[abc TO 20020101]", queryHelper.buildQuery("last_modified:[abc TO 20020101]").getQuery()); - // assertEquals("last_modified:[20020101 TO *]", queryHelper.buildQuery("last_modified:[20020101 TO *]").getQuery()); - // assertEquals("last_modified:[* TO 20020101]", queryHelper.buildQuery("last_modified:[* TO 20020101]").getQuery()); - // - // rangeQuery = "(content:[1 TO 2] OR content:[3 TO 4]) " + op + " (content:[5 TO 6] OR content:[7 TO 8])"; - // assertEquals(rangeQuery, queryHelper.buildQuery(rangeQuery).getQuery()); - // - // try { - // queryHelper.buildQuery("last_modified:[20020101 TO]").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:[TO 20030101]").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:[20020101]").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:[20030101]").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // // mod_date:{20020101 TO 20030101} - // assertEquals("title:{20020101 TO 20030101} OR content:{20020101 TO 20030101}", - // queryHelper.buildQuery("{20020101 TO 20030101}").getQuery()); - // assertEquals("last_modified:{20020101 TO 20030101}", queryHelper.buildQuery("last_modified:{20020101 TO 20030101}").getQuery()); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " last_modified:{20020101 TO 20030101}", - // queryHelper.buildQuery("QUERY last_modified:{20020101 TO 20030101}").getQuery()); - // assertEquals("title:{Aida TO Carmen} OR content:{Aida TO Carmen}", queryHelper.buildQuery("{Aida TO Carmen}").getQuery()); - // assertEquals("last_modified:{Aida TO Carmen}", queryHelper.buildQuery("last_modified:{Aida TO Carmen}").getQuery()); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " title:{Aida TO Carmen}", - // queryHelper.buildQuery("QUERY title:{Aida TO Carmen}").getQuery()); - // assertEquals("last_modified:{20020101 TO abc}", queryHelper.buildQuery("last_modified:{20020101 TO abc}").getQuery()); - // assertEquals("last_modified:{abc TO 20020101}", queryHelper.buildQuery("last_modified:{abc TO 20020101}").getQuery()); - // assertEquals("last_modified:{20020101 TO *}", queryHelper.buildQuery("last_modified:{20020101 TO *}").getQuery()); - // assertEquals("last_modified:{* TO 20020101}", queryHelper.buildQuery("last_modified:{* TO 20020101}").getQuery()); - // - // rangeQuery = "(content:{1 TO 2} OR content:{3 TO 4}) " + op + " (content:{5 TO 6} OR content:{7 TO 8})"; - // assertEquals(rangeQuery, queryHelper.buildQuery(rangeQuery).getQuery()); - // - // try { - // queryHelper.buildQuery("last_modified:{20020101 TO}").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:{TO 20030101}").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:{20020101}").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // try { - // queryHelper.buildQuery("last_modified:{20030101}").getQuery(); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // rangeQuery = "(content:[1 TO 2] OR content:{3 TO 4}) " + op + " (content:{5 TO 6} OR content:[7 TO 8])"; - // assertEquals(rangeQuery, queryHelper.buildQuery(rangeQuery).getQuery()); - // } - // } - // - // public void test_boosting() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ^1000 ""^1000 - // assertEquals("title:QUERY^1000 OR content:QUERY^1000", queryHelper.buildQuery("QUERY^1000").getQuery()); - // assertEquals("(title:QUERY1^1000 OR content:QUERY1^1000) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1^1000 QUERY2").getQuery()); - // assertEquals("(title:QUERY1^500 OR content:QUERY1^500) " + op + " (title:QUERY2^1000 OR content:QUERY2^1000)", - // queryHelper.buildQuery("QUERY1^500 QUERY2^1000").getQuery()); - // - // assertEquals("mimetype:QUERY1^1000", queryHelper.buildQuery("mimetype:QUERY1^1000").getQuery()); - // assertEquals("mimetype:QUERY1^1000 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("mimetype:QUERY1^1000 QUERY2").getQuery()); - // - // assertEquals("title:QUERY1\\ QUERY2^1000 OR content:QUERY1\\ QUERY2^1000", - // queryHelper.buildQuery("\"QUERY1 QUERY2\"^1000").getQuery()); - // assertEquals("title:QUERY1^1000 OR content:QUERY1^1000", queryHelper.buildQuery("\"QUERY1^1000\"").getQuery()); - // } - // } - // - // public void test_reserved() { - // for (int i = 0; i < Constants.RESERVED.length - 1; i++) { - // try { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildQuery(Constants.RESERVED[i]).getQuery()); - // } catch (final InvalidQueryException e) { - // if (Constants.RESERVED[i].equals("\"") && e.getMessageCode().equals("errors.invalid_query_quoted")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildQuery("\\" + Constants.RESERVED[i]).getQuery()); - // continue; - // } else if (Constants.RESERVED[i].equals("{") && e.getMessageCode().equals("errors.invalid_query_curly_bracket")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildQuery("\\" + Constants.RESERVED[i]).getQuery()); - // continue; - // } else if (Constants.RESERVED[i].equals("[") && e.getMessageCode().equals("errors.invalid_query_square_bracket")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildQuery("\\" + Constants.RESERVED[i]).getQuery()); - // continue; - // } else if (Constants.RESERVED[i].equals("(") && e.getMessageCode().equals("errors.invalid_query_parenthesis")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildQuery("\\" + Constants.RESERVED[i]).getQuery()); - // continue; - // } - // } - // } - // assertEquals("title:\\: OR content:\\:", queryHelper.buildQuery(":").getQuery()); - // } - // - // public void test_or() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildQuery("OR QUERY").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1 OR QUERY2").getQuery()); - // assertEquals("title:QUERY", queryHelper.buildQuery("OR title:QUERY").getQuery()); - // assertEquals("title:QUERY1 OR title:QUERY2", queryHelper.buildQuery("title:QUERY1 OR title:QUERY2").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR title:QUERY2", queryHelper.buildQuery("QUERY1 OR title:QUERY2").getQuery()); - // assertEquals("mimetype:QUERY1 OR title:QUERY2", queryHelper.buildQuery("mimetype:QUERY1 OR title:QUERY2").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildQuery("QUERY1 OR QUERY2 QUERY3").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2) OR (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildQuery("QUERY1 OR QUERY2 OR QUERY3").getQuery()); - // } - // } - // - // public void test_and() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildQuery("AND QUERY").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("QUERY1 AND QUERY2").getQuery()); - // assertEquals("title:QUERY", queryHelper.buildQuery("AND title:QUERY").getQuery()); - // assertEquals("title:QUERY1 AND title:QUERY2", queryHelper.buildQuery("title:QUERY1 AND title:QUERY2").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND title:QUERY2", queryHelper.buildQuery("QUERY1 AND title:QUERY2").getQuery()); - // assertEquals("mimetype:QUERY1 AND title:QUERY2", queryHelper.buildQuery("mimetype:QUERY1 AND title:QUERY2").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildQuery("QUERY1 AND QUERY2 QUERY3").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2) AND (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildQuery("QUERY1 QUERY2 AND QUERY3").getQuery()); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2) AND (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildQuery("QUERY1 AND QUERY2 AND QUERY3").getQuery()); - // } - // } - // - // public void test_not() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("NOT (title:QUERY OR content:QUERY)", queryHelper.buildQuery("NOT QUERY").getQuery()); - // assertEquals("NOT title:QUERY", queryHelper.buildQuery("NOT title:QUERY").getQuery()); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildQuery("NOT QUERY1 QUERY2").getQuery()); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildQuery("NOT QUERY1 OR QUERY2").getQuery()); - // assertEquals("NOT (title:QUERY1 OR content:QUERY1) " + op + " NOT (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("NOT QUERY1 NOT QUERY2").getQuery()); - // assertEquals("NOT (title:QUERY1 OR content:QUERY1) " + op + " NOT (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildQuery("NOT QUERY1 OR NOT QUERY2").getQuery()); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1) " + op - // + " NOT (title:QUERY3 OR content:QUERY3)", queryHelper.buildQuery("NOT QUERY1 QUERY2 NOT QUERY3").getQuery()); - // assertEquals("NOT mimetype:QUERY", queryHelper.buildQuery("NOT mimetype:QUERY").getQuery()); - // assertEquals("NOT mimetype:QUERY1 " + op + " NOT title:QUERY2", - // queryHelper.buildQuery("NOT mimetype:QUERY1 NOT title:QUERY2").getQuery()); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT mimetype:QUERY1", - // queryHelper.buildQuery("NOT mimetype:QUERY1 QUERY2").getQuery()); - // assertEquals("mimetype:QUERY2 " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildQuery("NOT QUERY1 mimetype:QUERY2").getQuery()); - // } - // } - // - // public void test_escapeValue() { - // final String[] targets = - // new String[] { "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~", ":", "\\", " ", "\u3000" }; - // for (final String target : targets) { - // assertEquals("abc\\" + target + "123", QueryUtil.escapeValue("abc" + target + "123")); - // } - // for (final String target : targets) { - // assertEquals("abc\\" + target, QueryUtil.escapeValue("abc" + target)); - // } - // for (final String target : targets) { - // assertEquals("\\" + target + "123", QueryUtil.escapeValue(target + "123")); - // } - // for (final String target : targets) { - // assertEquals("abc\\" + target + "123\\" + target + "ABC", QueryUtil.escapeValue("abc" + target + "123" + target + "ABC")); - // } - // } - // - // public void test_escapeRangeValue() { - // final String[] targets = new String[] { "&&", "||", "!", "(", ")", "{", "}", "[", "]", "\"", "~", ":", "\\", " ", "\u3000" }; - // for (final String target : targets) { - // assertEquals("abc\\" + target + "123", QueryUtil.escapeValue("abc" + target + "123")); - // } - // for (final String target : targets) { - // assertEquals("abc\\" + target, QueryUtil.escapeValue("abc" + target)); - // } - // for (final String target : targets) { - // assertEquals("\\" + target + "123", QueryUtil.escapeValue(target + "123")); - // } - // for (final String target : targets) { - // assertEquals("abc\\" + target + "123\\" + target + "ABC", QueryUtil.escapeValue("abc" + target + "123" + target + "ABC")); - // } - // } - // - // public void test_buildFacet() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("", queryHelper.buildFacetQuery("")); - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("QUERY")); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("QUERY ")); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery(" QUERY")); - // - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1 QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1 QUERY2 ")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery(" QUERY1 QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"")); - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildFacetQuery("\"QUERY1 QUERY2\" ")); - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildFacetQuery(" \"QUERY1 QUERY2\"")); - // - // assertEquals("(title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("\"QUERY1 QUERY2\" QUERY3")); - // } - // } - // - // public void test_buildFacet_fullwidthSpace() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1\u3000QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1\u3000QUERY2\u3000")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("\u3000QUERY1\u3000QUERY2")); - // - // assertEquals("title:QUERY1\\\u3000QUERY2 OR content:QUERY1\\\u3000QUERY2", - // queryHelper.buildFacetQuery("\"QUERY1\u3000QUERY2\"")); - // - // assertEquals("(title:QUERY1\\\u3000QUERY2 OR content:QUERY1\\\u3000QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("\"QUERY1\u3000QUERY2\"\u3000QUERY3")); - // } - // } - // - // public void test_buildFacet_prefix() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("mimetype:QUERY1", queryHelper.buildFacetQuery("mimetype:QUERY1")); - // assertEquals("mimetype:QUERY1 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1 QUERY2")); - // assertEquals("mimetype:QUERY1 " + op + " (title:QUERY2 OR content:QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("mimetype:QUERY1 QUERY2 QUERY3")); - // assertEquals("mimetype:QUERY1 " + op + " host:QUERY2 " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("mimetype:QUERY1 host:QUERY2 QUERY3")); - // assertEquals("mimetype:QUERY1\\ QUERY2 " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("mimetype:\"QUERY1 QUERY2\" QUERY3")); - // } - // } - // - // public void test_buildFacet_prefix_unknown() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("title:site\\: OR content:site\\:", queryHelper.buildFacetQuery("site:")); - // assertEquals("title:hoge\\:QUERY1 OR content:hoge\\:QUERY1", queryHelper.buildFacetQuery("hoge:QUERY1")); - // assertEquals("(title:hoge\\:QUERY1 OR content:hoge\\:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("hoge:QUERY1 QUERY2")); - // assertEquals("(title:hoge\\:QUERY1 OR content:hoge\\:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2) " + op - // + " (title:QUERY3 OR content:QUERY3)", queryHelper.buildFacetQuery("hoge:QUERY1 QUERY2 QUERY3")); - // assertEquals( - // "(title:hoge\\:QUERY1 OR content:hoge\\:QUERY1) " + op + " host:QUERY2 " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("hoge:QUERY1 host:QUERY2 QUERY3")); - // assertEquals("(title:hoge\\:QUERY1\\ QUERY2 OR content:hoge\\:QUERY1\\ QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("hoge:\"QUERY1 QUERY2\" QUERY3")); - // } - // } - // - // public void test_buildFacet_sortField() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // String query; - // String searchQuery; - // - // query = ""; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "sort:content_length"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "sort:content_length.desc"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "sort:content_length.asc,last_modified"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "QUERY sort:content_length"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("title:QUERY OR content:QUERY", searchQuery); - // - // query = "QUERY sort:content_length.desc"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("title:QUERY OR content:QUERY", searchQuery); - // - // query = "QUERY sort:content_length.asc,last_modified"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("title:QUERY OR content:QUERY", searchQuery); - // - // query = "QUERY mimetype:QUERY1 sort:content_length"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", searchQuery); - // - // query = "QUERY sort:content_length.desc mimetype:QUERY1"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", searchQuery); - // - // query = "QUERY sort:content_length.asc,last_modified mimetype:QUERY1"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " mimetype:QUERY1", searchQuery); - // } - // } - // - // public void test_buildFacet_sortField_invalid() { - // String query; - // String searchQuery; - // - // query = "sort:hoge"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "sort:content_length.hoge"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // - // query = "sort:content_length.asc,hoge"; - // searchQuery = queryHelper.buildFacetQuery(query); - // assertEquals("", searchQuery); - // } - // - // public void test_buildFacet_wildcardSearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // * - // - // assertEquals("title:\\* OR content:\\*", queryHelper.buildFacetQuery("*")); - // assertEquals("title:QUERY* OR content:QUERY*", queryHelper.buildFacetQuery("QUERY* ")); - // assertEquals("title:Q*ERY OR content:Q*ERY", queryHelper.buildFacetQuery(" Q*ERY")); - // - // assertEquals("(title:Q*ERY1 OR content:Q*ERY1) " + op + " (title:Q*ERY2 OR content:Q*ERY2)", - // queryHelper.buildFacetQuery("Q*ERY1 Q*ERY2")); - // - // assertEquals("title:Q*ERY1\\ Q*ERY2 OR content:Q*ERY1\\ Q*ERY2", queryHelper.buildFacetQuery("\"Q*ERY1 Q*ERY2\"")); - // - // assertEquals("(title:Q*ERY1\\ Q*ERY2 OR content:Q*ERY1\\ Q*ERY2) " + op + " (title:Q*ERY3 OR content:Q*ERY3)", - // queryHelper.buildFacetQuery("\"Q*ERY1 Q*ERY2\" Q*ERY3")); - // - // assertEquals("mimetype:QUERY1*", queryHelper.buildFacetQuery("mimetype:QUERY1*")); - // assertEquals("mimetype:QUERY1* " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1* QUERY2")); - // - // assertEquals("title:\\*QUERY1 OR content:\\*QUERY1", queryHelper.buildFacetQuery("*QUERY1")); - // assertEquals("title:\\*QUERY1* OR content:\\*QUERY1*", queryHelper.buildFacetQuery("*QUERY1*")); - // - // // ? - // - // assertEquals("title:\\? OR content:\\?", queryHelper.buildFacetQuery("?")); - // assertEquals("title:QUERY? OR content:QUERY?", queryHelper.buildFacetQuery("QUERY? ")); - // assertEquals("title:Q?ERY OR content:Q?ERY", queryHelper.buildFacetQuery(" Q?ERY")); - // - // assertEquals("(title:Q?ERY1 OR content:Q?ERY1) " + op + " (title:Q?ERY2 OR content:Q?ERY2)", - // queryHelper.buildFacetQuery("Q?ERY1 Q?ERY2")); - // - // assertEquals("title:Q?ERY1\\ Q?ERY2 OR content:Q?ERY1\\ Q?ERY2", queryHelper.buildFacetQuery("\"Q?ERY1 Q?ERY2\"")); - // - // assertEquals("(title:Q?ERY1\\ Q?ERY2 OR content:Q?ERY1\\ Q?ERY2) " + op + " (title:Q?ERY3 OR content:Q?ERY3)", - // queryHelper.buildFacetQuery("\"Q?ERY1 Q?ERY2\" Q?ERY3")); - // - // assertEquals("mimetype:QUERY1?", queryHelper.buildFacetQuery("mimetype:QUERY1?")); - // assertEquals("mimetype:QUERY1? " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1? QUERY2")); - // - // assertEquals("title:\\?QUERY1 OR content:\\?QUERY1", queryHelper.buildFacetQuery("?QUERY1")); - // assertEquals("title:\\?QUERY1? OR content:\\?QUERY1?", queryHelper.buildFacetQuery("?QUERY1?")); - // } - // } - // - // public void test_buildFacet_fuzzySearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~ - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("QUERY~")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1~ QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1~ QUERY2~")); - // - // assertEquals("mimetype:QUERY1~", queryHelper.buildFacetQuery("mimetype:QUERY1~")); - // assertEquals("mimetype:QUERY1~ " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1~ QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"~")); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildFacetQuery("\"QUERY1~\"")); - // - // // ~0.8 - // - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("QUERY~0.8")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1~0.8 QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1~0.5 QUERY2~0.8")); - // - // assertEquals("mimetype:QUERY1~0.8", queryHelper.buildFacetQuery("mimetype:QUERY1~0.8")); - // assertEquals("mimetype:QUERY1~0.8 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1~0.8 QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2", queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"~0.8")); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildFacetQuery("\"QUERY1~0.8\"")); - // - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildFacetQuery("\"QUERY1~0.8a\"")); - // assertEquals("title:QUERY1 OR content:QUERY1", queryHelper.buildFacetQuery("\"QUERY1~a\"")); - // } - // - // getMockRequest().setLocale(Locale.JAPANESE); - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~ - // - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY~", queryHelper.buildFacetQuery("QUERY~")); - // assertEquals("(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", queryHelper.buildFacetQuery("QUERY1~ QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2~)", queryHelper.buildFacetQuery("QUERY1~ QUERY2~")); - // - // assertEquals("mimetype:QUERY1~", queryHelper.buildFacetQuery("mimetype:QUERY1~")); - // assertEquals("mimetype:QUERY1~ " + op + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1~ QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2 OR content_ja:QUERY1\\ QUERY2~", - // queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"~")); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~", queryHelper.buildFacetQuery("\"QUERY1~\"")); - // - // // ~0.8 - // - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY~0.8", queryHelper.buildFacetQuery("QUERY~0.8")); - // assertEquals("(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", queryHelper.buildFacetQuery("QUERY1~0.8 QUERY2")); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.5) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2~0.8)", - // queryHelper.buildFacetQuery("QUERY1~0.5 QUERY2~0.8")); - // - // assertEquals("mimetype:QUERY1~0.8", queryHelper.buildFacetQuery("mimetype:QUERY1~0.8")); - // assertEquals("mimetype:QUERY1~0.8 " + op + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1~0.8 QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2 OR content:QUERY1\\ QUERY2 OR content_ja:QUERY1\\ QUERY2~0.8", - // queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"~0.8")); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8", queryHelper.buildFacetQuery("\"QUERY1~0.8\"")); - // - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~0.8", queryHelper.buildFacetQuery("\"QUERY1~0.8a\"")); - // assertEquals("title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1~", queryHelper.buildFacetQuery("\"QUERY1~a\"")); - // } - // } - // - // public void test_buildFacet_proximitySearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ~10 - // assertEquals("title:\"QUERY\"~10 OR content:\"QUERY\"~10", queryHelper.buildFacetQuery("QUERY~10")); - // assertEquals("title:\"QUERY\"~1 OR content:\"QUERY\"~1", queryHelper.buildFacetQuery("QUERY~1")); - // assertEquals("title:\"QUERY\"~5 OR content:\"QUERY\"~5", queryHelper.buildFacetQuery("QUERY~5.5")); - // assertEquals("(title:\"QUERY1\"~10 OR content:\"QUERY1\"~10) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1~10 QUERY2")); - // assertEquals("(title:\"QUERY1\"~5 OR content:\"QUERY1\"~5) " + op + " (title:\"QUERY2\"~10 OR content:\"QUERY2\"~10)", - // queryHelper.buildFacetQuery("QUERY1~5 QUERY2~10")); - // - // assertEquals("mimetype:\"QUERY1\"~10", queryHelper.buildFacetQuery("mimetype:QUERY1~10")); - // assertEquals("mimetype:\"QUERY1\"~10 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1~10 QUERY2")); - // - // assertEquals("title:\"QUERY1\\ QUERY2\"~10 OR content:\"QUERY1\\ QUERY2\"~10", - // queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"~10")); - // assertEquals("title:\"QUERY1\"~10 OR content:\"QUERY1\"~10", queryHelper.buildFacetQuery("\"QUERY1~10\"")); - // - // assertEquals("title:\"QUERY1\"~10 OR content:\"QUERY1\"~10", queryHelper.buildFacetQuery("\"QUERY1~10a\"")); - // } - // } - // - // public void test_buildFacet_rangeSearches() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // mod_date:[20020101 TO 20030101] - // assertEquals("title:[20020101 TO 20030101] OR content:[20020101 TO 20030101]", - // queryHelper.buildFacetQuery("[20020101 TO 20030101]")); - // assertEquals("last_modified:[20020101 TO 20030101]", queryHelper.buildFacetQuery("last_modified:[20020101 TO 20030101]")); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " last_modified:[20020101 TO 20030101]", - // queryHelper.buildFacetQuery("QUERY last_modified:[20020101 TO 20030101]")); - // - // // TODO more.. - // - // // title:{Aida TO Carmen} - // assertEquals("title:{Aida TO Carmen} OR content:{Aida TO Carmen}", queryHelper.buildFacetQuery("{Aida TO Carmen}")); - // assertEquals("last_modified:{Aida TO Carmen}", queryHelper.buildFacetQuery("last_modified:{Aida TO Carmen}")); - // assertEquals("(title:QUERY OR content:QUERY) " + op + " title:{Aida TO Carmen}", - // queryHelper.buildFacetQuery("QUERY title:{Aida TO Carmen}")); - // - // // TODO more.. - // } - // } - // - // public void test_buildFacet_boosting() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // // ^1000 ""^1000 - // assertEquals("title:QUERY^1000 OR content:QUERY^1000", queryHelper.buildFacetQuery("QUERY^1000")); - // assertEquals("(title:QUERY1^1000 OR content:QUERY1^1000) " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1^1000 QUERY2")); - // assertEquals("(title:QUERY1^500 OR content:QUERY1^500) " + op + " (title:QUERY2^1000 OR content:QUERY2^1000)", - // queryHelper.buildFacetQuery("QUERY1^500 QUERY2^1000")); - // - // assertEquals("mimetype:QUERY1^1000", queryHelper.buildFacetQuery("mimetype:QUERY1^1000")); - // assertEquals("mimetype:QUERY1^1000 " + op + " (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("mimetype:QUERY1^1000 QUERY2")); - // - // assertEquals("title:QUERY1\\ QUERY2^1000 OR content:QUERY1\\ QUERY2^1000", - // queryHelper.buildFacetQuery("\"QUERY1 QUERY2\"^1000")); - // assertEquals("title:QUERY1^1000 OR content:QUERY1^1000", queryHelper.buildFacetQuery("\"QUERY1^1000\"")); - // } - // } - // - // public void test_buildFacet_reserved() { - // for (int i = 0; i < Constants.RESERVED.length - 1; i++) { - // try { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildFacetQuery(Constants.RESERVED[i])); - // } catch (final InvalidQueryException e) { - // if (Constants.RESERVED[i].equals("\"") && e.getMessageCode().equals("errors.invalid_query_quoted")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildFacetQuery("\\" + Constants.RESERVED[i])); - // continue; - // } else if (Constants.RESERVED[i].equals("{") && e.getMessageCode().equals("errors.invalid_query_curly_bracket")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildFacetQuery("\\" + Constants.RESERVED[i])); - // continue; - // } else if (Constants.RESERVED[i].equals("[") && e.getMessageCode().equals("errors.invalid_query_square_bracket")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildFacetQuery("\\" + Constants.RESERVED[i])); - // continue; - // } else if (Constants.RESERVED[i].equals("(") && e.getMessageCode().equals("errors.invalid_query_parenthesis")) { - // assertEquals("title:\\" + Constants.RESERVED[i] + " OR content:\\" + Constants.RESERVED[i], - // queryHelper.buildFacetQuery("\\" + Constants.RESERVED[i])); - // continue; - // } - // } - // } - // assertEquals("title:\\: OR content:\\:", queryHelper.buildFacetQuery(":")); - // } - // - // public void test_buildFacet_or() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("OR QUERY")); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1 OR QUERY2")); - // assertEquals("title:QUERY", queryHelper.buildFacetQuery("OR title:QUERY")); - // assertEquals("title:QUERY1 OR title:QUERY2", queryHelper.buildFacetQuery("title:QUERY1 OR title:QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR title:QUERY2", queryHelper.buildFacetQuery("QUERY1 OR title:QUERY2")); - // assertEquals("mimetype:QUERY1 OR title:QUERY2", queryHelper.buildFacetQuery("mimetype:QUERY1 OR title:QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("QUERY1 OR QUERY2 QUERY3")); - // assertEquals("(title:QUERY1 OR content:QUERY1) OR (title:QUERY2 OR content:QUERY2) OR (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("QUERY1 OR QUERY2 OR QUERY3")); - // } - // } - // - // public void test_buildFacet_and() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("title:QUERY OR content:QUERY", queryHelper.buildFacetQuery("AND QUERY")); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("QUERY1 AND QUERY2")); - // assertEquals("title:QUERY", queryHelper.buildFacetQuery("AND title:QUERY")); - // assertEquals("title:QUERY1 AND title:QUERY2", queryHelper.buildFacetQuery("title:QUERY1 AND title:QUERY2")); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND title:QUERY2", queryHelper.buildFacetQuery("QUERY1 AND title:QUERY2")); - // assertEquals("mimetype:QUERY1 AND title:QUERY2", queryHelper.buildFacetQuery("mimetype:QUERY1 AND title:QUERY2")); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2) " + op + " (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("QUERY1 AND QUERY2 QUERY3")); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1) " + op + " (title:QUERY2 OR content:QUERY2) AND (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("QUERY1 QUERY2 AND QUERY3")); - // assertEquals("(title:QUERY1 OR content:QUERY1) AND (title:QUERY2 OR content:QUERY2) AND (title:QUERY3 OR content:QUERY3)", - // queryHelper.buildFacetQuery("QUERY1 AND QUERY2 AND QUERY3")); - // } - // } - // - // public void test_buildFacet_not() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("NOT (title:QUERY OR content:QUERY)", queryHelper.buildFacetQuery("NOT QUERY")); - // assertEquals("NOT title:QUERY", queryHelper.buildFacetQuery("NOT title:QUERY")); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildFacetQuery("NOT QUERY1 QUERY2")); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildFacetQuery("NOT QUERY1 OR QUERY2")); - // assertEquals("NOT (title:QUERY1 OR content:QUERY1) " + op + " NOT (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("NOT QUERY1 NOT QUERY2")); - // assertEquals("NOT (title:QUERY1 OR content:QUERY1) " + op + " NOT (title:QUERY2 OR content:QUERY2)", - // queryHelper.buildFacetQuery("NOT QUERY1 OR NOT QUERY2")); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT (title:QUERY1 OR content:QUERY1) " + op - // + " NOT (title:QUERY3 OR content:QUERY3)", queryHelper.buildFacetQuery("NOT QUERY1 QUERY2 NOT QUERY3")); - // assertEquals("NOT mimetype:QUERY", queryHelper.buildFacetQuery("NOT mimetype:QUERY")); - // assertEquals("NOT mimetype:QUERY1 " + op + " NOT title:QUERY2", - // queryHelper.buildFacetQuery("NOT mimetype:QUERY1 NOT title:QUERY2")); - // assertEquals("(title:QUERY2 OR content:QUERY2) " + op + " NOT mimetype:QUERY1", - // queryHelper.buildFacetQuery("NOT mimetype:QUERY1 QUERY2")); - // assertEquals("mimetype:QUERY2 " + op + " NOT (title:QUERY1 OR content:QUERY1)", - // queryHelper.buildFacetQuery("NOT QUERY1 mimetype:QUERY2")); - // } - // } - // - // public void test_inner_query() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("(title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)", - // queryHelper.buildQuery("(bbb ccc)").getQuery()); - // assertEquals("(title:bbb OR content:bbb) OR (title:ccc OR content:ccc)", queryHelper.buildQuery("(bbb OR ccc)").getQuery()); - // assertEquals("(title:bbb OR content:bbb) AND (title:ccc OR content:ccc)", queryHelper.buildQuery("(bbb AND ccc)").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (bbb ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (bbb AND ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa AND (bbb AND ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa OR (bbb AND ccc)").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (bbb OR ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa AND (bbb OR ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa OR (bbb OR ccc)").getQuery()); - // - // assertEquals("((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb ccc) ddd").getQuery()); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb AND ccc) ddd").getQuery()); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb AND ccc) AND ddd").getQuery()); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb AND ccc) OR ddd").getQuery()); - // - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb OR ccc) ddd").getQuery()); - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb OR ccc) AND ddd").getQuery()); - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildQuery("(bbb OR ccc) OR ddd").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildQuery("aaa (bbb ccc) ddd").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildQuery("aaa (bbb AND ccc) ddd").getQuery()); - // assertEquals( - // "(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildQuery("aaa AND (bbb AND ccc) AND ddd").getQuery()); - // assertEquals( - // "(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildQuery("aaa OR (bbb AND ccc) OR ddd").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildQuery("aaa (bbb OR ccc) ddd").getQuery()); - // assertEquals( - // "(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildQuery("aaa AND (bbb OR ccc) AND ddd").getQuery()); - // assertEquals( - // "(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildQuery("aaa OR (bbb OR ccc) OR ddd").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb " + op + " (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (label:bbb ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb AND (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (label:bbb AND ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb OR (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (label:bbb OR ccc)").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " label:ccc)", - // queryHelper.buildQuery("aaa (bbb label:ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND label:ccc)", - // queryHelper.buildQuery("aaa (bbb AND label:ccc)").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR label:ccc)", - // queryHelper.buildQuery("aaa (bbb OR label:ccc)").getQuery()); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " NOT (title:ccc OR content:ccc))", - // queryHelper.buildQuery("aaa (bbb NOT ccc)").getQuery()); - // } - // } - // - // public void test_more_inner_query() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " ((title:ccc OR content:ccc) " + op - // + " (title:ddd OR content:ddd)))", queryHelper.buildQuery("aaa (bbb (ccc ddd))").getQuery()); - // assertEquals("(((title:aaa OR content:aaa) " + op + " (title:bbb OR content:bbb)) " + op + " (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildQuery("((aaa bbb) ccc) ddd").getQuery()); - // } - // } - // - // public void test_inner_facetQuery() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("(title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)", queryHelper.buildFacetQuery("(bbb ccc)")); - // assertEquals("(title:bbb OR content:bbb) OR (title:ccc OR content:ccc)", queryHelper.buildFacetQuery("(bbb OR ccc)")); - // assertEquals("(title:bbb OR content:bbb) AND (title:ccc OR content:ccc)", queryHelper.buildFacetQuery("(bbb AND ccc)")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (bbb ccc)")); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (bbb AND ccc)")); - // assertEquals("(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa AND (bbb AND ccc)")); - // assertEquals("(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa OR (bbb AND ccc)")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (bbb OR ccc)")); - // assertEquals("(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa AND (bbb OR ccc)")); - // assertEquals("(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa OR (bbb OR ccc)")); - // - // assertEquals("((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb ccc) ddd")); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb AND ccc) ddd")); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb AND ccc) AND ddd")); - // assertEquals("((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb AND ccc) OR ddd")); - // - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) " + op + " (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb OR ccc) ddd")); - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb OR ccc) AND ddd")); - // assertEquals("((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("(bbb OR ccc) OR ddd")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildFacetQuery("aaa (bbb ccc) ddd")); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildFacetQuery("aaa (bbb AND ccc) ddd")); - // assertEquals( - // "(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("aaa AND (bbb AND ccc) AND ddd")); - // assertEquals( - // "(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) AND (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("aaa OR (bbb AND ccc) OR ddd")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildFacetQuery("aaa (bbb OR ccc) ddd")); - // assertEquals( - // "(title:aaa OR content:aaa) AND ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) AND (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("aaa AND (bbb OR ccc) AND ddd")); - // assertEquals( - // "(title:aaa OR content:aaa) OR ((title:bbb OR content:bbb) OR (title:ccc OR content:ccc)) OR (title:ddd OR content:ddd)", - // queryHelper.buildFacetQuery("aaa OR (bbb OR ccc) OR ddd")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb " + op + " (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (label:bbb ccc)")); - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb AND (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (label:bbb AND ccc)")); - // assertEquals("(title:aaa OR content:aaa) " + op + " (label:bbb OR (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (label:bbb OR ccc)")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " label:ccc)", - // queryHelper.buildFacetQuery("aaa (bbb label:ccc)")); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) AND label:ccc)", - // queryHelper.buildFacetQuery("aaa (bbb AND label:ccc)")); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) OR label:ccc)", - // queryHelper.buildFacetQuery("aaa (bbb OR label:ccc)")); - // - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " NOT (title:ccc OR content:ccc))", - // queryHelper.buildFacetQuery("aaa (bbb NOT ccc)")); - // } - // } - // - // public void test_more_inner_facetQuery() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("(title:aaa OR content:aaa) " + op + " ((title:bbb OR content:bbb) " + op + " ((title:ccc OR content:ccc) " + op - // + " (title:ddd OR content:ddd)))", queryHelper.buildFacetQuery("aaa (bbb (ccc ddd))")); - // assertEquals("(((title:aaa OR content:aaa) " + op + " (title:bbb OR content:bbb)) " + op + " (title:ccc OR content:ccc)) " + op - // + " (title:ddd OR content:ddd)", queryHelper.buildFacetQuery("((aaa bbb) ccc) ddd")); - // } - // } - // - // public void test_quote_query() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertException(format, "\"", "errors.invalid_query_quoted"); - // assertException(format, "a\"", "errors.invalid_query_quoted"); - // assertException(format, "\"b", "errors.invalid_query_quoted"); - // assertException(format, "a\"b", "errors.invalid_query_quoted"); - // assertException(format, "content:\"", "errors.invalid_query_quoted"); - // assertException(format, "content:\" ", "errors.invalid_query_quoted"); - // assertException(format, "content:a\"", "errors.invalid_query_quoted"); - // assertException(format, "content:\"b", "errors.invalid_query_quoted"); - // assertException(format, "content:a\"b", "errors.invalid_query_quoted"); - // } - // } - // - // public void test_curly_bracket_query() { - // queryHelper = new QueryHelper(); - // inject(new FieldHelper()); - // inject(new SystemHelper()); - // inject(queryHelper); - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertException(format, "{", "errors.invalid_query_curly_bracket"); - // assertException(format, "a{", "errors.invalid_query_curly_bracket"); - // assertException(format, "{b", "errors.invalid_query_curly_bracket"); - // assertException(format, "a{b", "errors.invalid_query_curly_bracket"); - // assertException(format, "content:{", "errors.invalid_query_curly_bracket"); - // assertException(format, "content:{ ", "errors.invalid_query_curly_bracket"); - // assertException(format, "content:a{", "errors.invalid_query_curly_bracket"); - // assertException(format, "content:{b", "errors.invalid_query_curly_bracket"); - // assertException(format, "content:a{b", "errors.invalid_query_curly_bracket"); - // } - // } - // - // public void test_square_bracket_query() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertException(format, "[", "errors.invalid_query_square_bracket"); - // assertException(format, "a[", "errors.invalid_query_square_bracket"); - // assertException(format, "[b", "errors.invalid_query_square_bracket"); - // assertException(format, "a[b", "errors.invalid_query_square_bracket"); - // assertException(format, "content:[", "errors.invalid_query_square_bracket"); - // assertException(format, "content:[ ", "errors.invalid_query_square_bracket"); - // assertException(format, "content:a[", "errors.invalid_query_square_bracket"); - // assertException(format, "content:[b", "errors.invalid_query_square_bracket"); - // assertException(format, "content:a[b", "errors.invalid_query_square_bracket"); - // } - // } - // - // public void test_parenthesis_query() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertException(format, "(", "errors.invalid_query_parenthesis"); - // assertException(format, "a(", "errors.invalid_query_parenthesis"); - // assertException(format, "(b", "errors.invalid_query_parenthesis"); - // assertException(format, "a(b", "errors.invalid_query_parenthesis"); - // assertException(format, "content:(", "errors.invalid_query_parenthesis"); - // assertException(format, "content:( ", "errors.invalid_query_parenthesis"); - // assertException(format, "content:a(", "errors.invalid_query_parenthesis"); - // assertException(format, "content:(b", "errors.invalid_query_parenthesis"); - // assertException(format, "content:a(b", "errors.invalid_query_parenthesis"); - // } - // } - // - // private void assertException(final String format, final String query, final String messageCode) { - // try { - // final String ret = queryHelper.buildQuery(String.format(format, query)).getQuery(); - // fail("format: " + format + ", query: " + query + ", ret: " + ret); - // } catch (final InvalidQueryException e) { - // FessMessages messages = new FessMessages(); - // e.getMessageCode().message(messages); - // if (!messages.hasMessageOf(UserMessages.GLOBAL_PROPERTY_KEY, messageCode)) { - // throw e; - // } - // } - // } - // - // public void test_quote_facetQuery() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertExceptionOnFacetQuery(format, "\"", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "a\"", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "\"b", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "a\"b", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "content:\"", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "content:\" ", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "content:a\"", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "content:\"b", "errors.invalid_query_quoted"); - // assertExceptionOnFacetQuery(format, "content:a\"b", "errors.invalid_query_quoted"); - // } - // } - // - // public void test_curly_bracket_facetQuery() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertExceptionOnFacetQuery(format, "{", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "a{", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "{b", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "a{b", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "content:{", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "content:{ ", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "content:a{", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "content:{b", "errors.invalid_query_curly_bracket"); - // assertExceptionOnFacetQuery(format, "content:a{b", "errors.invalid_query_curly_bracket"); - // } - // } - // - // public void test_square_bracket_facetQuery() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertExceptionOnFacetQuery(format, "[", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "a[", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "[b", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "a[b", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "content:[", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "content:[ ", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "content:a[", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "content:[b", "errors.invalid_query_square_bracket"); - // assertExceptionOnFacetQuery(format, "content:a[b", "errors.invalid_query_square_bracket"); - // } - // } - // - // public void test_parenthesis_facetQuery() { - // final String[] formats = - // { "%s", " %s ", "aaa %s", "aaa OR %s", "NOT %s", "%s bbb", "%s bbb", "%s OR bbb", "aaa (%s)", "(%s) bbb", "aaa (%s) bbb" }; - // for (final String format : formats) { - // assertExceptionOnFacetQuery(format, "(", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "a(", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "(b", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "a(b", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "content:(", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "content:( ", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "content:a(", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "content:(b", "errors.invalid_query_parenthesis"); - // assertExceptionOnFacetQuery(format, "content:a(b", "errors.invalid_query_parenthesis"); - // } - // } - // - // public void test_buildContentQueryWithLang() { - // StringBuilder buf; - // - // buf = new StringBuilder(); - // queryHelper.buildContentQueryWithLang(buf, "aaa", null); - // assertEquals("(title:aaa OR content:aaa)", buf.toString()); - // - // buf = new StringBuilder(); - // queryHelper.buildContentQueryWithLang(buf, "aaa", "ja"); - // assertEquals("(title:aaa OR content:aaa OR content_ja:aaa)", buf.toString()); - // - // buf = new StringBuilder(); - // queryHelper.buildContentQueryWithLang(buf, "aaa", "zh_CN"); - // assertEquals("(title:aaa OR content:aaa OR content_zh_CN:aaa)", buf.toString()); - // } - // - // public void test_getQueryLanguage() { - // assertNull(queryHelper.getQueryLanguage()); - // final MockletHttpServletRequest request = getMockRequest(); - // request.setLocale(Locale.JAPAN); - // assertEquals("ja", queryHelper.getQueryLanguage()); - // request.setLocale(Locale.SIMPLIFIED_CHINESE); - // assertEquals("zh_CN", queryHelper.getQueryLanguage()); - // queryHelper.addFieldLanguage("zh_CN", "cjk"); - // assertEquals("cjk", queryHelper.getQueryLanguage()); - // request.setLocale(Locale.CHINESE); - // assertEquals("zh", queryHelper.getQueryLanguage()); - // request.setLocale(Locale.CANADA_FRENCH); - // assertEquals("fr", queryHelper.getQueryLanguage()); - // request.setLocale(new Locale("aa")); - // assertNull(queryHelper.getQueryLanguage()); - // } - // - // public void test_buildWithLang() { - // final MockletHttpServletRequest request = getMockRequest(); - // request.setLocale(Locale.JAPAN); - // - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("", queryHelper.buildQuery("").getQuery()); - // - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY", queryHelper.buildQuery("QUERY").getQuery()); - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY", queryHelper.buildQuery("QUERY ").getQuery()); - // assertEquals("title:QUERY OR content:QUERY OR content_ja:QUERY", queryHelper.buildQuery(" QUERY").getQuery()); - // - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1) " + op - // + " NOT (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("QUERY1 NOT QUERY2").getQuery()); - // - // assertEquals("(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", queryHelper.buildQuery("QUERY1 QUERY2").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery("QUERY1 QUERY2 ").getQuery()); - // assertEquals( - // "(title:QUERY1 OR content:QUERY1 OR content_ja:QUERY1) " + op - // + " (title:QUERY2 OR content:QUERY2 OR content_ja:QUERY2)", - // queryHelper.buildQuery(" QUERY1 QUERY2").getQuery()); - // } - // } - // - // public void test_unbracketQuery() { - // assertEquals("", queryHelper.unbracketQuery("")); - // assertEquals("", queryHelper.unbracketQuery("()")); - // assertEquals("", queryHelper.unbracketQuery("(())")); - // assertEquals("()()", queryHelper.unbracketQuery("()()")); - // assertEquals("()()", queryHelper.unbracketQuery("(()())")); - // assertEquals("()()()", queryHelper.unbracketQuery("()()()")); - // assertEquals("()(()())", queryHelper.unbracketQuery("()(()())")); - // - // assertEquals("(", queryHelper.unbracketQuery("(")); - // assertEquals(")", queryHelper.unbracketQuery(")")); - // assertEquals("()(", queryHelper.unbracketQuery("()(")); - // assertEquals("())", queryHelper.unbracketQuery("())")); - // assertEquals(")()", queryHelper.unbracketQuery(")()")); - // assertEquals("(()", queryHelper.unbracketQuery("(()")); - // - // assertEquals("\\(", queryHelper.unbracketQuery("(\\()")); - // assertEquals("\\)", queryHelper.unbracketQuery("(\\))")); - // assertEquals("(\\\\()", queryHelper.unbracketQuery("(\\\\()")); - // assertEquals("(\\\\))", queryHelper.unbracketQuery("(\\\\))")); - // assertEquals("\\\\\\(", queryHelper.unbracketQuery("(\\\\\\()")); - // assertEquals("\\\\\\)", queryHelper.unbracketQuery("(\\\\\\))")); - // } - // - // public void test_appendRangeQueryValue() { - // StringBuilder buf = new StringBuilder(); - // queryHelper.appendRangeQueryValue(buf, "[1 TO 2]", '[', ']'); - // assertEquals("[1 TO 2]", buf.toString()); - // - // buf = new StringBuilder(); - // queryHelper.appendRangeQueryValue(buf, "[1234 TO 2345]", '[', ']'); - // assertEquals("[1234 TO 2345]", buf.toString()); - // - // buf = new StringBuilder(); - // queryHelper.appendRangeQueryValue(buf, "[* TO 2345]", '[', ']'); - // assertEquals("[* TO 2345]", buf.toString()); - // - // buf = new StringBuilder(); - // queryHelper.appendRangeQueryValue(buf, "[1234 TO *]", '[', ']'); - // assertEquals("[1234 TO *]", buf.toString()); - // - // buf = new StringBuilder(); - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[* TO *]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[1]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[1 TO]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[1 TO ]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[TO 1]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // - // try { - // queryHelper.appendRangeQueryValue(buf, "[ TO 1]", '[', ']'); - // fail(); - // } catch (final InvalidQueryException e) {} - // } - // - // public void test_inurl() { - // for (final String op : new String[] { "AND", "OR" }) { - // getMockRequest().setAttribute(Constants.DEFAULT_OPERATOR, op); - // assertEquals("url:*QUERY*", queryHelper.buildQuery("inurl:QUERY").getQuery()); - // assertEquals("url:*QUERY1* " + op + " url:*QUERY2*", queryHelper.buildQuery("inurl:QUERY1 inurl:QUERY2").getQuery()); - // assertEquals("(title:aaa OR content:aaa) " + op + " url:*QUERY1* " + op + " url:*QUERY2*", - // queryHelper.buildQuery("aaa inurl:QUERY1 inurl:QUERY2").getQuery()); - // assertEquals("url:*QUERY*", queryHelper.buildQuery("inurl:\"QUERY\"").getQuery()); - // } - // } - // - // public void test_buildOptionQuery() { - // final Map options = new HashMap<>(); - // - // assertEquals("", queryHelper.buildOptionQuery(null)); - // assertEquals("", queryHelper.buildOptionQuery(options)); - // - // // Q - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "a" }); - // assertEquals("a", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "a b" }); - // assertEquals("a b", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "a b c" }); - // assertEquals("a b c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "\"a b\"" }); - // assertEquals("\"a b\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "\"a b\" c" }); - // assertEquals("\"a b\" c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "\"a b\" \"c d\"" }); - // assertEquals("\"a b\" \"c d\"", queryHelper.buildOptionQuery(options)); - // - // // CQ - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "a" }); - // assertEquals("\"a\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "a b" }); - // assertEquals("\"a b\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "a b c" }); - // assertEquals("\"a b c\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "\"a b\"" }); - // assertEquals("\"a b\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "\"a b\" c" }); - // assertEquals("\"a b\" \"c\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "\"a b\" \"c d\"" }); - // assertEquals("\"a b\" \"c d\"", queryHelper.buildOptionQuery(options)); - // - // // OQ - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "a" }); - // assertEquals("a", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "a b" }); - // assertEquals("a OR b", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "a b c" }); - // assertEquals("a OR b OR c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "\"a b\"" }); - // assertEquals("\"a b\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "\"a b\" c" }); - // assertEquals("\"a b\" OR c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "\"a b\" \"c d\"" }); - // assertEquals("\"a b\" OR \"c d\"", queryHelper.buildOptionQuery(options)); - // - // // NQ - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "a" }); - // assertEquals("NOT a", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "a b" }); - // assertEquals("NOT a NOT b", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "a b c" }); - // assertEquals("NOT a NOT b NOT c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "\"a b\"" }); - // assertEquals("NOT \"a b\"", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "\"a b\" c" }); - // assertEquals("NOT \"a b\" NOT c", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "\"a b\" \"c d\"" }); - // assertEquals("NOT \"a b\" NOT \"c d\"", queryHelper.buildOptionQuery(options)); - // - // // combine - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "a" }); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "b" }); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "c" }); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "d" }); - // assertEquals("a \"b\" c NOT d", queryHelper.buildOptionQuery(options)); - // - // options.clear(); - // options.put(Constants.OPTION_QUERY_Q, new String[] { "a 1" }); - // options.put(Constants.OPTION_QUERY_CQ, new String[] { "b 2" }); - // options.put(Constants.OPTION_QUERY_OQ, new String[] { "c 3" }); - // options.put(Constants.OPTION_QUERY_NQ, new String[] { "d 4" }); - // assertEquals("a 1 \"b 2\" (c OR 3) NOT d NOT 4", queryHelper.buildOptionQuery(options)); - // } - // - // private void assertExceptionOnFacetQuery(final String format, final String query, final String messageCode) { - // try { - // final String ret = queryHelper.buildFacetQuery(String.format(format, query)); - // fail("format: " + format + ", query: " + query + ", ret: " + ret); - // } catch (final InvalidQueryException e) { - // FessMessages messages = new FessMessages(); - // e.getMessageCode().message(messages); - // if (!messages.hasMessageOf(UserMessages.GLOBAL_PROPERTY_KEY, messageCode)) { - // throw e; - // } - // } - // } - // - // public void test_getQueryParamMap() { - // assertEquals(0, queryHelper.getQueryParamMap().size()); - // - // Map queryParamMap; - // - // queryHelper.addQueryParam("aaa", new String[] { "111" }); - // queryHelper.addQueryParam("bbb", new String[] { "222", "$333" }); - // queryParamMap = queryHelper.getQueryParamMap(); - // assertEquals(2, queryParamMap.size()); - // assertEquals(1, queryParamMap.get("aaa").length); - // assertEquals("111", queryParamMap.get("aaa")[0]); - // assertEquals(2, queryParamMap.get("bbb").length); - // assertEquals("222", queryParamMap.get("bbb")[0]); - // assertEquals("", queryParamMap.get("bbb")[1]); - // - // getMockRequest().setParameter("333", "AAA"); - // queryParamMap = queryHelper.getQueryParamMap(); - // assertEquals(2, queryParamMap.size()); - // assertEquals(1, queryParamMap.get("aaa").length); - // assertEquals("111", queryParamMap.get("aaa")[0]); - // assertEquals(2, queryParamMap.get("bbb").length); - // assertEquals("222", queryParamMap.get("bbb")[0]); - // assertEquals("AAA", queryParamMap.get("bbb")[1]); - // - // } - } \ No newline at end of file