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

BZ-1232000: if lucene parser returns an empty query - we use widlcard to #123

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private Query buildQuery( final String term,
Query fullText;
try {
fullText = queryParser.parse( term );
if ( fullText.toString().isEmpty() ) {
fullText = new WildcardQuery( new Term( FULL_TEXT_FIELD, format( term ) + "*" ) );
}
} catch ( ParseException ex ) {
fullText = new WildcardQuery( new Term( FULL_TEXT_FIELD, format( term ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2015 JBoss, by Red Hat, Inc
*
* Licensed 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 org.uberfire.ext.metadata.io;

import java.io.IOException;
import java.util.List;

import org.junit.Test;
import org.uberfire.java.nio.file.Path;

import static org.junit.Assert.*;

public class IOSearchIndexTest extends BaseIndexTest {

@Override
protected String[] getRepositoryNames() {
return new String[]{ this.getClass().getSimpleName() };
}

@Test
public void testFullTextSearch() throws IOException, InterruptedException {

final IOSearchIndex searchIndex = new IOSearchIndex( config.getSearchIndex(), ioService() );

final Path path1 = getBasePath( this.getClass().getSimpleName() ).resolve( "a.txt" );
ioService().write( path1,
"ooooo!" );

Thread.sleep( 5000 ); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index

{
final List<Path> result = searchIndex.fullTextSearch( "a", 10, 0, path1.getRoot() );

assertEquals( 1, result.size() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,37 @@ public void testFullTextIndexedFile() throws IOException, InterruptedException {
hits.length );
}

{
final TopScoreDocCollector collector = TopScoreDocCollector.create( 10, true );

searcher.search( new WildcardQuery( new Term( FULL_TEXT_FIELD, "*mydrlfile1*" ) ), collector );

final ScoreDoc[] hits = collector.topDocs().scoreDocs;
listHitPaths( searcher,
hits );

assertEquals( 1,
hits.length );
}


final Path path2 = getBasePath( this.getClass().getSimpleName() ).resolve( "a.drl" );
ioService().write( path2,
"Some cheese" );

{
final TopScoreDocCollector collector = TopScoreDocCollector.create( 10, true );

searcher.search( new WildcardQuery( new Term( FULL_TEXT_FIELD, "a*" ) ), collector );

final ScoreDoc[] hits = collector.topDocs().scoreDocs;
listHitPaths( searcher,
hits );

assertEquals( 1,
hits.length );
}

( (LuceneIndex) index ).nrtRelease( searcher );
}

Expand Down