lucene-lucene-net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Slansky <jslan...@webgroup.cz>
Subject Re: How to limit search to directory
Date Wed, 08 Nov 2006 15:08:51 GMT
I'm using base of .Net WebService example. PARENT_NAME is a desired 
parent field.

private void search()
        {
            DateTime start = DateTime.Now;
            string indexDirectory = "h:\\SearchIndex";
            FSLockConfig.LockDirectory = "h:\\SearchIndex\\lock";
            IndexSearcher searcher = new IndexSearcher(indexDirectory);
            string updatedquery = this.Q + " AND parent:PARENT_NAME;
            Query query = QueryParser.Parse(updatedquery, "body", new 
StandardAnalyzer());
            this.Results.Columns.Add("title", typeof(string));
            this.Results.Columns.Add("sample", typeof(string));
            this.Results.Columns.Add("path", typeof(string));
            Hits hits = searcher.Search(query);
            this.total = hits.Length();
            QueryHighlightExtractor highlighter = new 
QueryHighlightExtractor(query, new StandardAnalyzer(), "<B>", "</B>");
            this.startAt = initStartAt();
            int resultsCount = smallerOf (total, this.maxResults + 
this.startAt);
            for (int i = startAt; i < resultsCount; i++)
            {
                Document doc = hits.Doc(i);
                string path = doc.Get("fullname");
                string plainText = doc.Get("body");
                DataRow row = this.Results.NewRow();
                row["title"] = doc.Get("name");
                row["sample"] = highlighter.GetBestFragments(plainText, 
80, 2, "...");
                this.Results.Rows.Add(row);
            }
            searcher.Close();
            this.duration = DateTime.Now - start;
            this.fromItem = startAt + 1;
            this.toItem = smallerOf(startAt + maxResults, total);
        }
Nathan Haywood wrote:
> It is probably a matter of either tokenizing the "parent" field when
> indexing or using standard analyzer (instead of, say, keywordanalyzer)
> when building the query.
>
> Can you post your code so we can all see/help?
>
> Nathan
>
> -----Original Message-----
> From: Jan Slansky [mailto:jslansky@webgroup.cz] 
> Sent: Wednesday, November 08, 2006 3:42 AM
> To: lucene-net-user@incubator.apache.org
> Subject: Re: How to limit search to directory
>
> Hi George,
>
> thank you for your reply. I have found that there is field named
> "parent". So it would be fine to use it in my search query (AND
> parent:d:\data\documents).
> But there is problem with parsing of colon, underscore and backslash
> characters. Even when I escape them (: as a \: ) the final query is
> without these characters and they are replaced with space. I tried to
> place d:\data\documents in quotations.
> What is wrong with parsing of these special characters? I'm using latest
> (I hope so) Lucene.net.dll (1.9.0.7).
>
> Jan
>
> George Aroush wrote:
>   
>> Hi Jan,
>>
>> The easiest solution is to create two separate indexes and search into
>>     
>
>   
>> the specific index.  When you want to search both indexes, create a 
>> MultiSearcher.
>>
>> An alternative is to create an extra field for each document.  In this
>>     
>
>   
>> extra field store a value unique to "d:\data\help" and a value unique 
>> to "d:\data\documents"  During search, AND this unique field to the
>>     
> search.
>   
>> Regards,
>>
>> -- George Aroush
>>
>> -----Original Message-----
>> From: Jan Slansky [mailto:jslansky@webgroup.cz]
>> Sent: Monday, November 06, 2006 6:06 AM
>> To: lucene-net-user@incubator.apache.org
>> Subject: How to limit search to directory
>>
>> Hello,
>>
>> I have a question about query. Is it possible to limit search query to
>>     
>
>   
>> look for a file in one specific folder and its subdirectories?
>>
>> Example:
>>
>> d:\data\help
>> d:\data\documents
>>
>> I am indexing d:\data folder and I would like to limit query to search
>>     
>
>   
>> only in d:\data\documents directory and all it's subdirectories.
>>
>> Thanks in advance for any help.
>>
>> Jan
>>
>>
>>
>>   
>>     
>
>
>
>
>   



Mime
View raw message