Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Use text flow id index for excluding option in tm search
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Apr 15, 2014
1 parent 3f6d381 commit 997dd5b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
@@ -0,0 +1,58 @@
/*
* Copyright 2014, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.hibernate.search;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.search.bridge.TwoWayStringBridge;
import org.zanata.common.ContentState;

public class DateBridge implements TwoWayStringBridge {

private final static String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";

private final SimpleDateFormat dateFormat = new SimpleDateFormat(
DATE_FORMAT);

@Override
public String objectToString(Object value) {
if (value instanceof Date) {
Date date = (Date) value;
return dateFormat.format(date);
} else {
throw new IllegalArgumentException(
"DateBridge used on a non-Date type: " + value.getClass());
}
}

@Override
public Object stringToObject(String date) {
try {
return dateFormat.parse(date);
} catch (ParseException e) {
throw new IllegalArgumentException(
"DateBridge used on invalid date format: " + date);
}
}

}
Expand Up @@ -17,6 +17,7 @@ public interface IndexFieldLabels {
public static final String DOCUMENT_ID_FIELD = "documentId";
public static final String LOCALE_ID_FIELD = "locale";
public static final String CONTENT_STATE_FIELD = "state";
public static final String LAST_CHANGE_FIELD = "lastChanged";

public static final String TF_CONTENT = "textFlow.content-nocase";
public static final String CONTENT = "content-nocase";
Expand Down
15 changes: 14 additions & 1 deletion zanata-model/src/main/java/org/zanata/model/HTextFlowTarget.java
Expand Up @@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -42,6 +43,8 @@
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

Expand All @@ -65,6 +68,7 @@
import org.zanata.common.HasContents;
import org.zanata.common.LocaleId;
import org.zanata.hibernate.search.ContentStateBridge;
import org.zanata.hibernate.search.DateBridge;
import org.zanata.hibernate.search.IndexFieldLabels;
import org.zanata.hibernate.search.LocaleIdBridge;
import org.zanata.hibernate.search.StringListBridge;
Expand All @@ -83,7 +87,7 @@
*
*/
@Entity
@EntityListeners({HTextFlowTarget.EntityListener.class})
@EntityListeners({ HTextFlowTarget.EntityListener.class })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed
@Setter
Expand Down Expand Up @@ -207,6 +211,15 @@ HTextFlow getTextFlow() {
return textFlow;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
@Field(analyze = Analyze.NO)
@FieldBridge(impl = DateBridge.class)
@Override
public Date getLastChanged() {
return super.getLastChanged();
}

/**
* As of release 1.6, replaced by {@link #getContents()}
*
Expand Down
Expand Up @@ -64,10 +64,10 @@ public class CopyTransServiceImpl implements CopyTransService {
* Copies previous matching translations for the given locale into a
* document. Translations are matching if their document id, textflow id and
* source content are identical, and their state is approved.
*
*
* The text flow revision for copied targets is set to the current text flow
* revision.
*
*
* @param document
* the document to copy translations into
* @param targetLocale
Expand Down Expand Up @@ -102,7 +102,7 @@ private void copyTransForDocumentLocale(HDocument document,

/**
* Perform copy trans on a batch of text flows for a document.
*
*
* @param batchStart
* USE_HIBERNATE_SEARCH The text flow position to start copying.
* @param batchLength
Expand Down
Expand Up @@ -115,7 +115,7 @@ public class TranslationMemoryServiceImpl implements TranslationMemoryService {
/**
* This is used by CopyTrans, with ContentHash search in lucene. Returns
* first entry of the matches which sort by HTextFlowTarget.lastChanged DESC
*
*
* @param textFlow
* @param targetLocaleId
* @param sourceLocaleId
Expand Down Expand Up @@ -156,7 +156,7 @@ public int compare(Object[] o1, Object[] o2) {
/**
* This is used by TMMerge. Returns first entry of the matches which sort by
* similarityPercent, sourceContents, and contents size.
*
*
* @param textFlow
* @param targetLocaleId
* @param sourceLocaleId
Expand Down Expand Up @@ -247,7 +247,7 @@ private TransMemoryQuery buildTMQuery(HTextFlow textFlow,
/**
* return match[0] = (float)score, match[1] = entity(HTextFlowTarget or
* TransMemoryUnit)
*
*
* @param targetLocaleId
* @param sourceLocaleId
* @param transMemoryQuery
Expand Down Expand Up @@ -544,7 +544,7 @@ private List<Object[]> getSearchResult(TransMemoryQuery query,
/**
* Generate the query to match all source contents in all the searchable
* indexes. (HTextFlowTarget and TransMemoryUnit)
*
*
* @param query
* @param sourceLocale
* @param targetLocale
Expand Down Expand Up @@ -578,7 +578,7 @@ private Query generateQuery(TransMemoryQuery query, LocaleId sourceLocale,
/**
* Generates the Hibernate Search Query that will search for
* {@link HTextFlowTarget} objects for matches.
*
*
* @param queryParams
* @param sourceLocale
* @param targetLocale
Expand Down Expand Up @@ -626,7 +626,7 @@ private Query generateTextFlowTargetQuery(TransMemoryQuery queryParams,

/**
* Build query for project, document and resId context
*
*
* @param queryParams
* @return
*/
Expand Down Expand Up @@ -709,7 +709,7 @@ private static TermQuery buildStateQuery(ContentState state) {
/**
* Generates the Hibernate Search Query that will search for
* {@link org.zanata.model.tm.TransMemoryUnit} objects for matches.
*
*
* @param sourceLocale
* @param targetLocale
* @param queryText
Expand Down Expand Up @@ -740,7 +740,7 @@ private Query generateTransMemoryQuery(LocaleId sourceLocale,
/**
* Joins a given set of queries into a single one with the specified
* occurrence condition.
*
*
* @param condition
* The occurrence condition all the joined queries will have.
* @param queries
Expand Down
Expand Up @@ -31,7 +31,7 @@
/**
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*
*/
public class TransMemoryQuery implements IsSerializable {
private SearchType searchType;
Expand Down

0 comments on commit 997dd5b

Please sign in to comment.