Work on test indexing
This commit is contained in:
parent
8ed9ca83af
commit
67eb06665e
|
@ -40,7 +40,7 @@ abstract class BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getQueryParameterQualifier() {
|
public final String getQueryParameterQualifier() {
|
||||||
if (myMissing != null) {
|
if (myMissing != null && myMissing.booleanValue()) {
|
||||||
return Constants.PARAMQUALIFIER_MISSING;
|
return Constants.PARAMQUALIFIER_MISSING;
|
||||||
}
|
}
|
||||||
return doGetQueryParameterQualifier();
|
return doGetQueryParameterQualifier();
|
||||||
|
|
|
@ -19,8 +19,7 @@ package ca.uhn.fhir.rest.param;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||||
import static org.apache.commons.lang3.StringUtils.*;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
@ -34,6 +33,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
private boolean myExact;
|
private boolean myExact;
|
||||||
private String myValue;
|
private String myValue;
|
||||||
|
private boolean myContains;
|
||||||
|
|
||||||
public StringParam() {
|
public StringParam() {
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
String doGetQueryParameterQualifier() {
|
String doGetQueryParameterQualifier() {
|
||||||
if (isExact()) {
|
if (isExact()) {
|
||||||
return Constants.PARAMQUALIFIER_STRING_EXACT;
|
return Constants.PARAMQUALIFIER_STRING_EXACT;
|
||||||
|
} else if (isContains()) {
|
||||||
|
return Constants.PARAMQUALIFIER_STRING_CONTAINS;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -68,6 +70,11 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
} else {
|
} else {
|
||||||
setExact(false);
|
setExact(false);
|
||||||
}
|
}
|
||||||
|
if (Constants.PARAMQUALIFIER_STRING_CONTAINS.equals(theQualifier)) {
|
||||||
|
setContains(true);
|
||||||
|
} else {
|
||||||
|
setContains(false);
|
||||||
|
}
|
||||||
myValue = ParameterUtil.unescape(theValue);
|
myValue = ParameterUtil.unescape(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +98,25 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
return myExact;
|
return myExact;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExact(boolean theExact) {
|
public StringParam setExact(boolean theExact) {
|
||||||
myExact = theExact;
|
myExact = theExact;
|
||||||
|
if (myExact) {
|
||||||
|
setContains(false);
|
||||||
|
setMissing(null);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String theValue) {
|
/**
|
||||||
|
* String parameter modifier <code>:contains</code>
|
||||||
|
*/
|
||||||
|
public boolean isContains() {
|
||||||
|
return myContains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringParam setValue(String theValue) {
|
||||||
myValue = theValue;
|
myValue = theValue;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,10 +126,25 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
if (myExact) {
|
if (myExact) {
|
||||||
builder.append("exact", myExact);
|
builder.append("exact", myExact);
|
||||||
}
|
}
|
||||||
|
if (myContains) {
|
||||||
|
builder.append("contains", myContains);
|
||||||
|
}
|
||||||
if (getMissing() != null) {
|
if (getMissing() != null) {
|
||||||
builder.append("missing", getMissing().booleanValue());
|
builder.append("missing", getMissing().booleanValue());
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String parameter modifier <code>:contains</code>
|
||||||
|
*/
|
||||||
|
public StringParam setContains(boolean theContains) {
|
||||||
|
myContains = theContains;
|
||||||
|
if (myContains) {
|
||||||
|
setExact(false);
|
||||||
|
setMissing(null);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class Constants {
|
||||||
public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
|
public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
|
||||||
public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
|
public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
|
||||||
public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
|
public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
|
||||||
|
public static final String PARAMQUALIFIER_STRING_CONTAINS = ":contains";
|
||||||
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
|
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
|
||||||
public static final int STATUS_HTTP_200_OK = 200;
|
public static final int STATUS_HTTP_200_OK = 200;
|
||||||
public static final int STATUS_HTTP_201_CREATED = 201;
|
public static final int STATUS_HTTP_201_CREATED = 201;
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class FhirSearchDao extends BaseHapiFhirDao<IBaseResource> implements ISe
|
||||||
for (List<? extends IQueryParameterType> nextAndList : theParams.get(nextParamName)) {
|
for (List<? extends IQueryParameterType> nextAndList : theParams.get(nextParamName)) {
|
||||||
for (Iterator<? extends IQueryParameterType> orIterator = nextAndList.iterator(); orIterator.hasNext();) {
|
for (Iterator<? extends IQueryParameterType> orIterator = nextAndList.iterator(); orIterator.hasNext();) {
|
||||||
IQueryParameterType nextParam = orIterator.next();
|
IQueryParameterType nextParam = orIterator.next();
|
||||||
if (nextParam instanceof TokenParam && false) {
|
if (nextParam instanceof TokenParam) {
|
||||||
TokenParam nextTokenParam = (TokenParam) nextParam;
|
TokenParam nextTokenParam = (TokenParam) nextParam;
|
||||||
if (nextTokenParam.isText()) {
|
if (nextTokenParam.isText()) {
|
||||||
orIterator.remove();
|
orIterator.remove();
|
||||||
|
@ -112,27 +112,26 @@ public class FhirSearchDao extends BaseHapiFhirDao<IBaseResource> implements ISe
|
||||||
if (isNotBlank(theResourceName)) {
|
if (isNotBlank(theResourceName)) {
|
||||||
bool.must(qb.keyword().onField("myResourceType").matching(theResourceName).createQuery());
|
bool.must(qb.keyword().onField("myResourceType").matching(theResourceName).createQuery());
|
||||||
}
|
}
|
||||||
|
//
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
|
String value = nextTokenParam.getValue().toLowerCase();
|
||||||
Query textQuery = qb
|
Query textQuery = qb
|
||||||
.phrase()
|
.phrase()
|
||||||
.withSlop(2)
|
.withSlop(2)
|
||||||
.onField("myValueText").boostedTo(4.0f)
|
.onField("myValueText").boostedTo(4.0f)
|
||||||
.andField("myValueTextEdgeNGram").boostedTo(2.0f)
|
.andField("myValueTextEdgeNGram").boostedTo(2.0f)
|
||||||
.andField("myValueTextNGram").boostedTo(1.0f)
|
// .andField("myValueTextNGram").boostedTo(1.0f)
|
||||||
.sentence(nextTokenParam.getValue().toLowerCase()).createQuery();
|
.sentence(value).createQuery();
|
||||||
bool.must(textQuery);
|
bool.must(textQuery);
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
FullTextQuery ftq = em.createFullTextQuery(bool.createQuery(), ResourceTable.class);
|
FullTextQuery ftq = em.createFullTextQuery(bool.createQuery(), ResourceIndexedSearchParamString.class);
|
||||||
ftq.setProjection("myResourcePid");
|
|
||||||
|
|
||||||
List<?> resultList = ftq.getResultList();
|
List<?> resultList = ftq.getResultList();
|
||||||
pids = new ArrayList<Long>();
|
pids = new ArrayList<Long>();
|
||||||
for (Object next : resultList) {
|
for (Object next : resultList) {
|
||||||
Object[] nextAsArray = (Object[]) next;
|
ResourceIndexedSearchParamString nextAsArray = (ResourceIndexedSearchParamString) next;
|
||||||
Long nextValue = (Long) nextAsArray[0];
|
pids.add(nextAsArray.getResourcePid());
|
||||||
pids.add(nextValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,20 +47,19 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
|
||||||
private Long myId;
|
private Long myId;
|
||||||
|
|
||||||
@Field
|
@Field
|
||||||
@Column(name = "SP_NAME", length = MAX_SP_NAME, nullable=false)
|
@Column(name = "SP_NAME", length = MAX_SP_NAME, nullable = false)
|
||||||
private String myParamName;
|
private String myParamName;
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(name = "RES_ID", referencedColumnName="RES_ID")
|
@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID")
|
||||||
@ContainedIn
|
@ContainedIn
|
||||||
private ResourceTable myResource;
|
private ResourceTable myResource;
|
||||||
|
|
||||||
@Field(store=Store.YES)
|
|
||||||
@Column(name = "RES_ID", insertable = false, updatable = false)
|
@Column(name = "RES_ID", insertable = false, updatable = false)
|
||||||
private Long myResourcePid;
|
private Long myResourcePid;
|
||||||
|
|
||||||
@Field(store=Store.YES)
|
@Field()
|
||||||
@Column(name = "RES_TYPE", nullable=false)
|
@Column(name = "RES_TYPE", nullable = false)
|
||||||
private String myResourceType;
|
private String myResourceType;
|
||||||
|
|
||||||
protected Long getId() {
|
protected Long getId() {
|
||||||
|
@ -75,6 +74,10 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
|
||||||
return myResource;
|
return myResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getResourcePid() {
|
||||||
|
return myResourcePid;
|
||||||
|
}
|
||||||
|
|
||||||
public void setParamName(String theName) {
|
public void setParamName(String theName) {
|
||||||
myParamName = theName;
|
myParamName = theName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,4 +201,5 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
|
||||||
b.append("value", getValueNormalized());
|
b.append("value", getValueNormalized());
|
||||||
return b.build();
|
return b.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,7 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest {
|
||||||
public void beforeFlushFT() {
|
public void beforeFlushFT() {
|
||||||
FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager);
|
FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager);
|
||||||
ftem.purgeAll(ResourceTable.class);
|
ftem.purgeAll(ResourceTable.class);
|
||||||
|
ftem.purgeAll(ResourceIndexedSearchParamString.class);
|
||||||
ftem.flushToIndexes();
|
ftem.flushToIndexes();
|
||||||
|
|
||||||
myDaoConfig.setSchedulingDisabled(true);
|
myDaoConfig.setSchedulingDisabled(true);
|
||||||
|
|
|
@ -185,6 +185,7 @@ public abstract class BaseJpaDstu21Test extends BaseJpaTest {
|
||||||
public void beforeFlushFT() {
|
public void beforeFlushFT() {
|
||||||
FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager);
|
FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager);
|
||||||
ftem.purgeAll(ResourceTable.class);
|
ftem.purgeAll(ResourceTable.class);
|
||||||
|
ftem.purgeAll(ResourceIndexedSearchParamString.class);
|
||||||
ftem.flushToIndexes();
|
ftem.flushToIndexes();
|
||||||
|
|
||||||
myDaoConfig.setSchedulingDisabled(true);
|
myDaoConfig.setSchedulingDisabled(true);
|
||||||
|
|
|
@ -38,12 +38,12 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu21SearchFtTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu21SearchFtTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testCodeTextSearch() {
|
public void testCodeTextSearch() {
|
||||||
Observation obs1 = new Observation();
|
Observation obs1 = new Observation();
|
||||||
obs1.getCode().setText("Systolic Blood Pressure");
|
obs1.getCode().setText("Systolic Blood Pressure");
|
||||||
obs1.setStatus(ObservationStatusEnum.FINAL);
|
obs1.setStatus(ObservationStatusEnum.FINAL);
|
||||||
obs1.setValue(new QuantityDt(123));
|
obs1.setValue(new QuantityDt(123));
|
||||||
|
obs1.setComments("obs1");
|
||||||
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
|
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
Observation obs2 = new Observation();
|
Observation obs2 = new Observation();
|
||||||
|
@ -55,11 +55,44 @@ public class FhirResourceDaoDstu21SearchFtTest extends BaseJpaDstu21Test {
|
||||||
SearchParameterMap map;
|
SearchParameterMap map;
|
||||||
|
|
||||||
map = new SearchParameterMap();
|
map = new SearchParameterMap();
|
||||||
map.add(Observation.SP_CODE, new TokenParam(null, "Systolic").setText(true));
|
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
|
||||||
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1, id2));
|
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1, id2));
|
||||||
|
|
||||||
|
map = new SearchParameterMap();
|
||||||
|
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
|
||||||
|
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), empty());
|
||||||
|
|
||||||
|
map = new SearchParameterMap();
|
||||||
|
map.add(Observation.SP_CODE, new TokenParam(null, "blood").setText(true));
|
||||||
|
map.add(Constants.PARAM_CONTENT, new StringParam("obs1"));
|
||||||
|
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void testStringTextSearch() {
|
||||||
|
Observation obs1 = new Observation();
|
||||||
|
obs1.getCode().setText("AAAAA");
|
||||||
|
obs1.setValue(new StringDt("Systolic Blood Pressure"));
|
||||||
|
obs1.setStatus(ObservationStatusEnum.FINAL);
|
||||||
|
IIdType id1 = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
Observation obs2 = new Observation();
|
||||||
|
obs1.getCode().setText("AAAAA");
|
||||||
|
obs1.setValue(new StringDt("Diastolic Blood Pressure"));
|
||||||
|
obs2.setStatus(ObservationStatusEnum.FINAL);
|
||||||
|
IIdType id2 = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
SearchParameterMap map;
|
||||||
|
|
||||||
|
map = new SearchParameterMap();
|
||||||
|
map.add(Observation.SP_VALUE_STRING, new StringParam("sure").setContains(true));
|
||||||
|
assertThat(toUnqualifiedVersionlessIds(myObservationDao.search(map)), containsInAnyOrder(id1, id2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestIgnoresBase64Content() {
|
public void testSuggestIgnoresBase64Content() {
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
|
|
|
@ -36,6 +36,18 @@ public class StringParameterTest {
|
||||||
|
|
||||||
private static Server ourServer;
|
private static Server ourServer;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContains() {
|
||||||
|
StringParam sp = new StringParam("VAL");
|
||||||
|
sp.setContains(true);
|
||||||
|
assertEquals(":contains", sp.getQueryParameterQualifier());
|
||||||
|
|
||||||
|
sp = new StringParam("VAL");
|
||||||
|
sp.setValueAsQueryToken(":contains", "VAL");
|
||||||
|
assertEquals(true, sp.isContains());
|
||||||
|
assertEquals("VAL", sp.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRawString() throws Exception {
|
public void testRawString() throws Exception {
|
||||||
{
|
{
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -742,7 +742,7 @@
|
||||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||||
<runOrder>random</runOrder>
|
<runOrder>random</runOrder>
|
||||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||||
<reuseForks>false</reuseForks>
|
<!--<reuseForks>false</reuseForks>-->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
Loading…
Reference in New Issue