Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Searching

 
Aleksander Zielinski
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

Would like to get to know your opinion on searching the database.

There are two issuses related to searching.

  • First, implementing the server-side 'find' method that access database, and requires to return records with fields that begins with a given value.
  • Second, implementing the search method that if needed would "filter" results from 'find' method for clients and give only exact matches.

  • I'm concerend about implementing 'find' method from DBMain interface. Well, in fact, I already implemented it and there's a problem... I'll exlpain the issue later on, for now let me quote the spec and let's look at the example below first please.

    Returns an array of record numbers that match the specified criteria. Field n in the database file is described by criteria[n]. A null value in criteria[n] matches any field value. A non-null value in criteria[n] matches any field value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy".)

    Having this read, three records an array criteria like this:



    Which records should the method find return in your opinion? In my opinion it would be the second record, because this is the one that meets all the criteria, it name begins with "Pa" and it's price begins with "$25". That's based on logical findings and my understanding of English, because spec says: "match the specified criteria" not "match any cryterion". In the latter case, all three would be returned, as each of them has a field that match one of the criteria, either name of a hotel or price. Anyway, if it returned records that match any criterion, we wouldn't be able to perfrom detailed searches, so I think we agree on that matter.

    Here's the problem. I implemented 'find' method as explained above, it would return only second record. Therefore, getting results from the 'find' method implemented like this, we are unable to "filter" the records to satisfy another condition from the spec, which is as follows:

    It must allow the user to search the data for all records, or for records where the name and / or location fields exactly match values specified by the user.


    Since we got result that match all specified criteria (therefore could satisfy only AND condition), it seems that we would have to invoke 'find' method twice, one time for first part of OR condition and second time for the other part and then filter both results to get the list of records that matches this OR that. I don't like the idea.

    Maybe simply I should interpret the spec, that client can search on records where *just* name OR *just* location is specified, not both?

    There's a "must" in this sentence, so better safe than sorry Thank you for opinions on this subject.

    [ October 13, 2006: Message edited by: Aleksander Zielinski ]

    [ October 13, 2006: Message edited by: Aleksander Zielinski ]
    [ October 13, 2006: Message edited by: Aleksander Zielinski ]
     
    Edwin Dalorzo
    Ranch Hand
    Posts: 961
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    My implementation works pretty much like you suggest. Regarding the search issue I am using a filter to satisfy the requirement.

    I know the fields that are an exact match for the name and location must be a subset of what the Data.findByCriteria(String[]) method would return. Therefore, once I have received the records, I remove those that are not an exact match from the result set.

    I dare say there is no other way to do this without implementing a more intelligent database seach algorithm. But the specification does not seem to require so. Therefore, I have implemented a filtering algorithm in my business compoenent, responsible for removing the unwanted records from a broader result set containing all possible occurrences of the records I am looking for.

    Would you say this approach satisfies the requirement?
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic