forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-11:Gfsh command for lucene query
Added a gfsh command to execute a basic search operation on the lucene index. Added junit and dunit tests to verify. This closes apache#213
- Loading branch information
1 parent
3f6acdc
commit 603bae8
Showing
8 changed files
with
481 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/cli/LuceneQueryInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.gemstone.gemfire.cache.lucene.internal.cli; | ||
|
||
import java.io.Serializable; | ||
|
||
public class LuceneQueryInfo implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private String indexName; | ||
private String regionPath; | ||
private String queryString; | ||
private String defaultField; | ||
|
||
public LuceneQueryInfo(final String indexName, | ||
final String regionPath, | ||
final String queryString, | ||
final String defaultField) | ||
{ | ||
this.indexName = indexName; | ||
this.regionPath = regionPath; | ||
this.queryString = queryString; | ||
this.defaultField = defaultField; | ||
} | ||
|
||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
public String getRegionPath() { | ||
return regionPath; | ||
} | ||
|
||
public String getQueryString() { | ||
return queryString; | ||
} | ||
|
||
public String getDefaultField() { | ||
return defaultField; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/cli/LuceneSearchResults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.gemstone.gemfire.cache.lucene.internal.cli; | ||
|
||
import java.io.Serializable; | ||
|
||
public class LuceneSearchResults<K,V> implements Comparable<LuceneSearchResults>, Serializable { | ||
|
||
private String key; | ||
private String value; | ||
private float score; | ||
|
||
public LuceneSearchResults(final String key, final String value, final float score) { | ||
this.key = key; | ||
this.value = value; | ||
this.score = score; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public float getScore() { | ||
return score; | ||
} | ||
|
||
@Override | ||
public int compareTo(final LuceneSearchResults searchResults) { | ||
return getScore() < searchResults.getScore() ? -1 : 1; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...a/com/gemstone/gemfire/cache/lucene/internal/cli/functions/LuceneSearchIndexFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.gemstone.gemfire.cache.lucene.internal.cli.functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import com.gemstone.gemfire.cache.Cache; | ||
import com.gemstone.gemfire.cache.CacheFactory; | ||
import com.gemstone.gemfire.cache.execute.FunctionAdapter; | ||
import com.gemstone.gemfire.cache.execute.FunctionContext; | ||
import com.gemstone.gemfire.cache.lucene.LuceneQuery; | ||
import com.gemstone.gemfire.cache.lucene.LuceneQueryException; | ||
import com.gemstone.gemfire.cache.lucene.LuceneResultStruct; | ||
import com.gemstone.gemfire.cache.lucene.LuceneService; | ||
import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider; | ||
import com.gemstone.gemfire.cache.lucene.PageableLuceneQueryResults; | ||
import com.gemstone.gemfire.cache.lucene.internal.cli.LuceneIndexDetails; | ||
import com.gemstone.gemfire.cache.lucene.internal.cli.LuceneIndexInfo; | ||
import com.gemstone.gemfire.cache.lucene.internal.cli.LuceneQueryInfo; | ||
import com.gemstone.gemfire.cache.lucene.internal.cli.LuceneSearchResults; | ||
import com.gemstone.gemfire.cache.query.RegionNotFoundException; | ||
import com.gemstone.gemfire.internal.InternalEntity; | ||
|
||
/** | ||
* The LuceneSearchIndexFunction class is a function used to collect the information on a particular lucene index. | ||
* </p> | ||
* @see Cache | ||
* @see com.gemstone.gemfire.cache.execute.Function | ||
* @see FunctionAdapter | ||
* @see FunctionContext | ||
* @see InternalEntity | ||
* @see LuceneIndexDetails | ||
* @see LuceneIndexInfo | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class LuceneSearchIndexFunction<K,V> extends FunctionAdapter implements InternalEntity { | ||
|
||
protected Cache getCache() { | ||
return CacheFactory.getAnyInstance(); | ||
} | ||
|
||
public String getId() { | ||
return LuceneSearchIndexFunction.class.getName(); | ||
} | ||
|
||
public void execute(final FunctionContext context) { | ||
|
||
Set<LuceneSearchResults> result=new HashSet<>(); | ||
final Cache cache = getCache(); | ||
final LuceneQueryInfo queryInfo = (LuceneQueryInfo) context.getArguments(); | ||
|
||
LuceneService luceneService = LuceneServiceProvider.get(getCache()); | ||
try { | ||
if (cache.getRegion(queryInfo.getRegionPath())!=null) { | ||
final LuceneQuery<K, V> query = luceneService.createLuceneQueryFactory().create( | ||
queryInfo.getIndexName(), queryInfo.getRegionPath(), queryInfo.getQueryString(), queryInfo.getDefaultField()); | ||
PageableLuceneQueryResults pageableLuceneQueryResults = query.findPages(); | ||
while (pageableLuceneQueryResults.hasNext()) { | ||
List<LuceneResultStruct> page = pageableLuceneQueryResults.next(); | ||
page.stream() | ||
.forEach(searchResult -> | ||
result.add(new LuceneSearchResults<K,V>(searchResult.getKey().toString(),searchResult.getValue().toString(),searchResult.getScore()))); | ||
} | ||
} | ||
context.getResultSender().lastResult(result); | ||
} | ||
catch (LuceneQueryException e) { | ||
context.getResultSender().lastResult(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.