• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is anyone familiar with NSStringrangeOfCharacterFromSet:options
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is anyone familiar with NSStringrangeOfCharacterFromSet:options


  • Subject: Is anyone familiar with NSStringrangeOfCharacterFromSet:options
  • From: David Yamartino <email@hidden>
  • Date: Thu, 22 Jan 2009 12:41:53 +1000


Hi All,

I need to write an application where the user inputs a search term and the app looks in a folder and subfolders containing text files and then displays not just the location of the documents containing the search string, but the context of each instance (maybe a few sentences before and after - or maybe just sends you to that part of the document where you can read before and after).

The "Search Kit Programming Guide" gives a "complete search method" under Listing 3-19 (see below), but it also states that it only finds documents, not the "position of a term within a document":

To Search Kit, a document is atomic in that it defines the granularity of a search. Using Search Kit, your application can find documents—as your application understands them—but cannot locate the position of a term within a document. If you want to locate matches for a user's query within a found document, use the MLTE TXNFind function in Carbon or the NSStringrangeOfCharacterFromSet:options: method in Cocoa.

I can't find any documentation on this method. If are familiar with it, I would appreciate any help you could provide.

Also, I'm thinking that the program I have in mind (since it's quite basic) may already be written and available some where. If you are aware of anything, I'd appreciate your help,

Thanks,

David

===============================
Listing 3-19  A complete search method
//..........................................................................
// specify the maximum number of hits
#define kSearchMax 1000
 
- (void) search
{
//..........................................................................
// set up search options
 
    SKSearchOptions options = kSKSearchOptionDefault;
 
    if ([searchOptionNoRelevance intValue]) options |= kSKSearchOptionNoRelevanceScores;
    if ([searchOptionSpaceIsOR intValue]) options |= kSKSearchOptionSpaceMeansOR;
    if ([searchOptionSpaceFindSimilar intValue]) options |= kSKSearchOptionFindSimilar;
 
//..........................................................................
// get the user's query
 
    NSString * query = [searchField stringValue];
 
//..........................................................................
// create an asynchronous search object
 
    SKSearchRef search = SKSearchCreate (
                             skIndex,
                             (CFStringRef) query,
                             options
                         );
    [(id) search autorelease];
 
//..........................................................................
// get matches from a search object
 
    Boolean more = true;
    UInt32 totalCount = 0;
 
    while (more) {
 
        SKDocumentID    foundDocIDs [kSearchMax];
        float            foundScores [kSearchMax];
        SKDocumentRef    foundDocRefs [kSearchMax];
 
        float * scores;
        Boolean unranked = options & kSKSearchOptionNoRelevanceScores;
 
        if (unranked) {
            scores = NULL;
        } else {
            scores = foundScores;
        }
 
        CFIndex foundCount = 0;
        CFIndex pos;
 
        more =    SKSearchFindMatches (
                    search,
                    kSearchMax,
                    foundDocIDs,
                    scores,
                    1, // maximum time before func returns, in seconds
                    &foundCount
                );
 
        totalCount += foundCount;
 
//..........................................................................
// get document locations for matches and display results.
//     alternatively, you can collect results over iterations of this loop
//     for display later.
 
        SKIndexCopyDocumentRefsForDocumentIDs (
            (SKIndexRef) skIndex,
            (CFIndex) foundCount,
            (SKDocumentID *) foundDocIDs,
            (SKDocumentRef *) foundDocRefs
        );
 
        for (pos = 0; pos < foundCount; pos++) {
            SKDocumentRef doc = (SKDocumentRef) [(id) foundDocRefs [pos] autorelease];
            NSURL * url = "" SKDocumentCopyURL (doc) autorelease];
            NSString * urlStr = [url absoluteString];
 
            NSString * desc;
 
            if (unranked) {
                desc = [NSString stringWithFormat: @"---\nDocID: %d, URL: %@", (int) foundDocIDs [pos], urlStr];
            } else {
                desc = [NSString stringWithFormat: @"---\nDocID: %d, Score: %f, URL: %@", (int) foundDocIDs[ pos], foundScores [pos], urlStr];
            }
            [self log: desc];
        }
    }
 
    NSString * desc = [NSString stringWithFormat: @"\"%@\" - %d matches", query, (int) totalCount];
    [self log: desc];
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Is anyone familiar with NSStringrangeOfCharacterFromSet:options
      • From: "Hank Heijink (Mailinglists)" <email@hidden>
    • Re: Is anyone familiar with NSStringrangeOfCharacterFromSet:options
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: #include <mex.h>
  • Next by Date: Re: Is anyone familiar with NSStringrangeOfCharacterFromSet:options
  • Previous by thread: Re: #include <mex.h>
  • Next by thread: Re: Is anyone familiar with NSStringrangeOfCharacterFromSet:options
  • Index(es):
    • Date
    • Thread