- minor fixes post-refactoring

- improve regex result filtering
This commit is contained in:
adam-m 2012-01-03 15:51:40 -05:00
parent ee588d2018
commit 529afce917
4 changed files with 32 additions and 29 deletions

View File

@ -177,17 +177,11 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
//use Lucene query to get files with regular expression match result //use Lucene query to get files with regular expression match result
final String keywordQuery = thing.getName(); final String keywordQuery = thing.getName();
LuceneQuery filesQuery = new LuceneQuery(keywordQuery); LuceneQuery filesQuery = new LuceneQuery(keywordQuery);
filesQuery.escape();
List<FsContent> matches = filesQuery.performQuery(); List<FsContent> matches = filesQuery.performQuery();
//get unique match result files //get unique match result files
Set<FsContent> uniqueMatches = new TreeSet<FsContent>(new Comparator<FsContent>() { Set<FsContent> uniqueMatches = new TreeSet<FsContent>();
@Override
public int compare(FsContent fsc1, FsContent fsc2) {
return (int) (fsc1.getId() - fsc2.getId());
}
});
uniqueMatches.addAll(matches); uniqueMatches.addAll(matches);
int resID = 0; int resID = 0;
@ -212,8 +206,14 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
//TODO option in GUI to include approximate matches (faster) //TODO option in GUI to include approximate matches (faster)
boolean matchFound = false; boolean matchFound = false;
if (contentStr != null) {//if not null, some error getting from Solr, handle it by not filtering out if (contentStr != null) {//if not null, some error getting from Solr, handle it by not filtering out
final String keywordQuery = thing.getName(); //perform java regex to validate match from Solr
Pattern p = Pattern.compile(keywordQuery, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); String origQuery = thingContent.getQuery();
//escape the regex query because it may contain special characters from the previous match
//since it's a match result, we can assume literal pattern
origQuery = Pattern.quote(origQuery);
Pattern p = Pattern.compile(origQuery, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(contentStr); Matcher m = p.matcher(contentStr);
matchFound = m.find(); matchFound = m.find();
} }

View File

@ -1,10 +1,7 @@
<?xml version="1.1" encoding="UTF-8" ?> <?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="buttonGroup1">
</Component>
</NonVisualComponents>
<AuxValues> <AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
@ -23,20 +20,24 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="queryLabel" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/> <Group type="102" attributes="0">
<Component id="chRegex" min="-2" max="-2" attributes="0"/> <Component id="queryLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="50" max="-2" attributes="0"/>
<Component id="chRegex" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane1" alignment="0" pref="599" max="32767" attributes="0"/>
<Component id="searchButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group> </Group>
<Component id="jScrollPane1" alignment="0" pref="599" max="32767" attributes="0"/>
<Component id="searchButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="filesIndexedNameLabel" min="-2" max="-2" attributes="0"/> <Component id="filesIndexedNameLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="filesIndexedValLabel" min="-2" max="-2" attributes="0"/> <Component id="filesIndexedValLabel" min="-2" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>

View File

@ -30,7 +30,6 @@ public class KeywordSearchSimpleTopComponent extends TopComponent implements Key
public KeywordSearchSimpleTopComponent() { public KeywordSearchSimpleTopComponent() {
initComponents(); initComponents();
setName("Simple"); setName("Simple");
buttonGroup1.add(chRegex);
searchButton.setEnabled(false); searchButton.setEnabled(false);
putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE); putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
@ -81,16 +80,18 @@ public class KeywordSearchSimpleTopComponent extends TopComponent implements Key
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(queryLabel) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(62, 62, 62) .addGroup(layout.createSequentialGroup()
.addComponent(chRegex)) .addComponent(queryLabel)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE) .addGap(50, 50, 50)
.addComponent(searchButton) .addComponent(chRegex))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE)
.addComponent(searchButton))
.addContainerGap())
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(filesIndexedNameLabel) .addComponent(filesIndexedNameLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(filesIndexedValLabel))) .addComponent(filesIndexedValLabel))))
.addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

View File

@ -66,6 +66,7 @@ public class LuceneQuery implements KeywordSearchQuery {
* @param query * @param query
* @return matches List * @return matches List
*/ */
@Override
public List<FsContent> performQuery() throws RuntimeException { public List<FsContent> performQuery() throws RuntimeException {
List<FsContent> matches = new ArrayList<FsContent>(); List<FsContent> matches = new ArrayList<FsContent>();