You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Paul Taylor <pa...@fastmail.fm> on 2007/05/04 10:33:09 UTC

Unable to get wildcards to work

I have indexed some records in a JTable , and I am trying to return all 
records where the value in a particular column starts with a particular 
value(http://musicbrainz.org:), but I get no matches. If I match for an 
exact values it works fine, Im stumped as to why this would be the case

//Works ok
DataIndexer.getInstance().singleTermSearch(ID3TagNames.INDEX_UFID,"http://musicbrainz.org:4d08a37a-6e71-401c-ad54-dbe5a8ae919a");  


//No matches (last option is what I really want to do)
DataIndexer.getInstance().singleTermSearch(ID3TagNames.INDEX_UFID,"http://musicbrainz.org:4d08a37a-6e71-401c-ad54-dbe5a8ae919?");  

DataIndexer.getInstance().singleTermSearch(ID3TagNames.INDEX_UFID,"http://musicbrainz.org:4d08a37a-6e71-401c-ad54-dbe5a8ae919*");  

DataIndexer.getInstance().singleTermSearch(ID3TagNames.INDEX_UFID,"http://musicbrainz.org:*");  



My Index is constructed using a KeywordAnalyser, the following line add 
a value to the index (there is one document per row)

 document.add(new Field((String) tc.getIdentifier(), columnValue, 
Field.Store.YES, Field.Index.UN_TOKENIZED));

My Search Code is:
 public List <Integer> singleTermSearch(Integer columnId,String 
searchstring)
    {
        List <Integer> matchingRows = new ArrayList<Integer>();
        try
        {
            //make a new index searcher with the in memory (RAM) index.
            IndexSearcher is = new IndexSearcher(directory);

            //Search on column columnId for value searchstring
            TermQuery query = new TermQuery(new 
Term(String.valueOf(columnId),searchstring));

            //run the search
            Hits hits = is.search(query);

            Iterator i = hits.iterator();
            while(i.hasNext())
            {
                Document doc = ((Hit)i.next()).getDocument();
                matchingRows.add(new 
Integer(doc.getField(ROW_NUMBER).stringValue()));
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return matchingRows;
    }

thanks Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Unable to get wildcards to work

Posted by Paul Taylor <pa...@fastmail.fm>.
Thanks, youve sparked a thought Ive now realised I was calling the wrong 
method i had another method (simpleSearch) that used the Query parser to 
parse the search string which I should have been using

cheers Paul

Koji Sekiguchi wrote:
> Hi Pail,
>
> Try WildcardQuery instead of TermQuery as follows:
>
>           //Search on column columnId for value searchstring
>           WildcardQuery query = new WildcardQuery(new 
> Term(String.valueOf(columnId),searchstring));
>
> Thank you,
>
> Koji
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Unable to get wildcards to work

Posted by Koji Sekiguchi <ko...@r.email.ne.jp>.
Hi Pail,

Try WildcardQuery instead of TermQuery as follows:

           //Search on column columnId for value searchstring
           WildcardQuery query = new WildcardQuery(new 
Term(String.valueOf(columnId),searchstring));

Thank you,

Koji


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org